Another DropList problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

Another DropList problem

Post by galligraph »

I need the following information from the database(2 tables, question and category). Other table includes CategoryId and CategoryText.

Code: Select all

$query = ("select Id, Answer, Type, QuestionText, Points, CategoryText FROM question, category where question.CategoryId=category.CategoryId and question.Id='$question'");
Id value comes from the list. So I'm tryin 2 get 1 particular questions information so u can change the information if needed. I'm using droplist and I need 2 get questions CategoryText 2 the Droplist. It should show the feeded CategoryText first but u can change it if needed. So how 2 get those values 2 the droplist. Now I get only the feeded CategoryText there, nothin' else. So it should show the feeded first but there should be other Categories also...

Code: Select all

while ($row = mysql_fetch_array($query)){

	echo "<option value='".$row['CategoryId']."'>".$row['CategoryText'];}"</option> ";
         "</select>"; "<td> </tr>";
If somebody understand what i'm tryin' 2 say and could help me I'll appreciate it. :)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

first off, PLEASE use the word "to" instead of "2", its only 1 more key you have to press.

second, i think your problem is in your query. use LEFT JOIN (search it on google) and you will be able to do it properly if your 2nd table has the id of the first to where you need to link it to. it will be somthing like

Code: Select all

SELECT
  Id, Answer, Type, QuestionText, Points, CategoryText
FROM
  question
LEFT JOIN
  category ON question.CategoryId = category.CategoryId
WHERE
  question.Id='$question'
this is not gaurenteed to work but it might steer you in the right direction.
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

Post by galligraph »

Thx for the reply but it did't help me this time. I think my query is exactly the same as yours just made differently(brings same value). Do I need more than one query or is it possible to make this with one? Maybe need some other changes also.. Don't know. :wink:
galligraph
Forum Newbie
Posts: 11
Joined: Wed Dec 21, 2005 10:26 am

Post by galligraph »

Hello ya'll! I know ur much more into this subject than I'm so hopefully somebody could help my ass out... I just dont know how to fix this one... damn.. If u got any suggestions I'll apprecieate... Pz! :wink:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post your table structure from a phpMyAdmin structure dump, then post what value you want as the option id and what value you want for the option text.
Post Reply