Hello all. Ran into another snag which should be an easy fix.
I am attempting to retrieve information from a table about a group of computers. There is an attribute called location, from which we can group computers by their physical location.
I use a standard form to pass the location to the page in question. For this troubleshooting purpose, I am using 'hq'. I know 'hq' is being passed, and so that is great.
I made up 3 computers, all belonging in 'hq'. If I perform a standard mysql query, I get all three computer names using this query:
SELECT computers.computer_name
FROM computers
WHERE computers.location='hq'
So, I know that is working.
However, I am sitting here trying to figure out how to retrieve each computer name from an array that would hold the entire computer list.
This is the way I had initially decided to do it:
// Query to pull information from the database about the computer name specified in the previous page.
$query="SELECT computers.computer_name
FROM computers
WHERE computers.location='$location'";
// Identified the above query as a valid query or dies if there is a problem with it.
$result = mysql_query($query) or die("Query failed");
$num_results = mysql_num_rows($result); //figure out how many rows are returned by the query (how many computers)
$row = mysql_fetch_array($result);
for ($i=0; $i < $num_results; $i++)
{
print($row[$i]);
}
Now, the error I get is that the array apparently doesn't know anything about offsets 1 or 2 (the second and third results). It prints out the first computer name fine, then gives me errors.
Any help would be appreciated. For some stupid reason I can't figure this out.