Jump to content

Archived

This topic is now archived and is closed to further replies.

mattennant

running a second query in a while loop

Recommended Posts

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

[url=http://fat-cat.co.uk/fatcat/events.php]http://fat-cat.co.uk/fatcat/events.php[/url]

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

[code]<?php

$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);

 
 
if($result){
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\">
$row[2]</td></tr>\n";
}
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>';
}
?>
[/code]

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

Share this post


Link to post
Share on other sites
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/

Desmond.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.