chordsoflife Posted March 26, 2009 Share Posted March 26, 2009 Here's the relevant code: $shows = mysql_query("SELECT * FROM tblConcert WHERE fkBandID = '$pk' AND fldConcertDate >= CURDATE() ORDER BY fldConcertDate", $db); $numRows = mysql_num_rows($shows); while($show = mysql_fetch_array($shows, MYSQL_ASSOC)){ $date = date("F j, Y",strtotime($show[fldConcertDate])); if($numRows == 0){ echo "<p>No upcoming shows for $show[fldBand]. <a href='#'>Know of one?</a></p>"; } else { This doesn't work. I assume it's a simple mistake (I'm self taught so I lack a lot of basics), but $numRows is acting like it doesn't exist. If I move that if statement outside of the while loop, it does work, and I guess I can do that, but I'm asking for the learning experience rather than a fix so... why can't I use the variable inside the loop? Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted March 26, 2009 Share Posted March 26, 2009 I would put the number of rows before the loop $shows = mysql_query("SELECT * FROM tblConcert WHERE fkBandID = '$pk' AND fldConcertDate >= CURDATE() ORDER BY fldConcertDate", $db); $numRows = mysql_num_rows($shows); if($numRows == 0){ echo "<p>No upcoming shows for $show[fldBand]. <a href='#'>Know of one?</a></p>"; } else { while($show = mysql_fetch_array($shows, MYSQL_ASSOC)){ $date = date("F j, Y",strtotime($show[fldConcertDate])); } Quote Link to comment Share on other sites More sharing options...
chordsoflife Posted March 26, 2009 Author Share Posted March 26, 2009 Agreed, that does work, but I'm more wondering why what I have does NOT work. I've used "$count" successfully after setting it outside of a loop, so the logic is where I'm fuzzy on this one. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.