[web] PHP+mysql problem

Started by
5 comments, last by Maquiavel 19 years, 7 months ago
I'm making a calendar where each day has an event. So when I get data out of the database, I need to make sure it belongs on THAT day. So I tried this:

$dayDate = date("Y") . "-" . $currentMonth . "-" . $day2;
        $row = mysql_fetch_array($result)
        if($row['Date'] == $dayDate) {
          echo($row["EventText"]);
        }

But that returns this error: Parse error: parse error, unexpected T_IF in /home/xb4a1aa/public_html/calendarj.php on line 178 Anyone know whats wrong, or how to accomplish the logic above? the Date field is Date data type as well.
-Going to Westwood College for my Associates in Computer Programming
Advertisement
The '$row = mysql_fetch_array($result)' line lacks a semicolon, if you add one in the error should go away.
Also;
$row = mysql_fetch_array($result);
should be replaced with
$row = mysql_fetch_assoc($result);

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Quote:Original post by benryves
Also;
$row = mysql_fetch_array($result);
should be replaced with
$row = mysql_fetch_assoc($result);


Why assoc...? Doesn't that yeild field[1]; integer identifiers?
Quote:Original post by Charles Hwang
Quote:Original post by benryves
Also;
$row = mysql_fetch_array($result);
should be replaced with
$row = mysql_fetch_assoc($result);


Why assoc...? Doesn't that yeild field[1]; integer identifiers?


Nope... you get the field names. You only get the field names.
Quote:PHP Manual
mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC for the optional second parameter. It only returns an associative array. This is the way mysql_fetch_array() originally worked. If you need the numeric indices as well as the associative, use mysql_fetch_array().


[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Ah I see I learned something today. So assoc essentially lessens time for the query/work rather than retrieving both numberical and literal and being a tad bit slower (not really an issue these days however).
Quote:Original post by benryves
Also;
$row = mysql_fetch_array($result);
should be replaced with
$row = mysql_fetch_assoc($result);


Or: $row = mysql_fetch_array($result, MYSQL_ASSOC);

This will only return an associative array, the same as mysql_fetch_assoc.

[Edited by - Maquiavel on September 14, 2004 10:42:22 PM]
Alfred Reinold Baudisch[Game Development Student] [MAC lover] [Ruby, Ruby on Rails and PHP developer] [Twitter]

This topic is closed to new replies.

Advertisement