Creating a link with php

I have a mysql table

CREATE TABLE IF NOT EXISTS rentals (
id smallint unsigned NOT NULL auto_increment,
c_id smallint unsigned default NULL,
c_name varchar(50) NOT NULL default ‘’,
unit tinyint NOT NULL,
bldg tinyint NOT NULL,
rooms tinyint NOT NULL,
brooms tinyint NOT NULL,
furnished tinyint NOT NULL,
utilities tinyint NOT NULL,
smoke tinyint NOT NULL,
pets tinyint NOT NULL,
start_date date NOT NULL,
end_date date NOT NULL,
intro varchar(500) NOT NULL default ‘’,
display tinyint default 1,
PRIMARY KEY (id)
);

and I insert my rentals,
How do I create a link to a records primary key (id), heres what im thinking


echo "<a href='manage_images.php?id=/*here I would put the PK of that record, but how do I?*/'>Manage Images</a>";

so, a record has just been inserted and Im trying to figure out how to get its primary key

If this is for a single image then you would just have PHP write in the actual ID of that image, eg.

echo "<a href='manage_images.php?id={$id}'>Manage Images</a>";

where $id would be the reference to your image record ID, how you gather that information will depend on what the rest of your script is doing.

If the link is for multiple images then your link would be best passing a range, and ID and then how many images to display after that ID

echo "<a href='manage_images.php?id={$id}&limit=50'>Manage Images</a>";

Then manage_images.php would have to output that ID and the next 50 images.

As you have only provided a small portion of code and nothing of manage_images.php, it is hard to tell what it is your asking so I have had a stab in the dark with this response.

I’m not sure what you mean…very unclear…is this what you want?


list($primarykey) = mysql_fetch_array(mysql_query("select id from rentals order by id desc limit 1"));

echo "<a href='manage_images.php?id=$primarykey'>Manage Images</a>";  

or


$keys = mysql_query("select id from rentals order by id desc");

while($key = mysql_fetch_array($keys)) {

echo "<a href='manage_images.php?id={$key['id']}'>Manage Images for {$key['id']}</a><br />";  

}

Please be more clear if I am wrong.

thank you!
(sorry for being unclear)

No problem! Glad I could be of help.