Hi I have a query in which all of the first names are retrieved from a table. I want to be able to display each person in the table and then allow a user to click a name which would take them to a new page that contains all the information about each person. The code for my query is below. I had the information displaying in a table so it's easier to read. The problem is....I need to pass the text in the name field using the get method because in the next page ill run a query to get all the rest of the information about the person.
I don't know if this is the right way to go about it.....or if my thinking is wrong somewhere? The code I have below with the input tag isn't working. I didn't know if there was an easier way to do this?
$result = mysql_query("SELECT * FROM tech;");
echo "<table><tr><th>Name</th>";
echo "<form action='updateTech2.php' method='get'>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>" . $row[name] . "</td>";
$name = $row[name];
echo "<input type='hidden' name="$name" value="$row[name]">";
echo "Value in the php name variable is " . $name;
}
echo "</form></table>";
Passing a sql row value in PHP
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Passing a sql row value in PHP
Dont use the name, use the ID for the next page. You can put it in the url not in a form.
i.e.
i.e.
Code: Select all
while (....) {
...
echo "<a href='details.php?id=".$row['id']."'>name</a>";
...
}Re: Passing a sql row value in PHP
Thanks so much!! That's exactly what I was looking for!!