Page 1 of 1
passing a variable, better than my links
Posted: Tue Mar 23, 2004 6:12 am
by andycruickshank
I am hoping to make a site which uses a frameset with a constant header section, and a menu system on the left.
Currently the menu has a list of Continents, and when you click a name, a list of the countries in that continent appears. At this moment, each is a link, which links to a page for the country. This means i will need 206 pages!
Is there a way of passing the country name (which is in a table, along with it's id, which is how the menu is created, using continent and country database tables) to a single page which i can use to select the needed info, cutting my page list by 205!
Thanks very much, hope that made sense!
Andy
Posted: Tue Mar 23, 2004 6:32 am
by patrikG
1) don't use frames.
2) $_SESSION is your friend
sessions to preserve values across pages.
3) don't use frames.
4) use tables instead of frames.
Posted: Tue Mar 23, 2004 6:38 am
by CoderGoblin
As I understand your question...
Your menu (left) frame could include....
Code: Select all
<a href="getcountry.php?id=1" target="right">England</a>
<a href="getcountry.php?id=2" target="right">Germany</a>
<a href="getcountry.php?id=3" target="right">France</a>
<a href="getcountry.php?id=4" target="right">Spain</a>
When the user clicks on the link he passes a GET request to the right frame.
In the right frame (getcountry.php) you could use...
Code: Select all
<?php
if (isset($_GET['id'])) {
$country_id=floor($_GET['id']);
// Get information from DB based on $country_id value
// Output information gathered.
}
?>
I have floored the id to prevent SQL injections (any text will be set as id=0) as you know the id will be an integer (Potential Security issue otherwise).
Hope this gives you a starting point
Posted: Tue Mar 23, 2004 10:06 am
by andycruickshank
Thanks for the advice patrikG, normally i'd probably take it, but i know mainly what i'm doin with frames, and have always used them, sorry! Personal preference!
CoderGoblin, thanks you ever so much,

that's exactly what I was lookin for! I've had a fiddle with the code, and it's all good! The security thing is a good idea, but i'll have to look at that later, coz my ID's as it stands are things like count1, count2, as I have more tables with more id everywhere, this way i make sure my tiny little mind doesn't frazzle remembering which ID it is...!
I might look at it come time, but it's part of a uni thing i'm tryin to do, and time is a bit tight! would be ok if i knew php and was quick at coding!

Posted: Tue Mar 23, 2004 6:27 pm
by andycruickshank
Code: Select all
if (isset($_GETї'id'])) {
$country_id=$_GETї'id'];
// Get information from DB based on $country_id value
// Output information gathered.
echo $country_id;
$sql = 'SELECT country, countryID FROM countries WHERE countryID="$country_id"';
$r2 = mysql_query($sql) or die(mysql_error()) ;
while($row2 = mysql_fetch_object($r2))
{
echo $row2->country;
echo $country_id;
}
This is my code having brought in the variable, and it is stored in $country_id as it is echo'd in the first instance.
What combination of " and ' do i need to use to make the select statement work ( WHERE countryID="$country_id"';) as i haven't a clue! Tried heaps using other code which is similar, but not the same, so ain't sure.
The second echo works if i just say WHERE countryID = "count60"; both echos work showing the ID selected in the menu, and Cambodia is shown, so it's just the WHERE doesn't work
Sorry for bein a pest...

Posted: Tue Mar 23, 2004 6:34 pm
by markl999
$sql = "SELECT country, countryID FROM countries WHERE countryID='$country_id'";