View Single Post
Old 10-06-2012, 11:18 PM   PM User | #3
Cloud Ghost
New Coder

 
Join Date: Jan 2010
Location: Canada
Posts: 34
Thanks: 11
Thanked 4 Times in 4 Posts
Cloud Ghost is an unknown quantity at this point
You don't need a foreach() loop in this case because while() acts as a loop with the MySQL rows you selected. You're missing a closing curly bracket, by the way but that could just be a problem with copy and pasting.

Try this:
PHP Code:
$sql mysql_query("SELECT id FROM servers WHERE active = '1'") or die(mysql_error());
while(
$ids mysql_fetch_array($sql)) { 
    
$get mysql_query("SELECT * FROM servers WHERE id = '{$ids['id']}'") or die(mysql_error()); 
    
$serv mysql_fetch_array($get); 
    
// rest of process here using $serv['cell_ref'] as a reference. 

Just a few notes...
I added or die(mysql_error()) onto the end of your MySQL queries. This is good practice because it will let you know of any errors in your query immediately which can save a lot of time when coding in the future.
I don't know exactly what you're doing here or your table structure, but SQL queries in loops can be considered slow and should be avoided if there's another, more efficient way to do what you want to do.
Cloud Ghost is offline   Reply With Quote
Users who have thanked Cloud Ghost for this post:
alphamale (10-06-2012)