Using Variable in MySQL query

nitapita

Hi everone.

Having a problem with getting the values from a database.

What im trying to do is:
I use variable 'varname' from packaging_items table (values are coressponding to the names of columns in packaging table ... pack01, pack02 .. and so on).
But in query result1 instead of getting the value of (pack01, pack02 ..) i get the names of columns (pack01, pack02 ..)
Here is my short code: (ofcourse there is more to it, but this bit is most important)

simplypixie

Try echoing out your $result1 query (you will need to remove the mysql_query wrapper first) and then run what is return directly in PHPMyAdmin to see what happens (easier to debug sometimes).

nitapita

well i did ...

pack01pack02pack03pack04pack05pack06pack07 just like i mentioned before, these are names of columns in packaging table, and frome these i want to get the values out..
need to have another variable specified for that ...and i jus do not now how to do this ..

nitapita

well i did ...

pack01pack02pack03pack04pack05pack06pack07 just like i mentioned before, these are names of columns in packaging table, and from these i want to get the values out..
need to have another variable specified for that ...and i just do not now how to do this ..

simplypixie

So when you ran your query in phpmyadmin you got no errors and then just a list of column names? Are you absolutely sure these are column names?

nitapita

that is for sure, values coming from the varname variable in packaging_items table , are the names exactlly the same as columns names in packaging table, so now all i have to do is to specify variable getting the value of selected column, do not know how to do that .. tried many options, some of them not logical too ..

simplypixie

Can you provide the structure of your packaging table as the problem you are having makes no sense at all.

nitapita

for example when i hardcode the query, results are ok and that is what i want to achive here

simplypixie

Yes, I understand what you want to achieve but I can't work out why it isn't working for you. Are you now saying that when you hard code the query (as above) or run directly in phpmyadmin it works as expected, it is just when you run it within the other while loop that it doesn't work?

nitapita

packaging _items table:

id
name
cat
varname - each record (ther is 14 of then at the moment ) haas name pack01, pack 02 ...so on
info
price
photo