new badge on category list php -


i having category sidebar below code

working code:

//showing categories function function getcats(){ global $db;  $q_cats = "select * cats order cat_name asc"; $run_cats = mysqli_query($db, $q_cats); while($row_cat = mysqli_fetch_array($run_cats)){     $cat_id = $row_cat['cat_id'];     $cat_name = $row_cat['cat_name'];         $q_count = "select * messages cat_id='$cat_id'";         $run_count = mysqli_query($db, $q_count);         $cat_sms_count = mysqli_num_rows($run_count);             if($cat_sms_count < 1){                 $cat_sms_count = 0;                 }            echo "<a href='category.php?category=$cat_id' class='list-group-item'>$cat_name<span class='badge'>$cat_sms_count</span></a>";      }//while row end here          $q_tmsgs = "select * messages";         $run_tcount = mysqli_query($db, $q_tmsgs);         $tsms_count = mysqli_num_rows($run_tcount);         echo "<a href='allindb.php' class='list-group-item t-list'>total messages in db<span class='badge'>$tsms_count</span></a>";      }//function getcats end here 

this working fine want, want add new badge image next category name. tried lot failed do, think relevant code.

please check code:

//showing categories function function getcats(){ global $db;  $q_cats = "select * cats order cat_name asc"; $run_cats = mysqli_query($db, $q_cats); while($row_cat = mysqli_fetch_array($run_cats)){     $cat_id = $row_cat['cat_id'];     $cat_name = $row_cat['cat_name'];         $q_count = "select * messages cat_id='$cat_id'";         $run_count = mysqli_query($db, $q_count);         $cat_sms_count = mysqli_num_rows($run_count);         //problem area----------------------------------                     $q_new = "select * messages cat_id='$cat_id' order date desc limit 20";                     $run_new = mysqli_query($db, $q_new);                     while($new = mysqli_num_rows($run_new)){                         $newbadge = $new['cat_id'];                         }                         if($cat_id==$newbadge){                             $newbadge1 = "<img src='images/mynew.gif'>";                             }          //--------------------------------------------                           if($cat_sms_count < 1){                 $cat_sms_count = 0;                 }            echo "<a href='category.php?category=$cat_id' class='list-group-item'>$cat_name $newbadge1<span class='badge'>$cat_sms_count</span></a>";      }//while row end here          $q_tmsgs = "select * messages";         $run_tcount = mysqli_query($db, $q_tmsgs);         $tsms_count = mysqli_num_rows($run_tcount);         echo "<a href='allindb.php' class='list-group-item t-list'>total messages in db<span class='badge'>$tsms_count</span></a>";      }//function getcats end here 

if understand correctly want show "new badge" on topics doesnt have messages in them. if got $q_count replace while{} inside if{}else{}like so:

if($q_count == 0) { $newbadge1 = "<img src='images/mynew.gif'>"; } else { $newbadge1 = ''; }

the problem doing query returning empty array, , therefore getting badges on topics has got messages. either remove while{} , replace if-else or can check like: if(empty($new)) { $newbadge1 = "<img src='images/mynew.gif'>"; } else { $newbadge1 = ''; }


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -