link to and edit page with the record ID number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

link to and edit page with the record ID number

Post by cjkeane »

Hi.

The code i'm using below lists all records as follows:
Name ID Number Company Name
john smith 1 ICBC
etc.

I need to be able to click on the id number and open an edit page for that specific record. I'm not sure how to go about doing that. I'd appreciate any help you may be able to offer. thx.

<?php
echo "<TABLE BORDER=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
echo "<TR ><TD>Name</TD><TD>ID Number</TD><TD>Company Name</TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR >\n";
} else { //if there isn't a remainder we will do the else

echo "<TR > \n";
}
echo "<TD>".$row['Name']."</TD><TD>".$row['IDNumber']."</TD><TD>".$row['CompanyName']."</TD>\n";
echo "</TR>\n";
}
//close table
echo "</TABLE>\n";
?>
pburgh
Forum Newbie
Posts: 13
Joined: Mon Feb 14, 2011 3:14 pm
Location: Boston

Re: link to and edit page with the record ID number

Post by pburgh »

If I understand correctly, change your code to:

echo "<TD>".$row['Name']."</TD><TD><a href="\edit.php?id=".$row['IDNumber']."\"edit</a></TD><TD>".$row['CompanyName']."</TD>\n";

Then, on the edit.php page, use the id url parameter as your key in in to the database (for your recordset).
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: link to and edit page with the record ID number

Post by cjkeane »

That is what i want, but without the word edit. in dreamweaver, i'm getting a red line indicating an error in the code, so i'm not sure where the error is in the code you gave me.
pburgh
Forum Newbie
Posts: 13
Joined: Mon Feb 14, 2011 3:14 pm
Location: Boston

Re: link to and edit page with the record ID number

Post by pburgh »

Oops, I had my escape character out of order:

echo "<TD>".$row['Name']."</TD><TD><a href=\"edit.php?id=".$row['IDNumber']."\"edit</a></TD><TD>".$row['CompanyName']."</TD>\n";
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: link to and edit page with the record ID number

Post by cjkeane »

its getting close. but when i view the page. the id number now is blank.
i don't need an edit link, just when they click on the id number for the related page to open.
pburgh
Forum Newbie
Posts: 13
Joined: Mon Feb 14, 2011 3:14 pm
Location: Boston

Re: link to and edit page with the record ID number

Post by pburgh »

ha, sorry again. fixed

echo "<TD>".$row['Name']."</TD><TD><a href=\"edit.php?id=".$row['IDNumber']."\">edit</a></TD><TD>".$row['CompanyName']."</TD>\n";
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: link to and edit page with the record ID number

Post by cjkeane »

thx for getting back to me. It's close :)

I'm getting the following displayed:
john smith 'edit' ICBC

But i need it to be:
john smith '1' icbc

where, when they click on the idnumber (1) it goes to edit.php?id=1
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: link to and edit page with the record ID number

Post by cjkeane »

I figured it out by
</TD><TD><a href=\"edit.php?id=".$row['IDNumber']."\">".$row['IDNumber']."</a></TD>

thx for your help.
pburgh
Forum Newbie
Posts: 13
Joined: Mon Feb 14, 2011 3:14 pm
Location: Boston

Re: link to and edit page with the record ID number

Post by pburgh »

no prob. my code was just an example, not a solution. :)
Post Reply