Jump to content

Help, getting info from two mysql tables with one query


ryandarin

Recommended Posts

I think the code is fairly self explanatory, so i'll post that first.

$query = "SELECT id,description,Title,tutorialtext,category," . 
                 "DATE_FORMAT(timeadded, '%Y-%m-%d') as date " . 
                 "FROM tutorial ORDER BY timeadded DESC LIMIT $max_items";

$query2 = "SELECT Name, catid," .
    "From tutorial_cats"

    $result = mysql_query ($query);
    while ($row = mysql_fetch_assoc ($result))

Im probably missing something simple, but how do I combine query and query2 togther so that it gets both the things from tutorial, and from tutorial_cats?

 

Tell me if you need more info, or if im not making sense.

 

Thanks alot :), Ryan.

$query = "SELECT t.id, t.description, t.Title, t.tutorialtext, t.category, c.Name 
            DATE_FORMAT(t.timeadded, '%Y-%m-%d') as date  
            FROM tutorial t
            INNER JOIN tutorial_cats c ON t.category = c.cat_id
            ORDER BY t.timeadded DESC 
            LIMIT $max_items";

Hmm, I added this, but then it gives me this error, its probably a stupid mistake by me, but this is the error.

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/tutorialscript/index.php on line 21

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.