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 Link to comment https://forums.phpfreaks.com/topic/93762-need-help-with-a-query/ 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); Link to comment https://forums.phpfreaks.com/topic/93762-need-help-with-a-query/#findComment-480445 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. Link to comment https://forums.phpfreaks.com/topic/93762-need-help-with-a-query/#findComment-480447 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 Link to comment https://forums.phpfreaks.com/topic/93762-need-help-with-a-query/#findComment-480451 Share on other sites More sharing options...
jbrill Posted February 29, 2008 Author Share Posted February 29, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/93762-need-help-with-a-query/#findComment-480470 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 />"; } Link to comment https://forums.phpfreaks.com/topic/93762-need-help-with-a-query/#findComment-480495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.