SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,648
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    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
    PHP Code:
    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
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    SitePoint Enthusiast bronze trophy \\.\'s Avatar
    Join Date
    Oct 2013
    Location
    UK
    Posts
    72
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If this is for a single image then you would just have PHP write in the actual ID of that image, eg.

    PHP Code:
    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

    PHP Code:
    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.

  3. #3
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure what you mean...very unclear...is this what you want?

    PHP Code:
    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

    PHP Code:
    $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.

  4. #4
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,648
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    thank you!
    (sorry for being unclear)
    "Oh, and Jenkins--apparently your mother died this morning."

  5. #5
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lukeurtnowski View Post
    thank you!
    (sorry for being unclear)
    No problem! Glad I could be of help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •