Hi!
Have a gander at the following code. When I uncomment the bottom bit, I get an error, because $cur_gig_id comes out as null on the second iteration of the first loop. The thing is, the actual data ($gigs) has been got before the first loop ever starts, so how can $cur_gig_id be different when I uncomment the second loop?
<?
@ $db = mysql_pconnect("localhost", "blah", "blah");
if (!$db)
{
echo "Cannot connect to database server.";
exit;
}
mysql_select_db("retrogrademedia_co_uk_-_iceberg0");
$query_gigs = 'SELECT gig_id, gig_title, gig_time, gig_venue, gig_price, gig_notes FROM gig WHERE (gig.gig_time > NOW()) LIMIT 0, 30';
$gigs = mysql_query($query_gigs);
$num_gigs = mysql_num_rows($gigs);
for ($gig_count = 0; $gig_count < $num_gigs; $gig_count++)
{
$cur_gig = mysql_fetch_array($gigs);
echo "<div class='gig' id='gig".$cur_gig["gig_id"]."'>";
if (!empty($cur_gig["gig_title"]))
{
echo "<p class='gig_title'>".$cur_gig["gig_title"]."</p>";
}
echo "<p class='gig_time'>".$cur_gig["gig_time"]."</p>";
echo "<p class='gig_venue'>".$cur_gig["gig_venue"]."</p>";
echo "<p class='gig_price'>";
if (!empty($cur_gig["gig_price"]))
{
echo $cur_gig["gig_price"]."</p>";
}
else
{
echo "£TBA</p>";
}
echo "<p class='gig_notes'>".$cur_gig["gig_notes"]."</p>";
$cur_gig_id = $cur_gig["gig_id"];
echo "Cur_ID".$cur_gig_id;
/*
$query_bands = "SELECT band_name, band_region, band_web FROM band, plays WHERE (band.band_id = plays.band_id) AND (plays.gig_id = ".$cur_gig_id.")";
echo $query_bands;
$bands = mysql_query($query_bands);
$num_bands = mysql_num_rows($bands);
echo "Number of bands->".$num_bands."<-";
for ($band_count = 0; $band_count < $num_bands; $band_count++)
{
$cur_band = mysql_fetch_array($gigs);
echo "<p class='gig_band'>";
if (!empty($cur_band["band_web"]))
{
echo "<a href='".$cur_band["band_web"]."'>".$cur_band["band_name"]." (".$cur_band["band_region"].")</a></p>";
}
else
{
echo $cur_band["band_name"]." (".$cur_band["band_region"].")</p>";
}
} */
echo "</div>";
}
?>
Here are the results:
For One Night Only
2005-08-05 19:00:00
Carterton Football Club
3
Bring ID or face instant solitary confinement, imperialist piglet.
Cur_ID1
2005-09-01 19:00:00
The Allendale Hall, Carterton
4.5
Bring a goat and a vial of blood. Or alcohol if you prefer.
Cur_ID2
For One Night Only
2005-08-05 19:00:00
Carterton Football Club
3
Bring ID or face instant solitary confinement, imperialist piglet.
Cur_ID1SELECT band_name, band_region, band_web FROM band, plays WHERE (band.band_id = plays.band_id) AND (plays.gig_id = 1)Number of bands->3<-
()
()
()
£TBA
Cur_IDSELECT band_name, band_region, band_web FROM band, plays WHERE (band.band_id = plays.band_id) AND (plays.gig_id = )
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jack/public_html/gigs.php on line 49
Number of bands-><-