Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query using two tables 1

Status
Not open for further replies.

xWastedMindx

Technical User
Sep 3, 2002
67
US
Alright, I have 2 tables. One with my dvdID, dvdName, and dvdPrice. The other table holds my dvdPicture information. (picture path to the disc, alt tag, img width, height, description, etc.)

I have an HTML table with just basic info first. DVD Name and the ID number. When a link is clicked for whichever DVD I click on it brings me to another page where it should display all the stored DB information about the selected DVD.

How do I go about pulling information from two tables and displaying this?
Not necessarily looking for code, just some insight or a place to get started. I've looked around on many different sites and didn't find anything good.

Thanks in advance.
Kenny

"Hey...Where are all the chicks?" -- unknown
 
What u need is to relate ur two tables .
eg. if table1 is like id,dvdID, dvdName, and dvdPrice
and table2 is like dvdid,dvdPicture
With the basic info of the dvd u also fetch the id from table1 and pass it to the script which shows the details of the dvd (eg picture etc)
then u can simply query the database as
Code:
$sql = "select * from table2 where dvdid =". $_GET[id] ;
where $_GET[id] is the value u pass to the script via a link

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
If you want information from both tables to be shown, you have to relate the two tables in some way like spookie said. It looks to me that your best bet would be to have dvdid be your join attribute. That means that you'd have to have dvdid in both tables. From there, just run a query with a join and voila. I haven't done much with MySQL and PHP combined, but I do know SQL. The SQL code would probably go something like this:

select * from table1 join table2 on table1.dvdid=table2.dvdid where dvdid="id from html page" and dvdname="name from html page";

Once again, this is not php, but it should be a good starting point for you.

Mark
 
Well I got most of it working. Now just for the part of actually displaying the images from Table2 along-side the other information pulled from the Table1...

How would I go about doing this?

This is what I have so far.. but I know it's wrong.

Code:
$img = '<img src=&quot;spread.php('.$img_file.') border=&quot;0&quot;>';
return $img;



&quot;Hey...Where are all the chicks?&quot; -- unknown
 
U r storing the image location in ur database , right ?
So for displaying image u can have something like,

Code:
// $imagepath is the value of the location of image ur pulling from database
<img src=&quot;<? echo $imagepath; ?>&quot; width=......>

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Yes.. I have just the file path stored in the DB.. the actual images are on disk. And I got it to work! :) I'm happy!
Thanks you all!

This is my final code... very similar to what Spookie gave an the example.

Code:
<img src='<?php echo(&quot;./image_upload_files/img/$img_file&quot;) ?>' border=&quot;0&quot;>

Again, I want to say thanks! You all helped me out very much. So now because of posting this, and due to a little bit of research in the process, I can now work with pulling images from a DB... and I know how to handle Relational Databases

&quot;Hey...Where are all the chicks?&quot; -- unknown
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top