Pages: [1]   Go Down
Author Topic: LEFT JOIN data listing  (Read 101 times)
Goldie_
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 2


« on: April 14, 2010, 07:08:10 AM »

I have 2 mysql tables
table "content" with rows "id" and "title"
and table "files" with rows "filename" and "content"

I wanted the PHP to create a list of titles from the "content" table, and that, under each title, list of filenames from table "files", if their "content" is the same number from the id number of a "title".
Like this:

title1
- filename1
- filename2
- filename3
title2
- filename4
- filename5

I used LEFT JOIN and this function

Code:
$arr_results = array();

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    $arr_results[$row['title']][]=$row['filename'];
stringovi koji ce predstavljati filename-ove
}

foreach($arr_results as $title=>$filenames)
{
    echo $title.'<br>';
   
    foreach($filenames as $filename)
    {
        echo '-'.$filename.'<br>';
    }   
}

recently I added "date" row into "files" table and now I need result like this
title1
- filename1 - date1
- filename2 - date2
- filename3 - date3
title2
- filename4 - date4
- filename5 - date5

Can somebody help me? Where and how should I insert "date" row into this function to get all work properly?
Report to moderator   Logged

Pages: [1]   Go Up
Print
 
Jump to:  

Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC | Theme Kani By Fussilet

Page created in 0.04 seconds with 21 queries.