SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question empty not being empty

    Hello,
    I have the following code:

    PHP Code:
    <div class="tab-page">
        <h2 class="tab">Links</h2>

        <img src="img/headings/links.jpg" alt="Related Links" /><br />
                        

          <?php
        $sqlrellinks 
    mysql_query("SELECT atm_rellinks.rellink_linkname, atm_rellinks.rellink_link
    FROM atm_rellinks,atm_rellink_resort
    WHERE atm_rellink_resort.resort_id='
    $resortid'
    and atm_rellink_resort.rellink_id = atm_rellinks.rellink_id"
    ); 
        
    if (!empty(
    $sqlrellinks)) {
        
        echo 
    '<ul>';
        while (
    $line2 mysql_fetch_array($sqlrellinks)) {
        
        echo 
    '<p><li><a target="_blank" href="'$line2['rellink_link'] .'">'$line2['rellink_linkname'] .'</a></li></p>';
        
        }
        echo 
    '</ul>';
        
    }else{
    echo 
    "<p>No Related links are currently available.</p>";
    }    
        
    ?>

    <br /><br />

    </div>
    I am running the code on a apge where $resortid is 2. The query when run outside of php in a program such as SQL Yog displays no results so shouldn;t my page resturn the echoed statement? For some reason the staement saying no links are available is not being shown. Whats happening?

    Thanks

    Neil

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    mysql_query will return false if the query fails. In this case the query is executed successfully and returns a resource to the result set. How many rows, doesn't matter, 0 or not returns the same result.

    What you're looking for is mysql_num_rows, which will return the actual number of rows in the result set.
    Saul

  3. #3
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I ahve updated my code to be like the following:

    PHP Code:
    <div class="tab-page">
        <h2 class="tab">Links</h2>

        <img src="img/headings/links.jpg" alt="Related Links" /><br />
        
    <?php
        $sqlrellinks 
    mysql_query("SELECT atm_rellinks.rellink_linkname, atm_rellinks.rellink_link
    FROM atm_rellinks,atm_rellink_resort
    WHERE atm_rellink_resort.resort_id='
    $resortid'
    and atm_rellink_resort.rellink_id = atm_rellinks.rellink_id"
    ); 
        
        if (!
    mysql_num_rows($sqlrellinks) = 0) {
            echo 
    '<ul>';
            while (
    $line2 mysql_fetch_array($sqlrellinks)) {
                echo 
    '<p><li><a target="_blank" href="'$line2['rellink_link'] .'">'$line2['rellink_linkname'] .'</a></li></p>';
                }
            echo 
    '</ul>';
        
        }else{
            echo 
    "<p>No Related links are currently available.</p>";
        }    
    ?>

    <br /><br />

    </div>
    But I get the following error:

    Fatal error: Can't use function return value in write context in C:\wamp\www\template atm\detail_resort.php on line 226

    Please Help

    Thanks
    Neil

  4. #4
    SitePoint Zealot Dachande663's Avatar
    Join Date
    Feb 2005
    Location
    Birmingham, UK
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change:
    PHP Code:
    if (!mysql_num_rows($sqlrellinks) = 0) { 
    to
    PHP Code:
    if (mysql_num_rows($sqlrellinks)>
    Web Developer & Geek: hybridlogic.co.uk ~ lukelanchester.com

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    = means assign a value

    == means check for a value

    Which one do you think you need?
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh yeah, that always catches me out, I frget it all the time, I just used:

    if (mysql_num_rows($sqlrellinks)>0 { as someone suggested and added the missing ")" and it works fine!

    Thanks all


Bookmarks

Posting Permissions

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