select from sql table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
merican
Forum Newbie
Posts: 22
Joined: Tue May 18, 2004 8:56 pm

select from sql table

Post by merican »

hi all,
I need to know how to select data from 2 different table in sql. below is the code i use to select data from 1 table:-

$ffdb->DivideData("SELECT * FROM ffdb_files ORDER BY file_name",$page,$CONFIG['files_per_page']);
$ffdb->MakePages("<a href=\"admin.php?page={eachpage}&action=edit_file\">{eachpage}</a> ","<b>({page})</b> ","<a href=\"admin.php?page=1&action=edit_file\">« First Page</a> ","<a href=\"admin.php?page={eachpage}&action=edit_file\">Last Page »</a>",$page,$ffdb->num_pages);
$tpl->LoadTemplate("file_list","Admin/templates/$admin_skin/file_list.tpl");
$mysql->Query("SELECT * FROM ffdb_files ORDER BY file_name LIMIT $ffdb->data_bottom,$ffdb->data_top");
while ($show_file=mysql_fetch_array($mysql->result_id)) {
$has_files=1;
$file_list_array = array(
'file_filename'=> $show_file[file_filename],
'category'=> $show_file[category],
'file_description'=> $show_file[file_description],
'author'=> $show_file[username],
'author_email'=> $show_file[author_email],
'version'=> $show_file[version],
'file_id'=>$show_file[file_id]
);


let say i want to selet username from the filedb_users table. can anyone help me? thank you in advance.

Regards,
Alfy Merican
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Post your SQL table (in code tags please, so it's easier to read).

Is the data you want to retrieve from the two tables related in any way?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Code: Select all

SELECT table.field, table2.field2, FROM table, table2 WHERE table.ID = blah AND table2.ID = 'this'
You just have to refer to each field using the table name before it.
merican
Forum Newbie
Posts: 22
Joined: Tue May 18, 2004 8:56 pm

Post by merican »

hi guyss..
thank you for your knowledge. It works man...now i can see data from 2 different table...thanks....really appreciate that!!!

best regards,
Alfy
Post Reply