SkyRanger Posted January 19, 2013 Share Posted January 19, 2013 $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $phtocat = $_GET['cid']; $query = "SELECT * FROM `gallery_photos` WHERE photo_category='$phtocat' and `photo_owner`='$client'"; $result = $mysqli->query($query) or die($mysqli->error.__LINE__); //Define number of columns to use $maxColumns = 5; $count = 0; //Var to count records $categoryList = ''; //Var to hold HTML output while($row = $result->fetch_assoc()) { $count++; //Increment count //Open new row if first record in row if($count % $maxColumns == 1) { $categoryList .= "<tr>\n"; } $image_dir = "members/$client/photos"; $pid = $row['photo_id']; //Output current record $categoryList .= "<td align=center width=20%> <a href={$image_dir}/{$row[photo_filename]} rel=lightbox title='{$row[photo_caption]}'><img src={$image_dir}/tb_{$row[photo_filename]} border='0' alt='{$row[photo_caption]}' /></a> <br> <A HREF=\"javascript:popUpPic('printimage.php?pid={$pid}&client={$client}')\"><img src=images/print.jpg></a> <a href=\"downloadimage.php?file={$image_dir}/{$row[photo_filename]}\" onclick=\"this.blur();\"><img src=images/download.jpg></a> <a href=removephoto.php?pid=$pid&photo_owner=$client><img src=images/delete2.jpg></a> </td>\n"; //Close row if last record in row if($count % $maxColumns == 0) { $categoryList .= "</tr>\n"; } } //Close last row if needed if($maxColumns % $count != 0) { $categoryList .= "</tr>\n"; } ?> <table align="center" width="95%" border="0"> <?php echo $categoryList; ?> </table> Error I am getting: Warning: Division by zero in showphoto.php on line 259 I am not sure how to make it say "There are no pictures in this category" Could somebody please give me a hand. I have tried an else { echo "There are no......."; but with no luck I still get the error. Link to comment https://forums.phpfreaks.com/topic/273346-not-sure-how-to-honestly/ Share on other sites More sharing options...
jazzman1 Posted January 19, 2013 Share Posted January 19, 2013 Where is the showphoto.php file and the line #259 ? Link to comment https://forums.phpfreaks.com/topic/273346-not-sure-how-to-honestly/#findComment-1406870 Share on other sites More sharing options...
SkyRanger Posted January 19, 2013 Author Share Posted January 19, 2013 Sorry knew I forgot something if($maxColumns % $count != 0) { $categoryList .= "</tr>\n"; } It works no problem when there is something in the database for this category but when it is empty I get the error. Link to comment https://forums.phpfreaks.com/topic/273346-not-sure-how-to-honestly/#findComment-1406872 Share on other sites More sharing options...
Jessica Posted January 19, 2013 Share Posted January 19, 2013 Check if $count is not 0 first. Link to comment https://forums.phpfreaks.com/topic/273346-not-sure-how-to-honestly/#findComment-1406873 Share on other sites More sharing options...
SkyRanger Posted January 19, 2013 Author Share Posted January 19, 2013 Thanks Jessica, got it to work, I just added this if ($result->num_rows == 0) { $categoryList .= "<tr><td>No Images</td></tr>"; } else { original while code } Link to comment https://forums.phpfreaks.com/topic/273346-not-sure-how-to-honestly/#findComment-1406883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.