RE: [PHP] looping through database results

2001-09-30 Thread Jack Dempsey

hi karl

just to let you know, i believe there's a good calendar app on php.net
before i knew about this though, i wrote my own. some general advice:
i often take results from mysql calls and build data structures with the
data. then, you always have that
data available, and you can loop as many times as you want..think about
making the result add the results to an array,
and then use it where you need it

-jack

-Original Message-
From: Karl Nelson [mailto:[EMAIL PROTECTED]]
Sent: Sunday, September 30, 2001 5:46 PM
To: [EMAIL PROTECTED]
Subject: [PHP] looping through database results


I'm working on a basic calendar app in PHP, but I've hit a snag.

The events are stored in a MySQL database, and the goal is to have the
events displayed on the correct day on the calendar.  The calendar is
generated through a couple of while() statements that loop through the weeks
and days.  I'm having trouble getting the events from the database match up
with the correct days.

I think the problem is that I can only loop through the database results
once.

The code looks something like this (lots of extraneous stuff trimmed):

 while ($day_of_week = 6)
  {
  while ($event_row = mysql_fetch_array($events))
   {
   $event_day = $event_row[event_day];
   if ($event_day == $day)
{
$event_name = $event_row[event_name];
print $event_name\n;
}
   }
  }

Since it seems to only loop through the while ($event_row =
mysql_fetch_array($events)) statement once (instead of the 30 times I want
it to loop through), I figure the issue is that after the one loop,
$event_row does indeed equal mysql_fetch_array($events).  So I try to unset
the $event_row after the loop, but that didn't work.  I even tried to make
$event_row into a variable variable name.  Couldn't get that to work either.

I'm running PHP version 4.0.6, if that matters.

thanks,
Karl
(feel free to cc [EMAIL PROTECTED], as I'm on the digest)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] looping through database results

2001-09-30 Thread Karl Nelson

Thanks for your help, Andrew, but it didn't seem to work.  As I read the 
manual (http://www.php.net/manual/en/function.mysql-fetch-array.php),
mysql_fetch_array is much like mysql_fetch_row, except that it uses the
field names instead of numbers as the array key.  Somebody correct me if I'm
wrong...

Karl

Andrew Elliston wrote:
 Try using:

 while ($event_row = mysql_fetch_row($events))

 instead. mysql_fetch_row will grab one row of the result array at a
 time, until there are no more rows. This sounds like what you want. What
 you were doing was grabbing the entire result array and storing them in
 one variable.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] looping through database results

2001-09-30 Thread Jack Dempsey

Right, fetch-array just adds extra results to fetch-row.
Have you tried storing your results in an array that you can then loop
over later?

-Original Message-
From: Karl Nelson [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, September 30, 2001 6:33 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] looping through database results

Thanks for your help, Andrew, but it didn't seem to work.  As I read the

manual (http://www.php.net/manual/en/function.mysql-fetch-array.php),
mysql_fetch_array is much like mysql_fetch_row, except that it uses the
field names instead of numbers as the array key.  Somebody correct me if
I'm
wrong...

Karl

Andrew Elliston wrote:
 Try using:

 while ($event_row = mysql_fetch_row($events))

 instead. mysql_fetch_row will grab one row of the result array at a
 time, until there are no more rows. This sounds like what you want.
What
 you were doing was grabbing the entire result array and storing them
in
 one variable.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]