Jump to content

[SOLVED] mysql query and display question ...


imarockstar

Recommended Posts

I am trying to join some tables and had a small question ...

 

Here is my code for joining tables :

 

<?php

// Retrieve data from database 
$sql="SELECT * FROM shows INNER JOIN bands ON shows.bandid = bands.id where shows.sid = '$sid' && shows.userid = ". $_SESSION['id'];
$result=mysql_query($sql);


// Start looping rows in mysql database.
$rows = mysql_fetch_array($result);

?>

year: <? echo $rows['year']; ?>

<?php } ?>

 

So what I have above works great. However if I want to display data from both tables, but the field name is the same in both, how could i do that ..

 

example .. both tables have a filed names ID, which is an integer ...  so how could I display the ID from each table ?

 

would it be something like this, which i tried and did not work : 

 

id 1: <? echo $rows['table1.id']; ?>

id 2: <? echo $rows['table2.id']; ?>

 

Does that make since ?

 

on another note ...

 

anyone know where to find the leaked transformers 2 trailer .. I found a crappy version on a russion website .. but it was hard to watch .. lol

 

Link to comment
https://forums.phpfreaks.com/topic/156140-solved-mysql-query-and-display-question/
Share on other sites

where would that go in the query, is there a certain order of how the query should be written ?

 

$sql="SELECT shows.id AS showid, bands.id AS bandid, * FROM shows INNER JOIN bands ON shows.bandid = bands.id where shows.sid = '$sid' && shows.userid = ". $_SESSION['id'];

 

Like that. Use showid and bandid wherever you want to reference IDs. It's self-explanatory which id is which, right?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.