controvi Posted April 13, 2011 Share Posted April 13, 2011 Hello Form, This is my first post here so hello to all . Ok now for my question. i am making an CMS system for a school project. we have decided to work with smarty. Now this question is about 2 tables. table 1: attributes it contains the collums 'att_Id, att_Lable and att_Name' table 2: pg_Data(page data) this contains the collums 'dat_Id, att_Id, dat_Lable and dat_Name' This table contains the values for the attributes from table 1. in short: |table 1 |------------------------------------------------| | att_Id | att_Lable | att_Name | |------------------------------------------------| | 1 | head | Head | |table 2 |------------------------------------------------------------| | dat_Id | att_Id | dat_Value | |------------------------------------------------------------| | 1 | 1 | This is a text | now i need a query that need a query that get out de att_label from table 1 en the value from table 2. SELECT dat.dat_Value, att.att_Lable FROM pg_Attributes AS att LEFT JOIN pg_Data AS dat ON att.att_Id = dat.att_Id then i get an output in php array( [dat_Value] => this is a text [att_Lable] => head ) now this is all good but i want to get the lable of the attribute in de key of the value. So it would look like this. array( [head] => this is a text ) is there anyone how understands this and can help me let me know. Link to comment https://forums.phpfreaks.com/topic/233578-help-needed-with-sql/ Share on other sites More sharing options...
ignace Posted April 13, 2011 Share Posted April 13, 2011 $sql = "SELECT att.att_Lable, dat.dat_Value FROM pg_Attributes AS att LEFT JOIN pg_Data AS dat USING(att_Id)"; $res = mysql_query($sql); if($res && mysql_num_rows($res)) { while(list($label, $value) = mysql_fetch_row($res)) { $labels[$label] = $value; // $labels['head'] = 'this is a text'; } } Link to comment https://forums.phpfreaks.com/topic/233578-help-needed-with-sql/#findComment-1201012 Share on other sites More sharing options...
controvi Posted April 13, 2011 Author Share Posted April 13, 2011 THANKS YOUR MY HERO 2 weeks of searching coming to an end. :D :D Link to comment https://forums.phpfreaks.com/topic/233578-help-needed-with-sql/#findComment-1201028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.