Skip to content

Instantly share code, notes, and snippets.

@philippTheCat
Created May 1, 2011 13:07
Show Gist options
  • Save philippTheCat/950487 to your computer and use it in GitHub Desktop.
Save philippTheCat/950487 to your computer and use it in GitHub Desktop.
function fetch($id=null) {
if (!is_null($id)) {
$where = "WHERE id = " . $id;
} else {
$where = " ";
}
$sql = "Select * from bug " . $where . ";";
print $sql . "\n";
$result = mysql_query($sql) or die(mysql_error());
if (!is_null($id)) {
while ($row = mysql_fetch_assoc($result)) {
$this->set_id($row["id"]);
$this->set_description($row["description"]);
}
return;
} else {
$res = array();
while ($row = mysql_fetch_assoc($result)) {
$curbug = new bug();
$curbug->set_id(intval($row["id"]));
$curbug->set_description($row["description"]);
$res[] = $curbug;
}
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment