Jump to content

[SOLVED] pulling variables with same name from joined tables


Recommended Posts

okay iv got 3 tables set up in mySQL ...

 

(fixtures)

id <--- primary key

cat_id <--- foreign key

league_id <--- foreign key

versus

winlose

score

date

report

 

(categories)

id <--- primary key

cat

 

(leagues)

id <--- primary key

league

 

and my php...

 

<table border="1" align="center">
<?php
$titlequery = "SELECT fixtures.*, categories.*, leagues.* FROM fixtures, categories, leagues
WHERE fixtures.cat_id = categories.id AND fixtures.league_id = leagues.id
ORDER BY date ASC";
$titleresult = mysql_query($titlequery);
while($row = mysql_fetch_array($titleresult)){
echo "<tr>";
echo "<td width=\"70\">" . $row['cat'] . "</td>";
echo "<td>" . $row['league'] . "</td>";
echo "<td>" . $row['versus'] . "</td>";
echo "<td>" . $row['win/lose'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td><a href='viewfixture.php?id=" . $row['id'] . "'>Report</a></td>";
echo "</tr>";
      }
    ?>
</table>

 

as you can see I have the results displayed in a table, that's working fine, but where I set up the link to the individual report for each entry.... $row['id'] .... identifies the individual entry, but it is currently taking the "id" from the "categories" table and NOT from the fixtures table which would uniquely identify the entry I am after!

 

is it something to do with the way i have joined the tables? cant think how to sort it out ! Any help is appreciated, thanks

  • 2 weeks later...

bump!

 

duno if i made it clear enough, but to reiterate,

 

this line

 

echo "<td><a href='viewfixture.php?id=" . $row['id'] . "'>Report</a></td>";

 

is taking $row['id'] from the categories table and i need to to be pulling "id" from the fixtures table.

 

Should i be renaming the id field in each table? or is there some way around it like selecting $row['fixtures.id']

 

im stumped and love any suggestions!

 

cheers

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.