Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

How to keep value from showing if its empty?

Hi, my function is showing images like I want.

but there always seems to be one image that doesnt show and it says its information is nothing.  I check my database many times to make sure there are no empty fields and there are none.

http://auroriella.com/index.php

I tried this:

if($featured != "") {

and

if(!empty($featured)) {

but its still letting values in that are nothing!  Any ideas?


// Displays the featured products randomly
function featured_products() {
      global $conn;
      /*
      $query = "SELECT * FROM bracelets WHERE featured=1 ";
    $query .= "UNION ALL SELECT * FROM earrings WHERE featured=1 ";
    $query .= "UNION ALL SELECT * FROM necklaces WHERE featured=1 ";
      */
      $query = "SELECT 'bracelets' as theTable,  id, filename FROM bracelets WHERE featured=1 ";
    $query .= " UNION ALL SELECT 'earrings'  as theTable,  id, filename FROM earrings WHERE featured=1 ";
    $query .= " UNION ALL SELECT 'necklaces' as theTable,  id, filename FROM necklaces WHERE featured=1 ";
      $result = mysql_query($query, $conn) ;
      confirm_query($result);

      $output = "";
      // These loops output the subject names with their corresponding pages underneath them
      $featured=array();
      while ($featured[] = mysql_fetch_assoc($result))
      {
            //do nothing here
      };

      //"randomize"
      shuffle($featured);
	  if($featured != "") {
		  foreach($featured as $images){
				$output .= "<a href=\"" . substr($images['theTable'], 0, -1) . ".php?item=" . urlencode($images['id']) . "\">";
				$output .= "<img src=\"" . $images['theTable'] .'/'.$images['filename'] . ".png\" />";
		  }
	  }
      return $output;
}

Open in new window

0
FairyBusiness
Asked:
FairyBusiness
1 Solution
 
hieloCommented:

// Displays the featured products randomly
function featured_products() {
      global $conn;
      /*
      $query = "SELECT * FROM bracelets WHERE featured=1 ";
    $query .= "UNION ALL SELECT * FROM earrings WHERE featured=1 ";
    $query .= "UNION ALL SELECT * FROM necklaces WHERE featured=1 ";
      */
      $query = "SELECT 'bracelets' as theTable,  id, filename FROM bracelets WHERE featured=1 ";
    $query .= " UNION ALL SELECT 'earrings'  as theTable,  id, filename FROM earrings WHERE featured=1 ";
    $query .= " UNION ALL SELECT 'necklaces' as theTable,  id, filename FROM necklaces WHERE featured=1 ";
      $result = mysql_query($query, $conn) ;
      confirm_query($result);

      $output = "";
      // These loops output the subject names with their corresponding pages underneath them
      $featured=array();
      while ($featured[] = mysql_fetch_assoc($result))
      {
            //do nothing here
      };

      //"randomize"
      shuffle($featured);
	  if( !empty($featured) ) {
		  foreach($featured as $images){
                       if(!empty($images))
                       {
				$output .= "<a href=\"" . substr($images['theTable'], 0, -1) . ".php?item=" . urlencode($images['id']) . "\">";
				$output .= "<img src=\"" . $images['theTable'] .'/'.$images['filename'] . ".png\" />";
                       }
		  }
	  }
      return $output;
}

Open in new window

0
 
FairyBusinessAuthor Commented:
Thanks!
0
 
DzynitCommented:
Try changing that to if ($images['filename'] != "")
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now