passing a variable, better than my links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andycruickshank
Forum Newbie
Posts: 10
Joined: Tue Mar 23, 2004 6:12 am
Location: Aberdeen

passing a variable, better than my links

Post 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! 8O
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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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
andycruickshank
Forum Newbie
Posts: 10
Joined: Tue Mar 23, 2004 6:12 am
Location: Aberdeen

Post 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, :D 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! :lol:
andycruickshank
Forum Newbie
Posts: 10
Joined: Tue Mar 23, 2004 6:12 am
Location: Aberdeen

Post by andycruickshank »

Code: Select all

if (isset($_GET&#1111;'id'])) &#123; 
   $country_id=$_GET&#1111;'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)) 
      &#123;
	  echo $row2->country;
	  echo $country_id; 
      &#125;
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... :oops:
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$sql = "SELECT country, countryID FROM countries WHERE countryID='$country_id'";
Post Reply