jbrill Posted February 29, 2008 Share Posted February 29, 2008 hey guys, been a while since i posted a question on here. I need help with an SQL statement im working with. I need to select information fro two different tables. for example, i have one table models and and another table type the models table has the fields: 'id' & 'modelname' & 'typeid' the type table has the fields: 'id' & 'typename' I need to be able to display the following: 'modelname' - 'typename' hope this is enough information to help me out Quote Link to comment Share on other sites More sharing options...
revraz Posted February 29, 2008 Share Posted February 29, 2008 SELECT models.modelname, type.typename FROM `models` JOIN `type` ON (models.typeid = type.id); Quote Link to comment Share on other sites More sharing options...
hawkenterprises Posted February 29, 2008 Share Posted February 29, 2008 There is still the question of what ID works with what but you can try this SELECT models.modelname,type.typename FROM models,type WHERE models.typeid=type.id I think the other post will work as well I just haven't used that format of a join. Quote Link to comment Share on other sites More sharing options...
jbrill Posted February 29, 2008 Author Share Posted February 29, 2008 how would i display it to look like this modelname = typename Quote Link to comment Share on other sites More sharing options...
jbrill Posted February 29, 2008 Author Share Posted February 29, 2008 anyone? Quote Link to comment Share on other sites More sharing options...
revraz Posted February 29, 2008 Share Posted February 29, 2008 $sql = "SELECT models.modelname, type.typename FROM `models` JOIN `type` ON (models.typeid = type.id)"; $result = mysql_query($sql) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { echo $row[0]. "=" .$row[1]. "<br />"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.