Jump to content

Archived

This topic is now archived and is closed to further replies.

Codeman0013

taking the url and putting it into query

Recommended Posts

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?

Share this post


Link to post
Share on other sites
so if you have a url like: http://mything.com/script.php?industry=232  ??

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

Share this post


Link to post
Share on other sites
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 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";
}
?>
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites

×

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.