Lucky2710 Posted July 20, 2010 Share Posted July 20, 2010 I have a mySQL Database named sports with a table in it named users. Im trying to retrieve each of my users id #s into separate variables to be used later in my code. Heres my code that gets the id #s together... $sql="SELECT id FROM users WHERE approved=1"; $result=mysql_query($sql); while($row = mysql_fetch_object($result)) { echo $row->id; echo '<br />'; mysql_data_seek($result,'$i++'); $row = mysql_fetch_object($result); echo $row->id; echo '<br />'; } This gets the ids and prints them on my web page but i need to somehow get them as separate variables. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/208320-retrieving-id-numbers-to-separate-variables/ Share on other sites More sharing options...
AbraCadaver Posted July 20, 2010 Share Posted July 20, 2010 while($row = mysql_fetch_object($result)) { $ids[] = $row->id; } print_r($ids); Link to comment https://forums.phpfreaks.com/topic/208320-retrieving-id-numbers-to-separate-variables/#findComment-1088716 Share on other sites More sharing options...
Mchl Posted July 20, 2010 Share Posted July 20, 2010 $ids = array(); while($row = mysql_fetch_object($result)) { $ids[] = $row->id; } // now your ids are in an array called $ids foreach($ids as $id) { echo $id.'</br>'; } [/code] Link to comment https://forums.phpfreaks.com/topic/208320-retrieving-id-numbers-to-separate-variables/#findComment-1088718 Share on other sites More sharing options...
Lucky2710 Posted July 20, 2010 Author Share Posted July 20, 2010 Super Simple! Thanks Link to comment https://forums.phpfreaks.com/topic/208320-retrieving-id-numbers-to-separate-variables/#findComment-1088724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.