PHP Detail page help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daveeboi
    New Member
    • Oct 2007
    • 18

    PHP Detail page help

    I have developed a search facility on my site which is now working as intended and produces pages of relevent records from the search. On the resuly pages I have created href links for records that I wish to use to forward users to a detailed html page for their item. I am planning on doing this using adetail.php script where the id will be taken and used to identify the corresponding file. Only problem is I've never done this before do I just post the id in and change the header part accordingly?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    If I am understanding you correctly, you only need to create a <a> link that points to your addetail.php, including the ID of the item you want to view.
    Then, in the addetail.php, you use the $_GET super-global to get the ID and get the item information.

    For example: (doing this in one page, but you get the idea)
    [code=php]
    <?php
    # Get and validate the itemID
    $itemID = $_GET['itemID'];
    if($itemID != abs($itemID) or $itemID <= 0) {
    echo("<p>Item ID is invalid.</p>");
    }
    else {
    # Get and display data from MySQL
    $result = mysql_query("SE LECT * FROM myTable WHERE id = $itemID");
    while($row = mysql_fetch_ass oc($result)) {
    echo "<b>Item details:</b><br>";
    foreach($row as $key => $value) {
    echo " - $key = $value<br>";
    }
    }
    }
    ?>

    <a href="thisPage. php?itemID=1">S how details</a>
    [/code]

    Comment

    • daveeboi
      New Member
      • Oct 2007
      • 18

      #3
      Originally posted by Atli
      Hi.

      If I am understanding you correctly, you only need to create a <a> link that points to your addetail.php, including the ID of the item you want to view.
      Then, in the addetail.php, you use the $_GET super-global to get the ID and get the item information.

      For example: (doing this in one page, but you get the idea)
      [code=php]
      <?php
      # Get and validate the itemID
      $itemID = $_GET['itemID'];
      if($itemID != abs($itemID) or $itemID <= 0) {
      echo("<p>Item ID is invalid.</p>");
      }
      else {
      # Get and display data from MySQL
      $result = mysql_query("SE LECT * FROM myTable WHERE id = $itemID");
      while($row = mysql_fetch_ass oc($result)) {
      echo "<b>Item details:</b><br>";
      foreach($row as $key => $value) {
      echo " - $key = $value<br>";
      }
      }
      }
      ?>

      <a href="thisPage. php?itemID=1">S how details</a>
      [/code]

      It is kind of what I'm aiming for. In my previuos post you were kind enough to help out with also, I had a search form accessing my database to extract all relevent records for criteria. I have a link established for each search output which is..
      [code=php]
      echo "<div id=\"right\"><i mg src=\"".$info['image']."\"><a href=\"detail.p hp\">".$info['title']."</a></div>\n";
      [/code]

      but it's linking it through detail.php I need to establish. What to put in detail.php?
      Last edited by Atli; Oct 3 '07, 01:59 PM. Reason: Added [code] tags.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        If you'd put the code I posted (leave out the link tho) into your details.php, you could change your links to this, in order to get it working:
        [code=php]
        echo "<div id=\"right\"><i mg src=\"".$info['image']."\"><a href=\"detail.p hp?itemID=". $info['id']. "\">".$info['title']."</a></div>\n";
        [/code]
        Assuming that your $info array includes the ID of the item to show.

        Comment

        • daveeboi
          New Member
          • Oct 2007
          • 18

          #5
          is it possible to use header location command for this purpose? I already have made up html detail pages and would like to use them.

          Comment

          Working...