Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop... help 1

Status
Not open for further replies.

cranebill

IS-IT--Management
Jan 4, 2002
1,113
US
I have the following code, it is written by someone else, I am trying to modify it for my needs. I cannot get it to connect to the query... this is what I have:

Code:
for ($list_day = 1; $list_day <= $daysinmonth; $list_day++) {
		$tm = date("U", mktime(0, 0, 0, $month, $list_day, $year)) - 86400; // Bir gün önce
		$tn = date("U", mktime(0, 0, 0, $month, $list_day, $year)); // O gün ...
		$tp = date("U", mktime(0, 0, 0, $month, $list_day, $year)) + 86400; // Bir gün sonra
		$Q = sprintf("SELECT * FROM `events` WHERE `date` > '%s' AND `date` < '%s' AND `day` = '%s';", $tm, $tp, $list_day);
		$R = mysql_query($Q);
		$D = mysql_fetch_assoc($R);
		$S = mysql_num_rows($R);
		$Y = $D['date'];
		$TheDay = date('d', $Y);
		$TheMon = date('F', $Y);
		$TheYea = date('Y', $Y);
		mysql_free_result($R);
		if ($S) {
		?>
			<td align="center" onclick="popupEvent(<?php echo $D['day']; ?>, <?php echo $D['month']; ?>, <?php echo $D['year']; ?>, 400, 500)" style="background-color: #CCFF00; color: #333333;cursor: pointer;" 
			onmouseover="<?PHP echo "return overlib('&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; class=&quot;popupDateTable&quot;&gt;&lt;tr&gt;&lt;td align=&quot;center&quot; class=&quot;popupDate&quot;&gt;" ?> <?php echo $TheDay; ?> <?php echo $TheMon; ?> <?php echo $TheYea; ?><?PHP echo "&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;');" ?>[B]<?php while ($D = mysql_fetch_assoc($R)) {?>[/B]<?PHP echo "&lt;br /&gt;&lt;div class=&quot;popupEventTitle s24&quot;&gt;" ?> <?php echo stripslashes($D['title']); ?><?PHP echo "&lt;/div&gt;"?><?PHP echo "&lt;div class=&quot;popupEventTime&quot;&gt;"?><?php echo date("d.m.Y", $D['date']); ?><?PHP echo "&lt;/div&gt;"?><?PHP echo "&lt;div class=&quot;popupEventDescription&quot;&gt;"?><?php echo '@' . stripslashes($D['location']); ?><?PHP echo "&lt;/div&gt;"?><?php } ?>"

I believe the problem lies here:
Code:
 <?php while ($D = mysql_fetch_assoc($R))
where I have it bolded for if I take from the bolded point forward and put it in a popup page triggerred by the on click command and change the bolded line to:
Code:
<?php
$Q = mysql_query(sprintf("SELECT * FROM `events` WHERE `day` = '%s' AND `month` = '%s' AND `year` = '%s';", $_GET['day'], $_GET['month'], $_GET['year']));
while ($D = mysql_fetch_assoc($Q)) {?>
it works....

so what am I doing wrong?
 
you have not said what does not work.

but i notice that you are calling mysql_fetch_assoc in two places. and after the first call you are freeing the result. which should make subsequent calls fail.

Code:
$R = mysql_query($Q);
       [red]//[\red] $D = mysql_fetch_assoc($R);
        $S = mysql_num_rows($R);
        $Y = $D['date'];
        $TheDay = date('d', $Y);
        $TheMon = date('F', $Y);
        $TheYea = date('Y', $Y);
       [red]//[\red] mysql_free_result($R);

i suggest you comment out the above lines and see whether that helps.
 
or even...

Code:
$R = mysql_query($Q);
       [red]//[/red] $D = mysql_fetch_assoc($R);
        $S = mysql_num_rows($R);
        $Y = $D['date'];
        $TheDay = date('d', $Y);
        $TheMon = date('F', $Y);
        $TheYea = date('Y', $Y);
       [red]//[/red] mysql_free_result($R);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top