Jump to content


running a second query in a while loop

  • Please log in to reply
2 replies to this topic

#1 mattennant

  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 16 August 2006 - 11:00 AM

I'm trying to prduce an events calendar similaar to the one here


I think i need to run a query to produce a unique month from my table, and within that loop run a second query for the days. I've successfully got the first loop running, it's the second i'm struggling with. is there a simple answer to this problem.

here's the code


$query= "SELECT distinct DATE_FORMAT(date,'%M  %Y') AS dr FROM hoarse_events ORDER BY date ASC";
$result = mysql_query ($query);

$query2= "SELECT  DATE_FORMAT(date,'%M %d %Y') AS dr FROM hoarse_events ORDER BY date ASC";
$result2 = mysql_query ($query2);

echo'<table align="left" cellspacing="" cellpadding""> ';

//fetchand print all results

while ($row = mysql_fetch_array($result, MYSQL_NUM)){
echo"<tr><td align=\"left\">
$row[0]</td><td align=\"left\">
echo '</table>';

mysql_free_result ($result);//free up resources

}else{//if it did not run ok
echo'<p> something is wrong.</p><p>' . mysql_error().'</P>';

I've tried sticking the second loop within the first, but i'm getting nothing but errors, any help much appreciated

#2 brown2005

  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 16 August 2006 - 11:01 AM

how horrible is the select boxes on that site... they need to be bigger. lol

#3 otuatail

  • Members
  • PipPipPip
  • Advanced Member
  • 960 posts

Posted 16 August 2006 - 11:25 AM

Running a query within a queery can be slow to say the least. Re-think your plan. Maybee get the user to pick a day first and then on another page list the vents for that/


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users