+ Reply to Thread
Results 1 to 8 of 8

Thread: MySQL troubles

  1. #1
    Luigi-San is offline x10Hosting Member Luigi-San is an unknown quantity at this point
    Join Date
    Dec 2006
    Posts
    14

    MySQL troubles

    When I try to view threads on my forum, the posts don't show up and I get the following error:

    Code:
    Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/luigisan/public_html/yiteamforums.it.cx/thread.php on line 162
    Help!

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: MySQL troubles

    In the script thread.php, on line 162, it tries to read the results of a MySQL query.
    The problem is that the results it is trying to read is not valid.
    That us usually because the query was not properly constructed. It can also be because you never connedted to the database.

    Without actually seeing the code from thread.php, there is very little we can do to help you.
    Nothing is always absolutely so.

  3. #3
    Luigi-San is offline x10Hosting Member Luigi-San is an unknown quantity at this point
    Join Date
    Dec 2006
    Posts
    14

    Re: MySQL troubles

    Quote Originally Posted by descalzo View Post
    In the script thread.php, on line 162, it tries to read the results of a MySQL query.
    The problem is that the results it is trying to read is not valid.
    That us usually because the query was not properly constructed. It can also be because you never connedted to the database.

    Without actually seeing the code from thread.php, there is very little we can do to help you.
    Here's the code:
    Attached Files

  4. #4
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: MySQL troubles

    The error is in line 135 in the query. I think the part "FROM posts p,posts_text" is wrong. As far as I know it's not possible to select from two tables, so that wouldn't be correct.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  5. #5
    Luigi-San is offline x10Hosting Member Luigi-San is an unknown quantity at this point
    Join Date
    Dec 2006
    Posts
    14

    Re: MySQL troubles

    Thanks for that. But what exactly should I change it to?

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: MySQL troubles

    Quote Originally Posted by marshian View Post
    The error is in line 135 in the query. I think the part "FROM posts p,posts_text" is wrong. As far as I know it's not possible to select from two tables, so that wouldn't be correct.
    Yes you can. It's called a join.

    Don't have time right now, will post some suggestions in about two hours.
    Nothing is always absolutely so.

  7. #7
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: MySQL troubles

    Here's a quick one (and probably Descalzo's first suggestion): on line 136, insert a test on the result of the query, and print the MySQL error message if $posts is false.
    PHP Code:
        if (False === $posts) {
            echo 
    mysql_error();
        } 
    Once you've got the error message, comment out the new code and post the error here. Once your issue is resolved, delete the new code.

    If you had written the script, the proper solution would be to test the query results immediately before the for loop that calls mysql_fetch_array, and only enter the loop if the result is valid.
    Last edited by misson; 02-02-2010 at 06:15 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  8. #8
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: MySQL troubles

    What I would do....

    Code:
    $min=$ppp*$page;   // FIND THIS TO BEGIN EDITS...
    
      // write SQL queries as separate strings, so you can see what they actually are,
     // not what you think they are 
    if($id){
      $sqlquery1= "SELECT p.*,text$sfields,edited,tagval,u.id uid,name,$ufields,regdate FROM posts p,posts_text LEFT JOIN users u ON p.user=u.id WHERE thread=$id AND p.id=pid ORDER BY p.id LIMIT $min,$ppp";
      $posts=mysql_query($sqlquery1);
      if (False === $posts) { 
            echo "Error with \$id = $id <br/>";
            echo mysql_error(); 
            echo "<br/>SQL: $sqlquery1 " ;
      }
    
    } elseif($usr){
      $thread[replies]=mysql_result(mysql_query("SELECT count(*) FROM posts WHERE user=$usr"),0,0)-1;
    
      $sqlquery2 = "SELECT p.*,text$sfields,edited,tagval,u.id uid,name,$ufields,regdate FROM posts p,posts_text LEFT JOIN users u ON p.user=u.id WHERE user=$usr AND p.id=pid ORDER BY p.id LIMIT $min,$ppp" ;
      $posts=mysql_query($sqlquery2);
    
      if (False === $posts) { 
            echo "Error with \$usr = $usr <br/>";
            echo mysql_error(); 
            echo "<br/>SQL: $sqlquery2 " ;
      }
        }
    Nothing is always absolutely so.

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  3. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  4. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM
  5. MySQL Troubles
    By blackholesun in forum Free Hosting
    Replies: 2
    Last Post: 07-25-2005, 04:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers