Jump to content

Inner join...


arunpatal
Go to solution Solved by arunpatal,

Recommended Posts

Throw away my query - it won't work for what you are trying to do.

 

What does "$datatb" contain in your links where you have "&datatb=$datatb"?

$datatb is a topic table....

 

id int auto_increment primary key,

    topic_title mediumtext,

    topic_detail mediumtext,

    added_date date,

    sub_id int(11) This is where sub_cat_id from subcategory table is saved

 

 

and my subcategory table is like this

 

sub_cat_id int auto_increment primary key,

sub_cat_name varchar(500),

category_id int(11)

Link to comment
Share on other sites

I assume the <div>s have a float:left style. Try

$datatb = 'datatb';

$sql = "SELECT s.sub_cat_id, s.sub_cat_name, t.id, t.topic_title
    FROM (
        SELECT sub_cat_id, sub_cat_name
        FROM subcategory
        ORDER BY sub_cat_id DESC
        LIMIT 5
        ) as s
    INNER JOIN $datatb t 
        ON (s.sub_cat_id=t.sub_id)
    ORDER BY s.sub_cat_id DESC , t.id DESC";

$res = mysql_query($sql);
$prev = '';
while ($row = mysql_fetch_assoc($res)) {
    if ($prev != $row['sub_cat_id']) {      // has sub_cat changed?
        echo "{$row['sub_cat_name']}<br>";
        $prev = $row['sub_cat_id'];
    }
    echo "<div class='topic_list' id='topic_list{$row['id']}'> <a href='review.php?topic_id={$row['id']}&datatb=$datatb'>";
        echo strtoupper($row['topic_title']);
        echo "</a></div>";
}
Link to comment
Share on other sites

  • Solution

 

I assume the <div>s have a float:left style. Try

$datatb = 'datatb';

$sql = "SELECT s.sub_cat_id, s.sub_cat_name, t.id, t.topic_title
    FROM (
        SELECT sub_cat_id, sub_cat_name
        FROM subcategory
        ORDER BY sub_cat_id DESC
        LIMIT 5
        ) as s
    INNER JOIN $datatb t 
        ON (s.sub_cat_id=t.sub_id)
    ORDER BY s.sub_cat_id DESC , t.id DESC";

$res = mysql_query($sql);
$prev = '';
while ($row = mysql_fetch_assoc($res)) {
    if ($prev != $row['sub_cat_id']) {      // has sub_cat changed?
        echo "{$row['sub_cat_name']}<br>";
        $prev = $row['sub_cat_id'];
    }
    echo "<div class='topic_list' id='topic_list{$row['id']}'> <a href='review.php?topic_id={$row['id']}&datatb=$datatb'>";
        echo strtoupper($row['topic_title']);
        echo "</a></div>";
}

First of all thanks that you came back and helped.......

Next time i will make sure that i can provide maximum and clear information. :)

 

Now the good thing :)

 

This works......  now showing exactly the way i want...

 

Many thanks to Barand & Jazzman1

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.