Jump to content

[SOLVED] 2 Files, URL and Variable problem!


erme

Recommended Posts

Thought this was best suited as a new topic rather then a string of multiple questions in a topic that the title wasn't now true to.

 

I have 2 files, index.php and locations.php.

 

In index.php I have

$extrapart = (isset($_GET['county'][0]))?"WHERE County='".mysql_real_escape_string($_GET['county'])."'":"";

 

and in locations.php

$query = "SELECT * FROM locations $extrapart";
$result = mysql_query($query);

 

In order for what I am wanting, I have my URL like this

/index.php?county=devon

 

however because this is being called in index.php, I can't use $extrapart in locations.php. Is there a way locations.php can read this?

Link to comment
Share on other sites

ofcourse,

it should be:

$query = "SELECT * FROM locations $_SESSION['extrapart']";

 

and if that doesn't work:

$extrapart = $_SESSION['extrapart'];
$query = "SELECT * FROM locations $extrapart";

 

BTW don't forget to include as first line above the html in your php:

session_start();

 

And I think something is wrong with your query:

SELECT * FROM locations $extrapart

what should the variable extrapart contain?

Link to comment
Share on other sites

in index.php

$extrapart = (isset($_GET['county'][0]))?"WHERE County='".mysql_real_escape_string($_GET['county'])."'":"";

$_SESSION['extra'] = $extrapart;//or just set the session var to the above

 

then in your locations page either use the session var or set the variable to the session var's value.

 

also, I don't know if you want to select everything from your database if the county isn't set, but currently your script will only select entries of a certain county if it's set, and everything from the table if the county isn't set. you may want to change this if this isn't desired

 

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.