imarockstar Posted September 8, 2008 Share Posted September 8, 2008 I have this site that displays images .. .but if there is nothing in the databse .... I need it to display a message saying that there are no pictures .... here is my code : <div class=head1>todays photos</div> <?php $today = date('F jS Y', time()); $time = mktime(23,59,58); $start_time = mktime(0,0,3); $pictures = m_q('SELECT picture, id FROM piks WHERE `uploaded` < '.$time.' AND `uploaded` > '.$start_time.' ORDER BY RAND() LIMIT 80'); if (mysql_num_rows($pictures) == 0) { //No pictures. } else { //add the pictures. $pics = array(); while($pic = mysql_fetch_assoc($pictures)) { if (!file_exists(dirname(__FILE__).'/../pics/'.$pic['picture']) || !is_file(dirname(__FILE__).'/../pics/'.$pic['picture'])) { continue; } $imagesrc = "pics/".$pic['picture']; $imagesrc = imgsrc($imagesrc, '53', '53', '1:1'); $pics[] = "<div class='todaysphotospic'><a href='showphoto.php?pic={$pic['id']}'><img src='$imagesrc' border='0'></a></div>"; } } ?> <div class=head2>all photos uploaded today <?=$today?></div> <?=@join("\n", $pics);?> <div class=clear></div> If there are no images in the database ... I need is to display " NO IMAGES " ... any clue ? Link to comment https://forums.phpfreaks.com/topic/123287-if-there-is-nothing-in-the-database/ Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 Why not do it here? if (mysql_num_rows($pictures) == 0) { //No pictures. Link to comment https://forums.phpfreaks.com/topic/123287-if-there-is-nothing-in-the-database/#findComment-636712 Share on other sites More sharing options...
obsidian Posted September 8, 2008 Share Posted September 8, 2008 When you query for your images, just check the count of your returned records. If it is less than 1, display "no images". <?php $sql = mysql_query(/* Your images query goes here */); if (mysql_num_rows($sql) < 1) { echo "NO IMAGES"; } else { // Loop over and display the images. } ?> Link to comment https://forums.phpfreaks.com/topic/123287-if-there-is-nothing-in-the-database/#findComment-636713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.