SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with mysql database retrieval from php script pls

    am a new PHP and MYSQL developer and i am using your book which has been of tremendous help so far especially your examples. However, i am having problems with getting data out of my MYSQL database especially when i want to count the number of affected rows the select statement affects. i get this error and cant seem to get around it for a couple of days now

    e.g mysql_affected_rows(): supplied arguement is not a valid MYSQL result resource
    i also get the same error with mysql_fetch_array, mysql_num_rows and this kinda functions. pls i need your help.

    connection from PHP to mysql db is working well though.

    Simon
    _______________

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Affected rows is only for queries that change the database, like INSERT and UPDATE. If you want to know the number of rows found by a SELECT query, use mysql_num_rows.
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  3. #3
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Phoenix, AZ
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have to supply the query results..

    set variable q = to the mysql_query..

    $q=mysql_query($sql,$con);

    if(mysql_affected_rows($q)>0 || mysql_num_rows($q)>0){
    echo "Hey It Worked!";
    }
    Kreative Development
    Infinite Possibilities

  4. #4
    SitePoint Enthusiast poirot's Avatar
    Join Date
    Jun 2006
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oddly enough, according to PHP.net mysql_affected_rows doesn't need a resource argument.

    http://www.php.net/mysql_affected_rows

    And also if you get 0 rows it doesn't mean the query didnt work.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, it worked!!


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
  •