Page 1 of 1

link to and edit page with the record ID number

Posted: Tue Feb 15, 2011 2:04 pm
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";
?>

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

Posted: Tue Feb 15, 2011 2:21 pm
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).

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

Posted: Tue Feb 15, 2011 2:36 pm
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.

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

Posted: Tue Feb 15, 2011 2:59 pm
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";

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

Posted: Tue Feb 15, 2011 3:15 pm
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.

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

Posted: Wed Feb 16, 2011 6:52 am
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";

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

Posted: Wed Feb 16, 2011 2:31 pm
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

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

Posted: Wed Feb 16, 2011 6:29 pm
by cjkeane
I figured it out by
</TD><TD><a href=\"edit.php?id=".$row['IDNumber']."\">".$row['IDNumber']."</a></TD>

thx for your help.

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

Posted: Thu Feb 17, 2011 8:27 am
by pburgh
no prob. my code was just an example, not a solution. :)