mostafatalebi Posted December 16, 2012 Share Posted December 16, 2012 Hello I have a mySQL table with six rows, How can I query all of them and put them one by one in a variable or an array? thanks Link to comment https://forums.phpfreaks.com/topic/272045-how-to-set-sql-result-into-variables/ Share on other sites More sharing options...
Pikachu2000 Posted December 16, 2012 Share Posted December 16, 2012 Where are you stuck, exactly? Link to comment https://forums.phpfreaks.com/topic/272045-how-to-set-sql-result-into-variables/#findComment-1399621 Share on other sites More sharing options...
mostafatalebi Posted December 16, 2012 Author Share Posted December 16, 2012 I mean I have a table, with six rows. Each row has a text in it. I want to query the table and get all six rows, putting each row's text into a variable, so at the end I have six variables or an array with six element. Something like looping through. But I don't know how Link to comment https://forums.phpfreaks.com/topic/272045-how-to-set-sql-result-into-variables/#findComment-1399629 Share on other sites More sharing options...
trq Posted December 16, 2012 Share Posted December 16, 2012 Assuming $results holds the result of your call to mysql_query(). $allResults = []; while ($row = mysql_fetch_assoc($results)) { $allResults[] = $row; } $allResults will now be an array containing all your rows. Link to comment https://forums.phpfreaks.com/topic/272045-how-to-set-sql-result-into-variables/#findComment-1399633 Share on other sites More sharing options...
mostafatalebi Posted December 16, 2012 Author Share Posted December 16, 2012 Ha! Thanks alot Link to comment https://forums.phpfreaks.com/topic/272045-how-to-set-sql-result-into-variables/#findComment-1399648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.