Page 1 of 1

Passing a sql row value in PHP

Posted: Thu Mar 12, 2009 1:02 pm
by srefer
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>";

Re: Passing a sql row value in PHP

Posted: Thu Mar 12, 2009 2:06 pm
by jaoudestudios
Dont use the name, use the ID for the next page. You can put it in the url not in a form.
i.e.

Code: Select all

while (....) {
...
echo "<a href='details.php?id=".$row['id']."'>name</a>";
...
}

Re: Passing a sql row value in PHP

Posted: Wed Mar 25, 2009 6:04 pm
by srefer
Thanks so much!! That's exactly what I was looking for!!