php - While loop inside if else statement not working -


i have code snippet failing work, don't know doing wrong, getting content mysql database , using if else statement while loop echo contents.

<?php                   if ($row_item['cat_item_id'] == ''){                         echo '<div class="col-sm-6 col-md-3"">                          </p>                         <p>                           no item show                         </p>                       </div>                   </div>';                     }                  else  {                                          while ($row_item = mysql_fetch_assoc($item)){                       echo                   '                 <div class="col-sm-6 col-md-3" style="'.$row_item['display'].'">                       <div class="thumbnail">                         <img src="myaccount/user_data/'.$row_item['file_name'].'" />                       </div>                       <div class="caption">                         <h3>'.$row_item['item_name'].'</h3>                                              <p>                           <a href="item_detail.php?item='.$row_item['cat_item_id'].'" class="btn btn-primary" role="button">                            view item                           </a>                            <a href="contact_seller.php?contact='.$row_item['cat_item_id'].'" class="btn btn-default" role="button">                           contact owner                           </a>                         </p>                       </div>                   </div>';                   }                  }                      ?> 

help me figure out not doing right.

you have call while ($row_item = mysql_fetch_assoc($item)) first place.

otherwise $row_items doesn't initialized properly.

so put inside

 while ($row_item = mysql_fetch_assoc($item)) 

and check if-else conditions inside while:

if ($row_item['cat_item_id'] == '') // goes inside while. otherwise $row_item not initialized 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -