[SOLVED] loading records into array and viewing
Posted: Tue Jan 06, 2004 12:57 pm
I do a simple query, and would like to load the records into an array, if it meets a conditon. The condition is not in the query.
I have tried loading the records and viewing the array, but it does not seem to work. Am i loading the array properly, or should i be using an array_push. I could not get that working either. Any help would be appreciated. Thanks.
[Edit: Added PHP tags for eyecandy. --JAM]
I have tried loading the records and viewing the array, but it does not seem to work. Am i loading the array properly, or should i be using an array_push. I could not get that working either. Any help would be appreciated. Thanks.
Code: Select all
$result= mysql_query("Select id, first_name, last_name, city From students");
$ids= array();
while($row = mysql_fetch_array($result))
{
//an if condition, if it meets condition, we will store record into array
{
$ids[] = $row[id];
$student[id] = $row[id];
$student[id][first_name] = $row[first_name];
$student[id][last_name] = $row[last_name];
$student[id][city] = $row[city];
}
}
for($i=0;$i<count($ids);$i++){
$id=$ids[$i];
echo "Student ID:".$student[$id]."\n";
echo "First Name:".$student[$id][first_name]."\n";
echo "Last Name:".$student[$id][last_name]."\n";
echo "City:". $student[$id][city]."\n";
}