john_duncan Posted February 24, 2011 Share Posted February 24, 2011 Hello guys, hope you can help me with this one. My PHP is limited but I am learning. I have a slight conundrum to solve. Take a look at the following code... It is a dropdown box that lists a number of categories attained from the "industry" table. These are "construction, building, surveying" etc.. Every industry is give and ID number from 1 to 5. This code, lists the names of the industries and then finds the corresponding ID and uses this to append "trade_"(ID) which corresponds to an HTML page for that industry. This populates the dropdown box with the industry names. When clicked on, it returns the ID number of the industry and inserts this into the address bar link. OK, what I would like to do is take this ID number and use it to for a query on our "products" table and look for all the products that contain this number in the "industries" column within that table, and display.. (instead of the "trade_"(id) as below) all the products that contain that number (i.e. industry). Something like index.php?page=results&industries=1. so for example. The rotating laser is in industries "1,2,3". Lets say 1 is construction. So I would like to display all products in the products table that have a 1 in the industries column. How would I append the code to include a separate query using the ID number from this? Something like $query="select this.value from products"; or similar. <select name="industries" class="dropDown2" id="industries" onChange="javascript:document.location='index.php?page=trade_'+this.value"> <option selected>Trade...</option> <? $query = "select * from industries" ; $result=mysql_query($query); while($record = mysql_fetch_array($result)){ if($record["status"] == "true"){ echo "\n<option value='".$record["id"]."'> ".$record["industry"]."</option>"; } } $query = "select * from industries" ; $result=mysql_query($query); ?> </select> Hope I've made sense! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/228698-need-help-with-a-query-thanks/ Share on other sites More sharing options...
cs.punk Posted February 24, 2011 Share Posted February 24, 2011 You need to use the WHERE in your query. $query = "SELECT * FROM industries WHERE industryID = '1'"; Quote Link to comment https://forums.phpfreaks.com/topic/228698-need-help-with-a-query-thanks/#findComment-1179078 Share on other sites More sharing options...
Skylight_lady Posted February 24, 2011 Share Posted February 24, 2011 Don't forget to also change: onchange="javascript:document.location='index.php?page=trade_'+this.value'&industries=1" Change the 1 to the php variable if it is a different value. Quote Link to comment https://forums.phpfreaks.com/topic/228698-need-help-with-a-query-thanks/#findComment-1179087 Share on other sites More sharing options...
john_duncan Posted February 25, 2011 Author Share Posted February 25, 2011 Thanks for the replies! Still can't get it to do what I want, but that is mainly my lack of understanding not your responses. I'll have another look at it as soon as I can... thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/228698-need-help-with-a-query-thanks/#findComment-1179454 Share on other sites More sharing options...
Muddy_Funster Posted February 25, 2011 Share Posted February 25, 2011 First up, lets tidy up some of your code: $query = "SELECT id, industry FROM industries WHERE industry.status = 'true'" ; $result=mysql_query($query) or die ('Fatal Error retrieving Industry list : '.mysql_error()); while($record = mysql_fetch_array($result)){ echo "\n<option value='".$record["id"]."'> ".$record["industry"]."</option> } The following will get your result set that you want, I never use javascript, so can't advise you how to call this, but it does what you want your looking for. $query2 = "SELECT id, name FROM products WHERE products.industries = ".$_GET['page'] ; $result2 = mysql_query($query2) or die ('Fatal Error retreving industry product list : '.mysql_error()); while($record2 = mysql_fetch_assoc($result2){ //your list code here } Quote Link to comment https://forums.phpfreaks.com/topic/228698-need-help-with-a-query-thanks/#findComment-1179461 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.