Jump to content

Need help with a query


jbrill

Recommended Posts

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

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.

$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 />";
}

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.