View Full Version : passing a value to another page???

05-07-2009, 05:25 PM
Hi All,

Ok im gonna try and describ this the best i can :D

i have several feeds of which the first 3 items are inserted into my db i then use php to pull out the specific items and place them in the correct divs which is fine

i then have and image inderneath the item header with the alt and title tag set to the title of the item in the database. (still following?)

i have also set the image to link to another php page results.php which it does

here is the problem...
i am unable to pass the item title to the other php page, can i use the image title as a varible?

is it possible

my php code is


$category_list = array("DVD", "CD", "Video Games", "Blu-Ray", "Books");
$subcategory_list = array("Bestsellers","New Releases","Gifted");

$cat_count = 0;

foreach ($category_list as $category){

print "<div class='catsections'>
<div class='catheader'>

<div class='category_name'>


<div class='cattop'>

<div class='cattop_header'>
Kernow Connect Pick Of The Week

<div class='cattop_item'></div>
<div class='cattop_desc'></div>

$sub_count = 0;

foreach($subcategory_list as $subcategory){

print "<div class='top3'>

<div class='subcat_header'>

$itemdata = "SELECT *
FROM category_data
WHERE page_category = 'Entertainment'
AND cat_id = '$category_list[$cat_count]'
AND subcat_id = '$subcategory_list[$sub_count]'";

$num_rows = mysql_num_rows($item_query);

if ($num_rows == 0){
echo "No Results Please Go Back And Try Again";
else {
while ($row = mysql_fetch_array($item_query)){
$short_title = preg_replace("/#\d: |\s*\(.*\)|\s*\[.*\]/U", "", $row['title']);
print '<div class="item">

<div class="itemIMG">
<img src="'.$row['image'].'"
height="100" />

<div class="itemTitle">'.$short_title.'</div>
<div class="itemButton">
<a href="http://www.kernow-connect.com/results.php">
<img src="images/compare.gif"
title="'.$short_title.'" border="0" /></a>

$sub_count ++;
print "</div>";

$cat_count ++;


any help would be greatly appreciated :)
thanks for your time

05-07-2009, 05:34 PM
Change your link like

<a href="http://www.kernow-connect.com/results.php?title='.$short_title.'">
<img src="images/compare.gif"
title="'.$short_title.'" border="0" /></a> and then use $_GET['title'] in your results.php page.

05-07-2009, 05:46 PM

OMG Thank You!!!!!

I didn't think that would work because i was unsure how it would know what $short_title should be, but looking back at my code its obvious it would work as the loop would insert each item at a time with the correct link info attached to that item.... wow i thought this was going to take ages lol

so the same would work with sessions then???

thank you!!!!!!!!!!!!!!!!!!!!!!

05-07-2009, 05:57 PM
so the same would work with sessions then???
Not in this case. Since you are generating a lot of links by your loop, it's not so easy to store and retrieve using sessions. If you are really worried about passing the entire title in the url, you may just send the table id (of that row) in the url and then query again in the next page to get that particular title from the table.

05-07-2009, 06:16 PM
mmm ok, im not worried about passing the entire varible in the url it just looks a bit messy if i have a long title thats all.

i think i'll leave it as it is then :)

thank you

05-07-2009, 09:04 PM
I suggest you use htmlentities on your $_GET to prevent XSS injection.

This way if a user tried to enter html into the title= part it would convert it to entities rather than html.

05-08-2009, 11:46 PM
hi mate, i have used as you have suggested as above which is fine but further along in the script i call the varible as so

<div class="searchbar">
<input name="searchbox"
value="<?php print $inputtext ?>"

but it displays a \' before the varible value, how do i remove this?


05-09-2009, 09:17 AM
It's worth to read http://www.codingforums.com/showthread.php?t=144149

05-09-2009, 10:26 AM
Fou-lu's tutorial might be overkill if you aren't using a lot of gets or posts. If you aren't then just use stripslashes($inputtext)