moosey_man1988 Posted May 20, 2015 Share Posted May 20, 2015 Hi There So I've Created a search results page, this displays as you can see attached to this post as you can see i have Joe Bloggs with a customer reference number of CRM00017 How can i make the results show the customer reference as a Link that once clicked takes them to the customers page with all information? e.g click the link this takes me to existingCustomers.php/id=00017 kinda thing :| I know its a long shot to ask on A forum for such a big thing, I am willing to accept extra help further to this if someone can guide me into building this function. Any help would be massively appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/296415-creating-a-link-to-customers-page-using-search/ Share on other sites More sharing options...
rwhite35 Posted May 20, 2015 Share Posted May 20, 2015 If you want to create the links server side, the script that produced the result needs to have that logic. If you want to create links on the client side, you'll need to look at some JQuery or Javascript functionality. Personally, I prefer the server side logic. Can you post the code that creates the page result, specifically the code block for each result? Quote Link to comment https://forums.phpfreaks.com/topic/296415-creating-a-link-to-customers-page-using-search/#findComment-1512282 Share on other sites More sharing options...
moosey_man1988 Posted May 20, 2015 Author Share Posted May 20, 2015 well what i was thinking is at the moment I have searchresults.php in the results I have this <?php if(mysql_num_rows($search_query)!=0) { do { ?> <tr><td><a href="editCustomer.php customerRef=<?php echo $search_rs['prefix'],$search_rs['customerId'];?>"><?php echo $search_rs['prefix'],$search_rs['customerId'];?></a></td><td> but i need to pass the customer reference to the editCustomer.php for it to run a mysql query with the variable $customerRef really not sure if this is going to work, but i cant find any pages that can help me with this kind of logic. I'm doing building as i learn as I find it a much more practical way of learning the language. could i do it like this? $CustomerRef= "$search_rs['prefix'],$search_rs['customerId']"; the link having edicustomer.php -c $customerRef then in editCustomer have $arguments = getopt("c:"); and then have another variable like $customerNumber = $arguments['c']; a little confusing but i hope you get it? lol Quote Link to comment https://forums.phpfreaks.com/topic/296415-creating-a-link-to-customers-page-using-search/#findComment-1512287 Share on other sites More sharing options...
rwhite35 Posted May 20, 2015 Share Posted May 20, 2015 (edited) You want to look at urlencoding( ) function and $_GET superglobals on php.net. The short answer is //concatinate all your vars proto prefix~custid $vars = $search_rs['prefix'] ."~". $search_rs['customerId']; //assign to $_GET <a href="editCustomer.php?customerRef=<?php echo $vars?>> Then on the editCustomer.php page if ($_GET['customerRef']) { $customer = explode('~',$_GET['customerRef']); } echo $customer[0]; //should be prefix echo $customer[1]; //should be custid Edited May 20, 2015 by rwhite35 Quote Link to comment https://forums.phpfreaks.com/topic/296415-creating-a-link-to-customers-page-using-search/#findComment-1512288 Share on other sites More sharing options...
moosey_man1988 Posted May 20, 2015 Author Share Posted May 20, 2015 Hi Thanks that worked so well! but one last thing what am i doing wrong here if ($_GET['customerRef']) { $customer = explode('~',$_GET['customerRef']); } echo $customer[0]; //should be prefix echo $customer[1]; //should be custid $vars = $customer[1]; echo "$vars"; the echo $vars doesnt work, with or without speechmarks Quote Link to comment https://forums.phpfreaks.com/topic/296415-creating-a-link-to-customers-page-using-search/#findComment-1512294 Share on other sites More sharing options...
Solution cyberRobot Posted May 20, 2015 Solution Share Posted May 20, 2015 Is PHP set to show all errors and warnings? Note that you can add the following to the top of your script(s) during the debugging process to show them: error_reporting(E_ALL); ini_set('display_errors', 1); Is $customer being set anywhere else in the script...besides when the "customerRef" GET variable is passed? Assuming it's not, you'll want to enclose all the statements involving $customer in that if construct. Note that you'll also want to use isset() in the if construct to avoid an undefined index warning. //IF CUSTOMER REFERENCE WAS PASSED, PROCESS IT if(isset($_GET['customerRef'])) { $customer = explode('~',$_GET['customerRef']); echo $customer[0]; //should be prefix echo $customer[1]; //should be custid $vars = $customer[1]; echo $vars; ///ELSE...SKIP PROCESSING / DISPLAY ERROR } else { echo '<p>GET variable is missing...</p>'; } Quote Link to comment https://forums.phpfreaks.com/topic/296415-creating-a-link-to-customers-page-using-search/#findComment-1512298 Share on other sites More sharing options...
moosey_man1988 Posted May 22, 2015 Author Share Posted May 22, 2015 Hi Guys, Thanks for this, I now have the pages the way I want Quote Link to comment https://forums.phpfreaks.com/topic/296415-creating-a-link-to-customers-page-using-search/#findComment-1512424 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.