Passing a sql row value in PHP
Posted: Thu Mar 12, 2009 1:02 pm
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>";
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>";