0
    //DB CONNECTION
   $sql = "SELECT `city`,`country` from infotab";
   $result = $conn->query($sql);

   while ($row = $result->fetch_assoc()) {
     echo  $row["city"].$row["country"]"<a href='order.php'>order</a>"; }

Table output:

http://imgur.com/jH2VzBf

This code will select data. Additionally, there is reference to order.php on every line. When the user clicks on reference( <a href> clause), it opens order.php and there I need to know which row the user selected to work with these data.

1
  • Do you have a id column in your db? yes, why not use the id? Commented Apr 26, 2015 at 10:08

1 Answer 1

1

Change the code to:

while ($row = $result->fetch_assoc()) {         
    echo  $row["city"] . $row["country"] . "<a href='order.php?city=" . $row["city"] . "&country=" . $row["country"] . "'>order</a>";
}

In order.php you can then access these values by using the $_GET["city"] and $_GET["country"] variables which contain the values from your <a href> link on the previous page. For example, running echo $_GET["city"]; will output the city name.

Edit: As @Rizier123 pointed out, using a unique ID might be more prone to errors in case your database contains more than one entry for the same city or country. You should consider introducing an ID in your table structure and then using that in the link to order.php.

Sign up to request clarification or add additional context in comments.

5 Comments

I doubt that the city is a unique column in OP's db!
You may have a point. Anyway, we don't know that and the combination of city and country could be unique. @Martin: Please clarify.
That's what I'm already asking: stackoverflow.com/questions/29876269/… (In other words, your solution can work if OP uses something unique to identify the row)
These data aren t unique, but i ll try to implement ids.
This tutorial could help you --> MySQL Primary Key

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.