Jump to content


Photo

umm fetch rows from multiple tables


  • Please log in to reply
4 replies to this topic

#1 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 16 July 2006 - 04:25 PM

umm what i want to do is fetch rows from multiple tables in 1 qury i want to this because im making a Forum..
well this is what i have
<table width='100%' border='0' class='border'>
<tr>
<td width='20%' class='nav'>Poster</td>
<td width='60%' class='nav'>Post</td>
<td width='20%' class='nav'>Options</td>
</tr></table>
<table width='100%' border='0' class='border'>
<?php
$link = mysql_connect('localhost', '1135394704283249', '0309192909121845');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tpf');
if (!$db_selected) {
   die('Could not select database: ' . mysql_error());
}
$query = "SELECT author,post,id FROM post where thread_id = '$thread_id' ORDER BY id ASC limit $start,15";

	 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){$count++;
echo "<tr><td width='20%' class='nav2' height='130'>". $row['author'] ."</td><td width='60%' class='nav2'>". $row['post'] ."</td><td width='20%' class='nav2'><a href='index.php?action=editpost&post_id=". $row['id'] ."'>Edit</a><br><a href='index.php?action=deletepost&post_id=". $row['id'] ."'>Delete</a></td>";
}
?>
</table>

well what that does is just get the Post,Author and displays it in a table.What i need it to do is use that author and get other information of the author from other tables like his Id# and maybe Email address etc.. amd display it under the author.
is this possiable if so can som1 help me im not so good with mysql..And btw.. i need it do that for all the authors/posts so yeah..Need some help with that

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 July 2006 - 04:34 PM

You need a 'join' (to join the tables for a single query).

It's less complicated than it sounds. http://htmlite.com/mysql012.php has simple examples that should get you on your way.
Legend has it that reading the manual never killed anyone.
My site

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 16 July 2006 - 05:33 PM

Agreed.. it's impossible to us to suggest a join with the relevant table definitions.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 17 July 2006 - 03:35 PM

Agreed.. it's impossible to us to suggest a join with the relevant table definitions.


umm i cant get it right

what right now it just gets the posts from the post table.
example
<table border='1' width='500'>
<tr>
<td>Author</td>
<td>Post</td>
<td>Id</td>
</tr>
<tr>
<td>Desithugg</td>
<td>Hello..Welcome to the Forums<br>enjoy your stay</td>
<td>1</td>
</tr>
<tr>
<td>Dusty</td>
<td>O hello.Ty for the welcome. :)</td>
<td>2</td>
</tr>
</table>
and displayes it but i also want it to use the author and get the row "Signtaure" from the "signup" table.and display it also and i want it to do it for each post

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 17 July 2006 - 06:11 PM

I understand, but I still need to the see the relevant tables first.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users