PDA

View Full Version : PHP - if a MySQL row is empty then do



Kolusion
December 3rd, 2011, 03:57 AM
How can I make it so if a MySQL row is empty, then do? I tried this, but it didn't work. $query = "SELECT * FROM products WHERE availability = 'yes' AND categorydir = 'belts' AND fordir = 'menswear'"; The problem is that there are matches to my MySQL query, but the ($row == "") stringis taking effect and causing nothing to display. Sorry for the page layout. I am using a web proxy that has been coded badly.

Kolusion
December 3rd, 2011, 04:07 AM
Its cool, I solved it: if (!$row['id'] == "") {

Kolusion
December 3rd, 2011, 06:02 AM
That actually didn't solve it, all it did was skip the string all together. This is is what I actually needed. All I had to do was add it to the end of the code. Bloody hell!
if ($listing == 0) {echo "";}

Petrolea
December 3rd, 2011, 02:25 PM
Its cool, I solved it: if (!$row['id'] == "") {

If your query doesn't return a column with name 'id', then this statement will fail. It will also fail if only 'id' is empty.

Use a loop to check all elements in a row.



foreach($row as $r)
{
if(empty($r)) //do something to later tell whether its empty or not
}

dazman19
December 9th, 2011, 09:43 AM
if(mysql_num_rows($resource) === 0) {
//true (no results) do this...

}