Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do they do this? 1

Status
Not open for further replies.
Well presumably each ad is a record in a database with a unique ID.

Then when you click the scissors, the ad's id is stored within your session, or as a cookie on your machine.
So when you go to "My List" the server simply retrieves the records corresponding to the ads you have clipped by looking at your session/cookie and getting the relevant id numbers.

I am not sure of the exact way that this particular site works, but that's the general idea.

 
hey i am ubable to open the page in my system...

Known is handfull, Unknown is worldfull
 
Actually, looking more closely at the site.
They appear to be using javascript to manage the clipping.
 
Ah the page came at last. it is javascript... it is simply a matter of changing the image src of the main page by the popup page...

Known is handfull, Unknown is worldfull
 
Foamcow, what you said at first is the path I was trying. So I have a form with a submit button in each listing. Each form in each listing contains a hidden field with the unique_id for each listing. But what should the action be for the form? I tried $SERVER['PHP_SELF'], but since this is already on the results page, wouldn't I have to resend all the information that was on the search page? Or is there a way to skip the code on the results page that retrieves the results, and only parse* the code that will store the unique_id's a session variables? Is there a way to have the user click the button and store the variable, without reloading the whole page?

*is parse the right word?

This is my first dynamic site so I might be missing a basic concept that I need when it comes to processing a form via $SERVER['PHP_SELF']. Here is the site I'm trying to do this for: I hope I was clear in my problem. Thanks.
 
Well, I wouldn't use a form for a start.
They are only using one as they are compiling this list with Javascript functions (I think... I am going out on a limb here)

Simply provide a link for each item that passes the id of that item to the same page its on. Then at the top of the page detect whether an id is being passed and append it to an array.

So you end up with an array that contains a number of ids.
Then when the user views the "my list" page, that array is used to generate the listing. I am guessing that this array should be a session variable so it has some persistance. PHP has some nice session handling functions that make life fairly easy in this respect.

To be honest, I am probably talking out of my arse here...
It's been a long, hard and hot day
and I don't think I would do it quite the same way if I sat down and thought about it for more than 5 minutes ;-)
 
"Simply provide a link for each item that passes the id of that item to the same page its on."

Is there a term for this so I can look up how to do what your saying? Thanks.
 
Heres the javascript in the page:
Don't know much javascript, so can't tell you how it works...
function changeAction(){
if ( document.quickSearch.alias.selectedIndex < 0 )
{
alert( 'Please select a category from the list.' );
return false;
}
document.quickSearch.action='/c2/'+document.quickSearch.alias.options[document.quickSearch.alias.selectedIndex].value +'/results/index.xml';
return true;
}

Magic... not really. It'd be that easy to do with PHP or ASP too.
 
Hi.. sorry it has taken me some time to get back to you.

Hmm, I know this should be easy, but the method I jsut tried does not work as I thought it would.

Code:
<!doctype html public &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title> Parameter Passing Test </title>
</head>
<body>
<? 
// set up session var array if not existing
if (!isset($_SESSION['list'])){
	$_SESSION['list']=array(&quot;item1&quot;,&quot;item2&quot;,&quot;item3&quot;,&quot;item4&quot;,); // fill the array with some test data to find where its going wrong
	}

// append the value of the passed parameter into the array
$_SESSION['list'][]=$_GET['parameter'];

//Output the list
echo(&quot;<h2>Here is your list</h2><br>&quot;);

// access the array in the session Var and output the values stored in it
foreach($_SESSION['list'] as $key => $value){
	echo($key.&quot; = &quot;.$value.&quot;<br>\n&quot;);
}
?>

<hr>
<h2>Pick an item from here</h2><br>
<p>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Fishpaste&quot;>Fishpaste</a><br>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Handgrenade&quot;>Hangrenade</a><br>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Mobile Phone&quot;>Mobile Phone</a><br>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Shoelaces&quot;>Shoelace</a><br>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Rubber Duck&quot;>Rubber Duck</a><br>
</p>
</body>
</html>

Now, I thought that this would append the value of the URL parameter to the array stored in $_SESSION['list'].
It does, but then when I try and append another value to the array it replaces the last one.

I expect that I have misunderstood how session variables work. I have used them before to handle a login thingy and didn't have any problem there.
As I understand it, a session variable should be available to the user/script throughout the &quot;session&quot; of that user's activity on the site.
So in my mind each time they click on one of the links in my test page, the corresponding value would get added to the list.

I'm going to try and spend some time on this tonight, hopefully i should get the answer as to why it doesnt work!
 
Oh you git ;-)

Yes.. it works now
Code:
<? session_start(); ?>
<!doctype html public &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title> Parameter Passing Test </title>
</head>
<body>
<? 
// set up session var array if not existing
if (!isset($_SESSION['list'])){
	$_SESSION['list']=array(&quot;item1&quot;,&quot;item2&quot;,&quot;item3&quot;,&quot;item4&quot;,); // fill the array with some test data to find where its going wrong
	}

// append the value of the passed parameter into the array
$_SESSION['list'][]=$_GET['parameter'];

//Output the list
echo(&quot;<h2>Here is your list</h2><br>&quot;);

// access the array in the session Var and output the values stored in it
foreach($_SESSION['list'] as $key => $value){
	echo($key.&quot; = &quot;.$value.&quot;<br>\n&quot;);
}
?>

<hr>
<h2>Pick an item from here</h2><br>
<p>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Fishpaste&quot;>Fishpaste</a><br>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Handgrenade&quot;>Hangrenade</a><br>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Mobile Phone&quot;>Mobile Phone</a><br>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Shoelaces&quot;>Shoelace</a><br>
<a href=&quot;<?=$_SERVER['PHP_SELF'];?>?parameter=Rubber Duck&quot;>Rubber Duck</a><br>
</p>
</body>
</html>

Now I could have SWORN that I read that you don't need to use session_start() with $_SESSION.

LMAO... can't see the wood for the trees as they say
Thanks ;)

 
You can use sessions without using session_start(). If an only if the PHP runtime configuration directive &quot;session.auto_start&quot; is set to either &quot;1&quot; or &quot;yes&quot;. The default value is either &quot;0&quot; or &quot;no&quot;.

I do not recommend changing this value -- why enable functionality you don't use?

If you're running PHP with Apache, you can change this value at a very discrete level -- you can set this value in httpd.conf or a .htaccess file.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Youre the best. I havent had a chance to work on the site because I'm swamped with overtime at work. I'll let you know how it works out though. Thanks so much
 
I almost have it but how would I select from the database WHERE listing_id = an array? When the user wants to display their listings I have to select from the db all the listings for values stored in the session variable array. Or would the listings be retrieved a different way?
 
There are two ways I can think of off the top of my head.

Use each array element in a query in turn and aggregate the results.

Use the individual array values in a comma-separated list to be fetched. Something like MySQL's WHERE id in (<list of ids>).


Either way, you're going to have to loop across the array.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
This code outputs the values in the array:


foreach($_SESSION['list'] as $key => $value)
{
echo($value);
}

_________________

How would I get the outputs into the query:

&quot;SELECT * FROM listings WHERE listing_id = &quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top