Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Problem with getting data from mysql

  1. #1
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with getting data from mysql

    I have this problem when i try to get my data from the mysql db -->

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/hosting/l2/web/index.php on line 142
    This is my script:

    <?php
    include 'inc/config.php';
    include 'inc/mysql.php';

    $query = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESC".
    "SELECT user_id FROM phpbb_users";
    $result = mysql_query($query);

    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    echo "<a href='forum/viewtopic.php?t={$row['topic_id']}'> {$row['topic_title']} <b>by</b> <a href='forum/profile.php?mode=viewprofile&u={$row['user_id']}'> {$row['topic_poster']}<br>";
    }


    include 'inc/cmysql.php';
    ?>

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    $query = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESC".
    "SELECT user_id FROM phpbb_users";
    //Becomes
    $query = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESCSELECT user_id FROM phpbb_users";
    You can perform two operations in one query by separating the lines by a semicolon:

    SELECT ...; SELECT ...;

    However, this doesn't work properly with PHP as it would return two separate sets of results in one query.

    As such, just do one call at a time.

    If you do need to make them integrated, you can try it like this:

    Code:
    $a = mysql_query($query1);
    $b = mysql_query($query2);
    
    while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) ) {
    echo $rowa[1].$rowb[2];
    }
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks i will try it

    P.S. The first one didnt work i will try the second...

  4. #4
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    same....

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/hosting/l2/web/index.php on line 184
    184 line is this:

    while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) )

  5. #5
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    What's $a and $b?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  6. #6
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Its the queries
    $query1 = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESC";
    $query2 = "SELECT user_id FROM phpbb_users";

    $a = mysql_query($query1);
    $b = mysql_query($query2);

    while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) )

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Try:
    PHP Code:
    $query1 "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESC";
    $query2 "SELECT user_id FROM phpbb_users";

    $a mysql_query($query1) or die(mysql_error());
    $b mysql_query($query2) or die(mysql_error());

    while ( (
    $rowa mysql_fetch_assoc($a)) && ($rowb mysql_fetch_assoc($b)) ) 
    and output the errors given.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Now i have MySQL error

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY topic_id DESC' at line 1

  9. #9
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Problem solved syntax fixed ^.^ thanks all

  10. #10
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have another problem... the query for username its not correct ... it shows IDs of usernames only... it dont show the CORRECT THING... im using PHPBB

    This is my whole script....
    <?php
    include 'inc/config.php';
    include 'inc/mysql.php';

    $query1 = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics ORDER BY `topic_id` DESC LIMIT 9";
    $query2 = "SELECT post_username FROM phpbb_posts";

    $a = mysql_query($query1) or die(mysql_error());
    $b = mysql_query($query2) or die(mysql_error());

    while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) )
    {
    echo "<font size=2><a href='forum/viewtopic.php?t={$rowa['topic_id']}'> {$rowa['topic_title']}</a> <font color=grey><b>by</b></font> <a href='forum/profile.php?mode=viewprofile&u={$rowa['topic_poster']}'> {$rowb['topic_username']}</a><br></font>";
    }


    include 'inc/cmysql.php';
    ?>
    You can see the result only at the index page ----> http://l2.headoff.com (Its not advertising only want to show you!!!)

    And it shows latest made TOPICS not POSTS .. i tried to make POSTS but no success ... thanks for trying to help again

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
  •