Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2006
    Location
    Merseyside
    Posts
    2,335
    Tokens
    0

    Latest Awards:

    Default Get data from 2 tables?

    Hey,

    I am getting a bit lost on how to get information from two different tables.

    I have got:

    PHP Code:
     <?
    ob_start
    ();
    include(
    "config.php");

    $amysql_query("SELECT * FROM `swnews` ORDER BY `newsid` DESC LIMIT 5") or die(mysql_error());
    while (
    $b mysql_fetch_array($a)) {
    echo 
    "<br />";
    echo 
    $b['subject'] . '</a></b><br /><i>';
    echo 
    $b['description'] . '</b></i><br />';
    echo 
    $b['contents'] . '</b></i><br />';
    }

    ?>
    However, I need "contents" to come from the table "swarticles" and not "swnews" when the ID = the subject ID (if you understand that).

  2. #2
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
     <?
    ob_start
    ();
    include(
    "config.php");

    $amysql_query("SELECT * FROM `swnews` ORDER BY `newsid` DESC LIMIT 5") or die(mysql_error());
    while (
    $b mysql_fetch_array($a)) {
    $c mysql_query("SELECT * FROM `swarticles` WHERE id='$b[subject]' LIMIT 0,1");
    $d mysql_fetch_array($d);
    echo 
    "<br />";
    echo 
    $b['subject'] . '</a></b><br /><i>';
    echo 
    $b['description'] . '</b></i><br />';
    echo 
    $d['contents'] . '</b></i><br />';
    }

    ?>

  3. #3
    Join Date
    Oct 2006
    Location
    Merseyside
    Posts
    2,335
    Tokens
    0

    Latest Awards:

    Default

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in news.php on line 8
    PHP Code:
    <?
    ob_start
    ();
    include(
    "config.php");

    $amysql_query("SELECT * FROM `swnews` ORDER BY `newsid` DESC LIMIT 5") or die(mysql_error());
    while (
    $b mysql_fetch_array($a)) {
    $c mysql_query("SELECT * FROM `swnewsdata` WHERE id='$b[subject]' LIMIT 0,1");
    $d mysql_fetch_array($d);
    echo 
    "<br />";
    echo 
    $b['subject'] . '</a></b><br /><i>';
    echo 
    $b['description'] . '</b></i><br />';
    echo 
    $d['contents'] . '</b></i><br />';
    }

    ?>
    Can't seem to find the problem. All the databases are there :S

  4. #4
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    oops

    PHP Code:
    <?
    ob_start
    ();
    include(
    "config.php");

    $amysql_query("SELECT * FROM `swnews` ORDER BY `newsid` DESC LIMIT 5") or die(mysql_error());
    while (
    $b mysql_fetch_array($a)) {
    $c mysql_query("SELECT * FROM `swnewsdata` WHERE id='$b[subject]' LIMIT 0,1");
    $d mysql_fetch_array($c);
    echo 
    "<br />";
    echo 
    $b['subject'] . '</a></b><br /><i>';
    echo 
    $b['description'] . '</b></i><br />';
    echo 
    $d['contents'] . '</b></i><br />';
    }

    ?>

  5. #5
    Join Date
    Oct 2006
    Location
    Merseyside
    Posts
    2,335
    Tokens
    0

    Latest Awards:

    Default

    Nope =[

    Edit:// Got it Needed to change id to $b[subject] to $b[newsid].

    Would Rep you Denta but need to spread

    Last edited by Lilian; 29-09-2007 at 07:51 PM.

  6. #6
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    ahh in your post I thought you said subject was the id

Posting Permissions

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