Jump to content

Extracting data from two tables using $_GET


shotza

Recommended Posts

Hi folks

I'm hoping someone can help me out here.  I'm trying to extract data from two tables using information passed via the url.
My code is as follows:

$track = $_GET[id];

$result = mysql_query ("SELECT rider.ridername, rider.bike, rider.favtrack, track.length
FROM rider, track
WHERE 'rider.$track'='track.$track'", $handle);

Now as you can probably deduce from this I'm very new to coding so any help would be very much appreciated.  I've been sitting here desperately trying all kinds of formats with the quotations, trying to place $_GET into the sql statement etc and to be honest I'm really not sure what I'm doing :)

Thanks in advance!
Are you getting any errors? What does the rest of the script look like? If you code you script like this:
[code]<?php
$q = "SELECT rider.ridername, rider.bike, rider.favtrack, track.length FROM rider, track WHERE 'rider.$track'='track.$track'";
$rs = mysql_query($q) or die("Problem with the query:<pre>$q</pre><br>" . mysql_error());
?>[/code]
is anything displayed?

Ken
I dont get any errors just no output.  The rest of the relevant code looks like this:

[code]#Generate table and rider info
$track = $_GET[id];
echo "<h1>$track</h1>";
$result = mysql_query ("SELECT rider.ridername, rider.bike, rider.favtrack,
track.length FROM rider, track
WHERE 'rider.$track'='track.$track'", $handle);
echo "<table border ='1'>";
echo "<tr>" . "<td>" . "<b>Rider</b>" . "</td>";
echo "<td>" . "<b>Bike</b>" . "</td>";
echo "<td>" . "<b>Track</b>" . "</td>";
echo "<td>" . "<b>Track Length</b>" . "</td>";


while ($record = mysql_fetch_row($result))
{#while
echo "<tr>";

for($i=0; $i<mysql_num_fields($result); $i++){#for

#remove id number from output
if ($i == 0){
$i = $i;
}

else {#else

echo "<td>" . $record[$i] . "</td>" . "  ";

}#end else

}#end for


echo "</tr>";

}#end while

echo "</table>";[/code]

The main body of this code I'm pretty sure works ok, I've used it in previous pages.  I think the problem is with my dodgy sql statement and trying to work the $_GET information in

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.