Jump to content


Photo

Getting data from more than one table


  • Please log in to reply
2 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 15 March 2006 - 01:20 PM

Hi,
I am having a few problems with getting the data i want from my tables. I have used the code below which works fine:

$sql_ord = "SELECT s.* FROM stock s
INNER JOIN order_item i
on s.stockID = i.stockID
WHERE i.orderiD = '$orderID'";


However when i change the bit highlighted in bold to:

SELECT s.* FROM stock s and i.* FROM order_item i, i.* FROM stock

It comes up with an error. I am using an array to ouput the data i need from the tables but as i need to get data from both tables so i can output the data from both tables, what do i do? I am sure there must be a command to select the data from 2 tables??
Thanks.

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 15 March 2006 - 01:34 PM

What are your table names? basicaly looks like u need

SELECT * FROM table1, table2 WHERE table1.ID = table2.id


If that helps you in how you select * from both tables?

I'm a bit confused with your code tho so not sure if thats going to help properly
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 15 March 2006 - 01:53 PM

try the following:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM stock s
INNER JOIN order_item i
on s.stockID = i.stockID
WHERE i.orderiD = '$orderID'
[!--sql2--][/div][!--sql3--]

this will select all from both tables
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users