Forum Moderators: coopster

Message Too Old, No Replies

Put an If statement around a Select statement

If select equls true echo results

         

ski442

9:30 pm on Jan 20, 2010 (gmt 0)

10+ Year Member



Hi Guys.
Is it possible to do somthing like
<?php
If query == true
$queryInfo =mysql_query ( "SELECT * FROM table WHERE CatSeq = $Scatseq AND CatPage = $Scatpage AND stknum != $Sstockcode");
while($myrowInfo = mysql_fetch_assoc($queryInfo))
{ ?>

<? echo $myrowInfo["Image"] ?>
<? echo $myrowInfo["price"] ?>
etc

Its like it needs to run the sql, check to see if any thing is there then echo output, if no output the users don't see anything.
Thanks guys
Ski442

d40sithui

10:48 pm on Jan 20, 2010 (gmt 0)

10+ Year Member



Yes,
You can check if any rows are returned by the query using mysql_num_rows(). If it returns a 0, then your query returned no rows. If it returns any number higher than 0, then your query has at least one affected row(s).

if(mysql_num_rows($queryInfo)){
//if query returns rows->print results here
}
else{
//do nothing
}

ski442

11:48 pm on Jan 20, 2010 (gmt 0)

10+ Year Member



Hi d40sithui
Thanks very much, worked like charm
Cheers :)
Ski441