Re: Getting ID from a presented table



Lennart Anderson wrote:
"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> skrev i meddelandet news:wvSdnUTGP722TWPYnZ2dnUVZ_rylnZ2d@xxxxxxxxxxxxxx
Lennart Anderson wrote:
"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> skrev i meddelandet news:0oGdneT-v7svMmPYnZ2dnUVZ_s3inZ2d@xxxxxxxxxxxxxx
Lennart Anderson wrote:
"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> skrev i meddelandet news:ybqdnXJcAfixAmDYnZ2dnUVZ_vPinZ2d@xxxxxxxxxxxxxx
Lennart Anderson wrote:
"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> skrev i meddelandet news:xtCdnUF-VpfLF2DYnZ2dnUVZ_rbinZ2d@xxxxxxxxxxxxxx
Lennart Anderson wrote:
I'm having a MySQl table wih a lot of information. I want to present some main fields in a table on one page. Each record do, of course, have a unique ID. The presnted table will have one field as a linked field. I want to be able to click this link, retreive the ID information for that record and then present detailed data for that record on the next page.
How do I retreive the ID?
Any hints are very much appreciated.
Thanks
Put the id in the link itself.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
I think I get the idea but I don't know how to doo that. Can you give me an aidea of how such a link with, I guess, embedded ID would look like?
Do you know how to do it in html? Same idea - just generated with a PHP echo statement instead.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
No, I do not know how to do that in HTML.
But, once again, the problem is that I have a number of records presented in a table. All records do have unique ID. When preseneted by the hTML page they are parsed into "hard-coded" HTML and although I can have a field to act as a link I can't get the ID for the special record I am selecting. Only the ID for the last presented record will come through since that ID is still present in the array. Any hint of how to get the ID from any selected record?
OK, posting the code you're using would help a lot.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
Here is the essential part of the code with the presneted table where one of the records field will be a link. I want to retreive the ID for any selefted record from, say, 25 presented.

mysql_select_db('db2') or die ('Unable to select database!');
// create and execute query
$query = "SELECT ID, DATE_FORMAT(addate, '%m-%d') AS adday, DATE_FORMAT(addate, '%H:%i')as adtime, addate, adnamn, adcat, adheader,adtext,adprice,adcats.catname FROM ads, adcats where ads.adcat = adcats.catid order by ID DESC";
$result = mysql_query($query)
or die ('Error in query: $query. ' . mysql_error());
// check if records were returned
if (mysql_num_rows($result) > 0)
{
// iterate over record set
// print each field

echo '<h2>Test on data retrieval from the data base</h2></br>';
echo '<table border=0 cellpadding=2 width = 100% bgcolor="#FFFF99" bordercolor="#FFFFFF">';
echo '<tr>
<td>Ad-No.</td>
<td>Day</td>
<td>Time</td>
<td>Ad-header</td>
<td>Price CI$</td>
<td>Category</td>

</tr>';

while($row = mysql_fetch_object($result))

{
echo '<tr>';
echo '<td width=5% bgcolor="#FFFFFF" align = "right">' . ($row->ID) . '</td>';
echo '<td width=4% bgcolor="#FFFFFF">' . ($row->adday) . '</td>';
echo '<td width=5% bgcolor="#FFFFFF">' . ($row->adtime) . '</td>';
echo '<td width=40% bgcolor="#FFFFFF">' . '<a href= "advertinfo.php" >' . ($row->adheader) . '</td>';
echo '<td width = 6% bgcolor="#FFFFFF" align = "right">' . ($row->adprice) . '</td>';
echo '<td width = 18% bgcolor="#FFFFFF">' . ($row->catname) . '</td>';
echo '</tr>';


}

echo '</table>';

}
else
{
// print error message
echo 'No rows found!';
}


OK, if you're going to make it a link, you have to pass the id as a parameter in the link, i.e.

echo '<td width=40% bgcolor="#FFFFFF">' . '<a href= "advertinfo.php?id=' . $row['id'] . " >' . ($row->adheader) . '</td>';

This will pass the link as "advertinfo.php?id=3", for example.

Then in advertinfo.php you use access it with $_GET['id'].

Be sure to use isset($_GET['id']) in case someone comes to this page without an id being passed.



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Thanks. This seems most promising but don't I need to have some kind of form method to pass the $_GET variable. Just now the table is presented without any kind of form tags.
jstucklex@xxxxxxxxxxxxx
==================



You need a form to pass values via POST. But GET values can be passed in the href. Check alt.html for more info on this.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: Getting ID from a presented table
    ... Jerry Stuckle ... JDS Computer Training Corp. ... PHP echo statement instead. ... I do not know how to do that in HTML. ...
    (comp.lang.php)
  • Re: Getting ID from a presented table
    ... Jerry Stuckle ... JDS Computer Training Corp. ... Same idea - just generated with a PHP echo statement instead. ... I do not know how to do that in HTML. ...
    (comp.lang.php)
  • Re: Getting ID from a presented table
    ... Jerry Stuckle ... JDS Computer Training Corp. ... PHP echo statement instead. ... I do not know how to do that in HTML. ...
    (comp.lang.php)
  • Re: Getting ID from a presented table
    ... Jerry Stuckle ... JDS Computer Training Corp. ... When preseneted by the hTML page they are parsed into "hard-coded" HTML and although I can have a field to act as a link I can't get the ID for the special record I am selecting. ... Any hint of how to get the ID from any selected record? ...
    (comp.lang.php)
  • Re: Getting ID from a presented table
    ... Jerry Stuckle ... JDS Computer Training Corp. ... echo statement instead. ... I do not know how to do that in HTML. ...
    (comp.lang.php)