Jump to content

Recommended Posts

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.";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/114665-solved-mysql_num_rows/
Share on other sites

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.";
}
?>

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.";
}
?>

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

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.