...

View Full Version : Why am i getting Resource id #5 when i run this function??



kevinkhan
11-16-2010, 07:01 PM
function resetPublished($con) {
echo "UPDATE Classified SET `published`=0 WHERE `published`=3 AND UNIX_TIMESTAMP()-`created`>(172800/2)";

$countAds = mysql_query("SELECT COUNT(*) FROM Classified WHERE published <3", $con);
echo "<hr />".$countAds."<hr />";
if($countAds <1)
{
echo "<hr />".$countAds."<hr />";
$ret = mysql_query("UPDATE Classified SET `published`=0 WHERE `published`=3", $con);
return $ret;
}
else
{
echo "<hr />there are still ads with published <3<hr />";
}
}

MattF
11-16-2010, 07:08 PM
function resetPublished($con) {
echo "UPDATE Classified SET `published`=0 WHERE `published`=3 AND UNIX_TIMESTAMP()-`created`>(172800/2)";

$result = mysql_query("SELECT COUNT(*) FROM Classified WHERE published <3", $con);
$countAds = ((mysql_num_rows($result)) ? mysql_result($result, 0) : 0);
echo "<hr />".$countAds."<hr />";
if($countAds <1)
{
echo "<hr />".$countAds."<hr />";
$ret = mysql_query("UPDATE Classified SET `published`=0 WHERE `published`=3", $con);
return $ret;
}
else
{
echo "<hr />there are still ads with published <3<hr />";
}
}

kevinkhan
11-16-2010, 07:25 PM
$countAds = ((mysql_num_rows($result)) ? mysql_result($result, 0) : 0);

what does this line mean??

MattF
11-16-2010, 07:27 PM
Firstly, does it now work as expected?

kevinkhan
11-16-2010, 07:31 PM
Firstly, does it now work as expected?

yes perfect thanks for your help


$countAds = ((mysql_num_rows($result)) ? mysql_result($result, 0) : 0);

i just never seen the above notation ie ? and : 0 part of the above line

MattF
11-16-2010, 07:36 PM
When you do the query, you are getting resource for a query result, not the result of the query itself. You need to fetch the result. That line checks as to whether any rows, (results), are available and if so returns the result. If there are no rows, it defaults to 0. That code works along the lines of:

$value = ((if this part equals true) ? [this code runs] : [else this code runs if it was false]);

kevinkhan
11-16-2010, 07:39 PM
When you do the query, you are getting resource for a query result, not the result of the query itself. You need to fetch the result. That line checks as to whether any rows, (results), are available and if so returns the result. If there are no rows, it defaults to 0. That code works along the lines of:

$value = ((if this part equals true) ? [this code runs] : [else this code runs if it was false]);

ok thanks.. jez you learn something new every day..

that will be usefull in the future.

Thanks again.

MattF
11-16-2010, 07:45 PM
It's explained more indepth here:

http://uk2.php.net/manual/en/language.operators.comparison.php

Look for the ternary operator.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum