Lamez Posted July 14, 2008 Share Posted July 14, 2008 I am having a problem with my marquee, it is suppose to check to see if there is anything in the database. Well it is not echoing anything out, because there is nothing in the database, but I setup a default message in case something like this happens. But my default message is not working. Here is my code: <?php $query = mysql_query("SELECT * FROM `marquee`"); $marquee = mysql_fetch_array($query); $num_rows = mysql_num_rows($query); if($num_rows < '1'){ $status = "This is the default marquee message, if you are the admin please login and change it."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/ Share on other sites More sharing options...
craygo Posted July 14, 2008 Share Posted July 14, 2008 try removing the single quotes <?php $query = mysql_query("SELECT * FROM `marquee`"); $marquee = mysql_fetch_array($query); $num_rows = mysql_num_rows($query); if($num_rows < 1){ $status = "This is the default marquee message, if you are the admin please login and change it."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589651 Share on other sites More sharing options...
Dethman Posted July 14, 2008 Share Posted July 14, 2008 Im pretty sure you dont need '1' it should be just 1 like this <?php $query = mysql_query("SELECT * FROM `marquee`"); $marquee = mysql_fetch_array($query); $num_rows = mysql_num_rows($query); if($num_rows < 1){ $status = "This is the default marquee message, if you are the admin please login and change it."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589652 Share on other sites More sharing options...
Dethman Posted July 14, 2008 Share Posted July 14, 2008 dang he beat me to it.. Good Show craygo Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589653 Share on other sites More sharing options...
Lamez Posted July 14, 2008 Author Share Posted July 14, 2008 well that did not work either. Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589656 Share on other sites More sharing options...
PFMaBiSmAd Posted July 14, 2008 Share Posted July 14, 2008 Use var_dump() to show what is in $num_rows. What is your code that displays $status? Are you sure the posted code is being executed? Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589662 Share on other sites More sharing options...
craygo Posted July 14, 2008 Share Posted July 14, 2008 make sure you are not getting any errors <?php $query = mysql_query("SELECT * FROM `marquee`") or die(mysql_error()); $marquee = mysql_fetch_array($query); $num_rows = mysql_num_rows($query); if($num_rows < 1){ $status = "This is the default marquee message, if you are the admin please login and change it."; } ?> also add mysql_error() to your connection strings to make sure you are connecting. Ray Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589664 Share on other sites More sharing options...
Lamez Posted July 14, 2008 Author Share Posted July 14, 2008 Thanks for the replys guys. I did do the mysql_error after I posted this topic, and I am connect, and no errors. I did do the var_dump($num_rows); and I got this: int(0) You guys where asking about $status, here is the rest of the code: <?php $q = mysql_query("SELECT * FROM `site_status`"); $row = mysql_fetch_array($q); $query = mysql_query("SELECT * FROM `marquee`"); $marquee = mysql_fetch_array($query); $num_rows = mysql_num_rows($query); if($num_rows < 1){ $status = "This is the default marquee message, if you are the admin please login and change it."; } if ($marquee['num'] == (2)){ $status = $marquee['mar_custom']; }else{ $stat = $row['status']; if ($stat == ('0')){ $status = $marquee['mar_nu']; } if ($stat == ('1')){ $status = $marquee['mar_basket']; } if ($stat == ('2')){ $status = $marquee['mar_foot'];; } } ?> <script type="text/javascript"> //<![CDATA[ document.write("<marquee> <?php echo $status; ?></marquee>"); //]]> </script> this is a included file in my head.php Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589670 Share on other sites More sharing options...
Lamez Posted July 14, 2008 Author Share Posted July 14, 2008 gosh I feel retarted, once I posted the code I saw my else statement was in the wrong spot. here is the fix: <?php $q = mysql_query("SELECT * FROM `site_status`"); $row = mysql_fetch_array($q); $query = mysql_query("SELECT * FROM `marquee`"); $marquee = mysql_fetch_array($query); $num_rows = mysql_num_rows($query); if($num_rows < 1){ $status = "This is the default marquee message, if you are the admin please login and change it."; }else{ if ($marquee['num'] == (2)){ $status = $marquee['mar_custom']; } $stat = $row['status']; if ($stat == ('0')){ $status = $marquee['mar_nu']; } if ($stat == ('1')){ $status = $marquee['mar_basket']; } if ($stat == ('2')){ $status = $marquee['mar_foot'];; } } ?> <script type="text/javascript"> //<![CDATA[ document.write("<marquee> <?php echo $status; ?></marquee>"); //]]> </script> since the else statement was in the wrong spot, it was setting $status to a empty variable. That is why I got nothing echoed out. Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589674 Share on other sites More sharing options...
craygo Posted July 14, 2008 Share Posted July 14, 2008 was just going to tell you that. Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589678 Share on other sites More sharing options...
Lamez Posted July 14, 2008 Author Share Posted July 14, 2008 lol I am getting better with php Quote Link to comment https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/#findComment-589683 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.