How to generate a link that can pass on a variable?

Posted on 2004-10-30
Last Modified: 2008-02-20
Ok here is what i am trying to do!

I have a customer database and i want to make somethign that prints all the customers to the screen so that you can click on a customer and edit their information.  I know how to do this using a combo box and a form but i am looking for a more intuitive way of acomplishing this task.
Question by:mightofnight
    LVL 1

    Accepted Solution

    $customer_id = 1; // get from database
    echo '<a href="edit_customer.php?customer_id=' . $customer_id . '">' . $customer_name . '</a>';

    echo $customer_id;
    LVL 2

    Author Comment

    That was so easy it’s disgusting :P

    Thanks a lot dude
    LVL 12

    Expert Comment


    This way will display all customers in a HTML table, with one customer in each row and a edit link for each of the customers under appropriate table headers. When click on the "Edit" link, you will get redirected to the edit page and the customer id will also get passed to the edit page, so the system knows which customer to edit.

    DISPLAY CUSOMTER IN TABLE**********************************************

    $query = mysql_query("SELECT * FRIN customer");

    <TABLE WIDTH ="100%" BORDER ="1">
    <TD>Customer Name</TD>
    <TD>Customer Surname</TD>
    <TD>Customer Email</TD>
    <TD>Edit Customer</TD>


    while ($row = mysql_fetch_assoc($query))
          echo "<TR>";
          echo "<TD>" . $row['customer_name'] . "</TD>";
          echo "<TD>" . $row['customer_surname'] . "</TD>";
          echo "<TD>" . $row['customer_email'] . "</TD>";
          echo "<TD><a A HREF ='edit_customer.php?id=" . $row['customer_id'] . "'>Edit</TD>";
          echo "</TR>";


    EDIT CUSTOMER**********************************************
    //on this page you will do a query with something like this:
    $query = mysql_query("SELECT * FROM customer WHERE customer_id = '$_GET[id]'");
    LVL 2

    Author Comment

    Thanks for the code you saved me some time... if i could i would give you some points to!

    not that i need to do this right now but how do you do multiable variables?  Exp

    the galleary i use on my website

    in this link it appears that there are two variables
    and that & is the seperator of the two variables? am i right in thinking this?
    LVL 2

    Author Comment

    I know i just posted but just wanted to thank you guys again for the help, i feal like a little kid i am so excited. I was expecting to spend most of the day doing this and now i will be able to have this part of my form done in a couple of hours!
    LVL 12

    Expert Comment

    no prob :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    845 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now