super-newbie variable question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevinwinters
Forum Newbie
Posts: 20
Joined: Wed Jan 06, 2010 8:31 pm

super-newbie variable question

Post by kevinwinters »

I create a variable "$num_rows" and assign it to a record result from a mysql query - why can't I access that variable later? sorry if this is a real silly question

Code: Select all

 
$query="SELECT * FROM testable WHERE `NAME`='AVAILABLE'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
// works here but not down below
echo "$num_rows Rows\n";
 
if ($num_rows = 0) {
    echo "<br><h2 style=\"color: #ff0000\">This set of is completly filled out</h2><br>";
}
// find out why this doesn't work 
 
echo "$num_rows". " left";
 
 
Thanks for any help
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: super-newbie variable question

Post by AbraCadaver »

Code: Select all

if ($num_rows = 0) {
If the assignment of 0 to $num_rows is successful. So you have set $num_rows=0. = is assignment, == and === are comparison.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply