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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question displaying a statement for 'no results'

    Hi. I'm pretty new to the php coding thing, kinda learning as I go when I have time. Well, I getting ready to start up a gaming ladder and when I click on our "match results" link, it outputs this error:

    Code:
    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /*/*/*/bani/functions/matchdb.php on line 61
    And thats because the database is empty as there are no recorded matches yet. I tested this. If I entered in a match, the error goes away and the match result is displayed.

    Here's the code:

    PHP Code:
    $result=mysql_query("SELECT matchid,winnerid,loserid,winneralias,loseralias,ladderid,laddername,DATE_FORMAT(reportdate, '%M %d, %l:%i %p'),reporterip,confirmerip from matchdb ORDER BY reportdate desc LIMIT $start,$stop");

    while(list(
    $matchid,$winnerid,$loserid,$winneralias,$loseralias,$ladderid,$laddername,$reportdate,$reporterip,$confirmerip)=mysql_fetch_row($result)) 
    Note: Line 61 is the "while(list"

    I can't figure out how to make it so that when it searches the db and there isn't anything, it will say "There are no recorded matches at this time."

    Can anyone help me? Thanks in advance.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    when you put [php]$rows = mysql_fetch_rows() put an @ infront of it to hide the error and then in your main part put
    PHP Code:
    if($rows >= 1){
    echo 
    'The amount of rows is ' $rows;
    }
    else {
    echo 
    'There are no recorded matches at this time.';

    Something like that will work...
    Last edited by Mwnciau; 06-19-2006 at 04:55 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your error is not caused by an empty result set; there's something going wrong with your query call. Use mysql_error() to find out what it is.

  • #4
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kid Charming
    Your error is not caused by an empty result set; there's something going wrong with your query call. Use mysql_error() to find out what it is.
    Ok. I did that and here is what it said:

    Quote Originally Posted by MySQL Query
    A fatal MySQL error occured.
    Query:
    Error: (1065) Query was empty
    Mwnciau: I'll try what you suggested. I don't need the output though for the for if there is something, just something to say there aren't any results. Thanks. I'll reply with results .

    _____

    edit:

    Didn't work. I still get the error. I also tried having the '@' in front of 'while' and I got a T_WHILE parse error. Just a note, I'm having a problem with the 'while(list(' statement... Still working on it. I tried to do:

    PHP Code:
    if($row ==){
    echo 
    'There are no match records at this time.';

    but that didn't work either.
    Last edited by xAtlas; 06-16-2006 at 04:39 AM.

  • #5
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Move the closing doublequotes outside the closing parenthesis in your query:

    LIMIT $start,$stop)";

    [Edit]My bad. Never mind this post.
    Last edited by Kid Charming; 06-16-2006 at 05:13 AM.

  • #6
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kid Charming
    Move the closing doublequotes outside the closing parenthesis in your query:

    LIMIT $start,$stop)";
    Tried and got an ugly parse error. You're having me edit this line:
    PHP Code:
    $result=mysql_query("SELECT 
    But the error says its being generated from this one:

    PHP Code:
    while(list($matchid,$winnerid,$loserid,$winneralias,$loseralias,$ladderid,$laddername,$reportdate,$reporterip,$confirmerip)=mysql_fetch_row($result)); 
    It has the "=mysql_fetch_row($result)" at the end of it.
    Last edited by xAtlas; 06-16-2006 at 05:07 AM.

  • #7
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I was high -- forget that last post of mine.


    Try putting your query into a variable, echoing it out, and posting the result.

  • #8
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The mysql_num_rows() is raising the error, but that's because there's something wrong with your query -- your mysql_query() is returning FALSE instead of a result resource, and that's causing the mysql_num_rows() error.

  • #9
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kid Charming
    The mysql_num_rows() is raising the error, but that's because there's something wrong with your query -- your mysql_query() is returning FALSE instead of a result resource, and that's causing the mysql_num_rows() error.
    oh. I see. Ok then, I'll see what I can draw up and post the results (again lol). thanks.

  • #10
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok. After all this time, I still can't figure this one out. Can anyone out there throw me some other ideas?

    ____

    EDIT:

    I figured out what the problem was. It was this part of the 'mysql_query()':

    PHP Code:
    desc LIMIT $start,$stop 
    Can anyone tell me what that is supposed to do? I'm modifying a ladder that was pre-scripted (which means the author did this).
    Last edited by xAtlas; 06-19-2006 at 04:06 AM.

  • #11
    New Coder
    Join Date
    Aug 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this were you are echo'ing out the query. You might see the problem right away, if not, run it in phpmyadmin or command shell, and see what it says.

    PHP Code:
    $select "SELECT matchid, winnerid, loserid, winneralias, loseralias, ladderid,  laddername,
                      DATE_FORMAT(reportdate, '%M %d, %l:%i %p'), reporterip, confirmerip 
               FROM matchdb 
               ORDER BY reportdate desc 
               LIMIT $start,$stop"
    ;
    $result=mysql_query($select) or die ("Can't get stuff " mysql_error());
    echo (
    $select); 
    do you get any errors?

  • #12
    New Coder
    Join Date
    Aug 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to answer you question on what desc is doing. It is part of your ORDER BY, and it will order them descending. the LIMIT $start, $stop will start at a record set position and how many to rows from that position to display. An example of this would be say you have a record set that has 10 rows and each row has one field with letters a-j. LIMIT 1, 2 would display b and c. LIMIT 0,1 would display a.

  • #13
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    have you fixed this yet?
    If not try putting this around mysql_fetch_row() :

    PHP Code:
    if ($results){// if the mysql_query returns info and there is no error
    //...
    }
    else {
    echo 
    'no rows!';


  • #14
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mwnciau

    PHP Code:
    if ($results){// if the mysql_query returns info and there is no error 

    Just to clarify -- checking the boolean value of $results will only determine whether there has been an error in your mysql_query() call. It will not tell you if you have no data. If you send the query:

    Code:
    SELECT * FROM table WHERE column='foo'
    and you don't have a column that equals 'foo', then you will still get a result resource. To check if you have rows, you then need to run that resource through mysql_num_rows(). mysql_query() only returns FALSE if there is an error sending the query.

  • #15
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by flann
    to answer you question on what desc is doing. It is part of your ORDER BY, and it will order them descending. the LIMIT $start, $stop will start at a record set position and how many to rows from that position to display. An example of this would be say you have a record set that has 10 rows and each row has one field with letters a-j. LIMIT 1, 2 would display b and c. LIMIT 0,1 would display a.
    Ok. I understand what you are saying. But why is it causing the error? If I remove it, no error and everything is kosher. Could it be the $start,$stop? Should there be numbers instead? And thank you all that are helping . I appreciate every instance!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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