Bobd3142 Posted June 26, 2009 Share Posted June 26, 2009 As of right now I have two MySQL tables.... one with manufacturers and then one with items. They're called "Manuers" and "Items." Items has a field called "manu" with a number corresponding to the ID in "Manu." My goal is to have a file (file.php for example) that will get the items with a given ID (file.php?id=10) and then display only those results. Right now with the following code.. it displays everything, since I can't get anything with $_GET to work at all.. <?php mysql_connect("website","username","password"); mysql_select_db("database"); $result = mysql_query("SELECT Manuers.*, Items.* FROM Manuers, Items WHERE Manuers.id = Items.Manu"); while($r=mysql_fetch_array($result)) { $Name = $r["Name"]; $Picture = $r["Picture"]; echo "$Name - $Picture"; echo "<br />"; } ?> Also, how would I go about making $r only get data from the Items table and not Manuers? It works like that right now but I'm not quite sure why. Thanks for all the help Link to comment https://forums.phpfreaks.com/topic/163721-multiple-table-query-and-_get/ Share on other sites More sharing options...
xtopolis Posted June 26, 2009 Share Posted June 26, 2009 So this code makes some assumptions: +The tables are properly setup (id and manu are of same type) +name is the first column, and picture is the second column returned in the result set +I didn't make any errors (i remembered how to use list() = mysql_.. correctly) <?php $id = ( isset($_GET['id']) ) ? intval($_GET['id']) : 1; mysql_connect("website","username","password"); mysql_select_db("database"); $query = "SELECT m.*, i.* FROM Manuers m JOIN Items i ON(m.id = i.manu) WHERE m.id = $id"; $result = mysql_query($query); while( list($name,$pic) = mysql_fetch_array($result) ) { echo "$name - $picture"; echo "<br />"; } ?> If no id is sent to the page, it will default to 1. Try it, and if it works, we can refine it from there. Link to comment https://forums.phpfreaks.com/topic/163721-multiple-table-query-and-_get/#findComment-863878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.