Problem finding which row selected

Codes here !

Moderators: macek, egami, gesf

Jules00
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Feb 16, 2003 11:08 am

Problem finding which row selected

Postby Jules00 » Sun Feb 16, 2003 11:16 am

Im new to php/mysql so my question might sound pretty basic. I want php to look in my database and list all the values of a table in a web interface im creating. The code I use to diplay the rows is shown as follows:

Code: Select all

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<tr align='center'><td height='30'><a href='edit.php'>edit</a>  <a href='delete.php'>delete</a></td><td>";
echo htmlspecialchars( stripslashes($row["class_name"]));
echo "</td><td>";
echo htmlspecialchars( stripslashes($row["class_date"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["name"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["email"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["company"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["position"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["phone"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["city"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["state"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["zip_code"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["comments"]));
echo "</td></tr>";
}


The problem is that I want a "delete/edit" option for each row, in the form of a link (similar to the phpmyadmin table viewing page). I have no idea how to figure out how to tell which row the user selects the "edit/delete" link from. Im not sure how clear this explanation is, but if anyone could help me I would gladly appreciate it. Thank you :)

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Sun Feb 16, 2003 12:47 pm

if you have created your database correctly you should have a primary key. usually 'id' or the sort.

in the 'edit' href you can append the id and have php use the $_GET super global to determine what record you want to edit. example using your sample.

Code: Select all

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<tr align='center'><td height='30'><a href='edit.php?record=".$row["id"]."'>edit</a>  <a href='delete.php?record=".$row["id"]."'>delete</a></td><td>";
echo htmlspecialchars( stripslashes($row["class_name"]));
echo "</td><td>";
echo htmlspecialchars( stripslashes($row["class_date"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["name"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["email"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["company"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["position"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["phone"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["city"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["state"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["zip_code"]));
echo "</td><td>";
echo htmlspecialchars (stripslashes($row["comments"]));
echo "</td></tr>";
}

Jules00
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Feb 16, 2003 11:08 am

Postby Jules00 » Sun Feb 16, 2003 3:26 pm

Thank you very much!
Just what i needed :)


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest