Jump to content


Photo

taking the url and putting it into query


  • Please log in to reply
3 replies to this topic

#1 Codeman0013

Codeman0013
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationCentral Illinois USA

Posted 20 September 2006 - 07:36 PM

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?
Remember to always look for those dang ; they can be a killer!

#2 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 20 September 2006 - 08:19 PM

so if you have a url like: http://mything.com/s...p?industry=232  ??

Then you can use $_GET[]
<?php
if(isset($_GET['industry'])) {
  $industry_id = $_GET['industry'];
}
?>


#3 Codeman0013

Codeman0013
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationCentral Illinois USA

Posted 20 September 2006 - 09:08 PM

where does that go at?
Remember to always look for those dang ; they can be a killer!

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 10:30 PM

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:

<?php
// get parameters from the URL into the page and sanitise
if (!empty($_GET['industry'])){
   $ind_id = strip_tags(add_slashes($_GET['industry']));
}

// call the file that has my DB connect code in it
include('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 ok
if (!$result){
   die ('There was an error executing the SQL: ' . mysql_error());
}

// Do something with the results
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   echo "$row['columnname']<br>\n";
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users