Codeman0013 Posted September 20, 2006 Share Posted September 20, 2006 Hey guys this might be just a noob question but in my sql query for the database how do i set it to say like where industry = and then the id number from the url for its query? Quote Link to comment https://forums.phpfreaks.com/topic/21453-taking-the-url-and-putting-it-into-query/ Share on other sites More sharing options...
SharkBait Posted September 20, 2006 Share Posted September 20, 2006 so if you have a url like: http://mything.com/script.php?industry=232 ??Then you can use $_GET[][code]<?phpif(isset($_GET['industry'])) { $industry_id = $_GET['industry'];}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21453-taking-the-url-and-putting-it-into-query/#findComment-95654 Share on other sites More sharing options...
Codeman0013 Posted September 20, 2006 Author Share Posted September 20, 2006 where does that go at? Quote Link to comment https://forums.phpfreaks.com/topic/21453-taking-the-url-and-putting-it-into-query/#findComment-95678 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 I tend to put that sort of information at the top of my page after the headers.Defines the variables for the rest of the page that way.So you'd have it look like this:[code]<?php// get parameters from the URL into the page and sanitiseif (!empty($_GET['industry'])){ $ind_id = strip_tags(add_slashes($_GET['industry']));}// call the file that has my DB connect code in itinclude('connect.php');// setup the SQL statement with the variable from the url$sql = "SELECT * FROM tablename WHERE industry = $ind_id";// execute the statement$result = mysql_query($sql);// Check it executed okif (!$result){ die ('There was an error executing the SQL: ' . mysql_error());}// Do something with the resultswhile ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "$row['columnname']<br>\n";}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21453-taking-the-url-and-putting-it-into-query/#findComment-95720 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.