Solved

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

Posted on 2004-10-30
220 Views
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.
0
Question by:mightofnight
    6 Comments
     
    LVL 1

    Accepted Solution

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

    edit_customer.php:
    echo $customer_id;
    0
     
    LVL 2

    Author Comment

    by:mightofnight
    That was so easy it’s disgusting :P

    Thanks a lot dude
    0
     
    LVL 12

    Expert Comment

    by:minichicken
    Hi

    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**********************************************
    <?
    //DO DATABASE CONNECTION HERE

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

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

    <?

    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>";
    }
    ?>

    </TABLE>

    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]'");
    ?>
    0
     
    LVL 2

    Author Comment

    by:mightofnight
    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
    http://www.mightofnight.com/wallpaper/index.php?album=1024x768%2F&pic=4K1-0.JPG

    in this link it appears that there are two variables
    album=1024x768%2F
    pic=4K1-0.JPG
    and that & is the seperator of the two variables? am i right in thinking this?
    0
     
    LVL 2

    Author Comment

    by:mightofnight
    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!
    0
     
    LVL 12

    Expert Comment

    by:minichicken
    no prob :)
    0

    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