0

I have one table in MySQL which is post_data. consists of fields like (uname, pass, email, cam_name,cam_img, cam_model etc..) when user registered my website some fields get updated like (uname, pass, email) and other fields are empty.but in another page I want to display (cam_img, cam_name) fields based on the columns count in the page.

my code in index.php:


$stmt = $index_home->getDetails();

if($stmt->rowCount() > 0)
{

    while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        extract($row);
    }
        ?>  

getDetails implentation in USER class


public function getDetails()
{
try
{
$stmt = $this->conn->prepare('SELECT userID, user_name, cam_name, cam_model, cam_rent, cam_img, mobile FROM post_data ORDER BY userID DESC');
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
    {
        echo $ex->getMessage();
    }
}

Everything is fine when data is there on selected columns like (cam_name,cam_img etc). But the problem is, when data is not there in those fields it also count all rows in the table. I want to restrict that.

Any suggestions?

A R
  • 1,412
  • 2
  • 14
  • 29
virat121
  • 95
  • 7

0 Answers0