Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    Why am i getting Resource id #5 when i run this function??

    PHP Code:
    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 />";
            }


  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    PHP Code:
    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($result0) : 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 />";
            }


  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    PHP Code:
    $countAds = ((mysql_num_rows($result)) ? mysql_result($result0) : 0); 
    what does this line mean??

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Firstly, does it now work as expected?

  • Users who have thanked MattF for this post:

    kevinkhan (11-16-2010)

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    Firstly, does it now work as expected?
    yes perfect thanks for your help

    PHP Code:
    $countAds = ((mysql_num_rows($result)) ? mysql_result($result0) : 0); 
    i just never seen the above notation ie ? and : 0 part of the above line

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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]);

  • Users who have thanked MattF for this post:

    kevinkhan (11-16-2010)

  • #7
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    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.

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    It's explained more indepth here:

    http://uk2.php.net/manual/en/languag...comparison.php

    Look for the ternary operator.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •