Jump to content

MySQL query SELECT statement not functioning as expected


Skorpio

Recommended Posts

MySQL server version: 5.1.60-rel13.1

"SELECT `id`, `sub_topic`, `url`, `info`
                    FROM `links

No errors are being thrown.

 

The structure of my database is visible here

 

== Table structure for table links
 
|------
|Column|Type|Null|Default
|------
|//**id**//|int(11)|No|
|topic|varchar(150)|No|
|sub_topic|varchar(150)|No|
|info|text|No|
|url|varchar(255)|No|
== Dumping data for table links

 

Hi, after completing a dropdown tutorial I am trying to convert code for my purpose which is dropdown1 make selection from topics which upon valid selection triggers dropdown2 to be enabled and populate with subtopics then upon selection from dropdown2 (final choice) a textarea will be populated with the relevant information and hyperlink.

 

The issue at the moment is that I am getting all information in sub_topics rather than the ones linked to the main topic selected in dropdown1 which means my statement is incorrect but I cannot work out what I am missing.  I know what I want to do but not sure how to get it/write it.

 

I have been working on this for several hours, my statement started out as 

SELECT * 
				FROM `categories`
				WHERE `master` = ?

from the tutorial to 

SELECT `id`, `topic`, `sub_topic`, `info`, `url` 
				FROM `links`
				WHERE `id` = ? GROUP BY `topic`

Reasoning for the GROUP BY was that I wanted to remove duplicates, for example I have 'web design' as a topic but this is same for over 20 records, I don't want 'web design' in the list 20+ times.

 

I went through a few other statements before I got to 

"SELECT `id`, `topic`, `sub_topic`, `url`, `info`
                    FROM `links

Now this has meant that I am getting data populating the 2nd box and the trigger is enabling the box however now I am getting all the records (everything).

 

I realise I have not got the statement right but cannot work out how to write it.

 

Link to the code being used.  The MySQL db

 

I would appreciate it if someone could advise as to where I have gone wrong and possibly how I correct it so only the correct options show in the 2nd box.  Thanks

Link to comment
Share on other sites

I now have the 2nd box functioning as expected however the third, a textarea is a whole other matter.  If someone could steer me in the right direction I would appreciate it?  Thanks

 

The previous links to the code hold the updated code.

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.