Jump to content

Inner join...


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
https://forums.phpfreaks.com/topic/284343-inner-join/page/2/#findComment-1460565
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
https://forums.phpfreaks.com/topic/284343-inner-join/page/2/#findComment-1460567
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>";
}

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
https://forums.phpfreaks.com/topic/284343-inner-join/page/2/#findComment-1460570
Share on other sites

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.