Jump to content

creating a Link to customers page using search


moosey_man1988
Go to solution Solved by cyberRobot,

Recommended Posts

Hi There

 

So I've Created a search results page, this displays as you can see attached to this post

 

post-178672-0-77929100-1432114557_thumb.png

 

 

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by rwhite35
Link to comment
Share on other sites

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 :(
Link to comment
Share on other sites

  • Solution

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>';
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.