shotza Posted January 20, 2007 Share Posted January 20, 2007 Hi folksI'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, trackWHERE '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! Link to comment https://forums.phpfreaks.com/topic/34988-extracting-data-from-two-tables-using-_get/ Share on other sites More sharing options...
kenrbnsn Posted January 20, 2007 Share Posted January 20, 2007 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 Link to comment https://forums.phpfreaks.com/topic/34988-extracting-data-from-two-tables-using-_get/#findComment-164999 Share on other sites More sharing options...
shotza Posted January 20, 2007 Author Share Posted January 20, 2007 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 Link to comment https://forums.phpfreaks.com/topic/34988-extracting-data-from-two-tables-using-_get/#findComment-165001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.