Re: [PHP] PHP + MySQL looping question
On Friday 13 December 2002 05:40, Mark McCulligh wrote: I was wondering if there is a easy way to loop through the same SQL results many times. I have a for loop that loops 3 time. Each time I want to loop through the SQL result printing. The end result is printing the SQL results 3 times in a order. The problem is I have to reset the SQL result array on each for loop. How do you do that? for ($i = 1; $i = 3; $i++) { while ($row = mysql_fetch_array($result)) { //Some Code echo $row['filed']; } //Reset $result - SQL result } Read all the results into an array first, then you can print it out as many times as you like from the array. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* I don't like spinach, and I'm glad I don't, because if I liked it I'd eat it, and I just hate it. -- Clarence Darrow */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + MySQL looping question
Mark, Try looking at : http://www.php.net/manual/en/function.mysql-data-seek.php and see if that function gives you the desired result. HTH -Brad I was wondering if there is a easy way to loop through the same SQL results many times. I have a for loop that loops 3 time. Each time I want to loop through the SQL result printing. The end result is printing the SQL results 3 times in a order. The problem is I have to reset the SQL result array on each for loop. How do you do that? for ($i = 1; $i = 3; $i++) { while ($row = mysql_fetch_array($result)) { //Some Code echo $row['filed']; } //Reset $result - SQL result } Thanks, Mark. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP + MySQL looping question
The problem is I have to reset the SQL result array on each for loop. How do you do that? $myNewArrayFullofSqlResultsThatICanLoopOverAsManyTimesAsIWant = mysql_query($sql); -Craig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP + MySQL looping question
If I understand you if you use the mysql_query($sql) again won't it rerun my SQL again, not just reprint. Example: $result = mysql_query($sql); for ($i = 1; $i = 3; $i++) { while ($row = mysql_fetch_array($result)) { //Some Code echo $row['filed']; } //Reset result array $result = mysql_query($sql); } -- _ Mark McCulligh, Application Developer / Analyst Sykes Canada Corporation www.SykesCanada.com (888)225-6824 ex. 3262 [EMAIL PROTECTED] Craig Thomas [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... The problem is I have to reset the SQL result array on each for loop. How do you do that? $myNewArrayFullofSqlResultsThatICanLoopOverAsManyTimesAsIWant = mysql_query($sql); -Craig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP + MySQL looping question
Set the new array before your for loops, then loop over the array. -Craig -Original Message- From: Mark McCulligh [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 12, 2002 4:56 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] PHP + MySQL looping question If I understand you if you use the mysql_query($sql) again won't it rerun my SQL again, not just reprint. Example: $result = mysql_query($sql); for ($i = 1; $i = 3; $i++) { while ($row = mysql_fetch_array($result)) { //Some Code echo $row['filed']; } //Reset result array $result = mysql_query($sql); } -- _ Mark McCulligh, Application Developer / Analyst Sykes Canada Corporation www.SykesCanada.com (888)225-6824 ex. 3262 [EMAIL PROTECTED] Craig Thomas [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... The problem is I have to reset the SQL result array on each for loop. How do you do that? $myNewArrayFullofSqlResultsThatICanLoopOverAsManyTimesAsIWant = mysql_query($sql); -Craig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php