Jump to content

Help needed with sql


controvi

Recommended Posts

Hello Form,

 

This is my first post here so hello to all  :P.

 

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 :P and can help me

let me know.

 

 

Link to comment
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.