-1

In simple data to fetch,working correctly but if something not found then not throwing message.It means if i search for something and found it will fetch, but if not nothing returned on screen, while i want display 'nothing found' message .Please help:

$email= $_GET['email'];
$a = $conn->prepare("SELECT `id` FROM `userdata` WHERE `diary`=?");
$a->bind_param("s", $email);
$a->execute();
$res = $a->get_result();
if ($res->num_rows > 0) {
    while ($row = $res->fetch_assoc()) {
        echo $row['id'];
    }

} else {
    echo'Nothing found';
}
 // Close the prepared statement.
    $a->close();
    $conn->close();
125fura
  • 383
  • 2
  • 13

2 Answers2

0

you need to check for null value also

//your code ...
if ($res->num_rows > 0 && !is_null($res)) 
//your code ...
Ashish Ranade
  • 595
  • 2
  • 14
-1

There was some typo (or measurement error), that is now gone. This is obviously working code in the OP, no additions needs to be done. Especially in the course of getting number of rows found, as it's already worked even in the beginning.

And the OP is now praising completely wrong answers, wrongly attributing their now working code to these useless suggestions.

I wonder if this question ever be deleted.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • Actually error in your point of view,it doesn't matter how many better answers i recieved, for me or anyone who do programming only working code matters. – 125fura Aug 20 '15 at 11:26
  • And it doesn't means others answers are wrong or bad, but i'm not going to change my whole code or implemented style for the sake of good or better answer.They can be praised but depends on me to implement or not. – 125fura Aug 20 '15 at 11:28