inquisitive Posted September 26, 2008 Share Posted September 26, 2008 Ok here is my code: <a href="cart.php?action=add&id='.$row['id'].'"> ok now i am prolly really just making this more complicated than it is...but how do i make this a variable... What I am trying to accomplish is that my shopping cart page calls this using $_GET['action']....but I need to make it so that it only executes my function if the link is pushed. In order to do that i believe i need to setup an (isset['$action']) or something similar....some help please??? Quote Link to comment https://forums.phpfreaks.com/topic/125939-setting-a-php-link-as-variable/ Share on other sites More sharing options...
dave_sticky Posted September 26, 2008 Share Posted September 26, 2008 If I understand what you mean, then you could probably do this using sessions and substr_count() <?php if(substr_count($_SESSION['shopping_basket'],$_GET['id']) == 0)) { $_SESSION['shopping_basket'] = $_SESSION['shopping_basket'].";".$_GET['id']; } ?> That'll only add items to the shopping basket, based on the value in the url, if value isn't already in the session. Also stores multiple items in the shopping basket, which you can separate using explode(). Is that what you were after? Quote Link to comment https://forums.phpfreaks.com/topic/125939-setting-a-php-link-as-variable/#findComment-651225 Share on other sites More sharing options...
inquisitive Posted September 26, 2008 Author Share Posted September 26, 2008 well actually sort of...i literally want to turn that link i posted into a variable then way within my functions page I can write a script to execute based on that being clicked...right now it just calls a function that automatically runs through the cart...if you need to see some code I can put it up on phpfi.com ... Quote Link to comment https://forums.phpfreaks.com/topic/125939-setting-a-php-link-as-variable/#findComment-651235 Share on other sites More sharing options...
dave_sticky Posted September 26, 2008 Share Posted September 26, 2008 So when you click the link at the moment, a function is called that looks at everything in the cart, but you just want it to look at one thing in particular? If you want the link in a variable, all you need to do is <?php $link = "<a href='cart.php?action=add&id=".$row['id']."'>Link</a>"; ?> But I'm pretty sure that isn't what you mean. May need to look at some of your code! Quote Link to comment https://forums.phpfreaks.com/topic/125939-setting-a-php-link-as-variable/#findComment-651258 Share on other sites More sharing options...
inquisitive Posted September 26, 2008 Author Share Posted September 26, 2008 Ok i am uploading the code http://phpfi.com/357278 Quote Link to comment https://forums.phpfreaks.com/topic/125939-setting-a-php-link-as-variable/#findComment-651295 Share on other sites More sharing options...
dave_sticky Posted September 29, 2008 Share Posted September 29, 2008 Ok, Still trying to get my head round your code, but 1st of all, there is an error on line 28. (Looks like you just copied the code that I last posted in, so partially my fault I suppose). <?php $output[] = '<li>"'.$row['product_name'].'" by '.$row['manufacturer'].': $'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to Cart</a></li>'; ?> Which function is it that you are having a problem with it, or what is it that you need the function to do? You know you can pass values to functions? <?php function yourFunction($value,$vaule2) { // Your function code. } // And to call the function yourFunction("The 1st thing you want to pass to it","The 2nd thing"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/125939-setting-a-php-link-as-variable/#findComment-652806 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.