SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $count doesnt not count how many rows in a table

    i am trying to a custom intergration for a php script for a friend and i have this php code i have made for displaying navagation but for some odd reason it doesnt show up seems fine to me

    PHP Code:
    $rQuery="SELECT * FROM navagation WHERE type='1'";
    echo 
    $rQuery;
    $result=mysql_query($rQuery);
    if(!
    $result)
    {
            echo 
    "Error";
    }
    else
    {
        
    //
        
    echo "Result is Fine";
        
    $count=$result->num_rows;
        if(
    $count>0)
        {
            echo 
    "Count is  more than 1";
            while(
    $data=$result->fetch_assoc())
            {
                echo 
    "&nbsp;&raquo; <a href=".$data['navlink']."\>".$data['navname']."</a><br>";
            }
        }
        else
        {
            
            echo 
    "Navagation is Empty";echo "There ".$count."in the navagation table";
        }
        
    //

    the error i am getting is this

    PHP Code:
    SELECT FROM navagation WHERE type='1'Result is FineNavagation is EmptyThere in the navagation table 
    nothing else

    What i am doing wrong hhow can i fix this?

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Use mysql_num_rows; mysql_query doesn't return an object.

    PHP Code:
    $count=mysql_num_rows($result); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and instead of

    PHP Code:
    while($data=$result->fetch_assoc()) 
    use

    PHP Code:
    while($data=mysql_fetch_assoc()) 

  4. #4
    SitePoint Zealot shoorace's Avatar
    Join Date
    Jun 2005
    Location
    Florida
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is $result an object for your class, that you have not mentioned here?

  5. #5
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by shoorace
    Is $result an object for your class, that you have not mentioned here?
    It most likely isn't. if you see the code posted above you'll notice that $result is the MySQL result resource as returned by the function mysql_query(). So $result->fetch() wouldn't work.

  6. #6
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Most likely, William, you want mysqli

  7. #7
    SitePoint Addict Wildhoney's Avatar
    Join Date
    Apr 2006
    Location
    Nottingham
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Most likely, William, you want mysqli
    You've got it. They then do return as objects to which makes sense after observing the way you've implemented it.
    TalkPHP.com - The Friendly PHP Community

    Watch Reaper Online - Watch Chuck Online


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
  •