Thread: Sql statement
Results 1 to 2 of 2
Related
-
How to write if statement in MySQL Forum: PHP Forum
Replies: 2 -
Syntax for Select Statement Forum: Databases
Replies: 2 -
If statement inside <td> Forum: CGI Perl Forum
Replies: 1 -
Select Case SQL Statement... Forum: Databases
Replies: 7 -
MySQL Select statement Forum: Databases
Replies: 1
-
08-15-2007, 12:18 AM #1
Sql statement
hello...
I want to ask about how to use sql statement when I have 2 tables and I want to display information from both table by using their ID.
Here I have 2 tables.
Table 1 is journal:
This table have journal_ID and authorID
Table 2 is author:
This table have authorID and author_name
So, I want to display info from table journal and get the author name from table author.But I can't display the author name.
Here are my coding:
Code:$result = mysql_query("SELECT * FROM journal HAVING description LIKE '%".$keyword."%' OR description LIKE '%".$keyword."%'"); if (!$result || mysql_num_rows($result) < 1) { $href = "user_browse_1.php"; print"<meta HTTP-EQUIV='REFRESH' CONTENT='1; URL=".$href."'><div class='sub_title'>item not found...</div><br><br><br>"; }
Code:$result2 = mysql_query("SELECT name FROM author WHERE authorID=$item_Author"); while($row2 = mysql_fetch_array($result2)) { $authorname=$row2["authorID"]; }
Last edited by vinyl-junkie; 08-15-2007 at 07:21 AM. Reason: Added code tags
-
08-15-2007, 07:24 AM #2
Re: Sql statement
You only need one query to get what you want, by using an inner join like so:
Code:$result = mysql_query("SELECT * FROM journal HAVING description LIKE '%".$keyword."%' OR description LIKE '%".$keyword."%' INNER JOIN journal on journal.AuthorID = author.AuthorID");
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum