I'd like to create a master/detail page using php for my site. In other words, when someone searches my database and it displays 100 records of say a product name and image, how do I create a link under each record displayed that will open a details page about JUST that record? You know what I'm saying?

SO if anyone has advice, I'd greatly appreciate it....thanks!

    Have a details page that opens a database or a file, and queries the database for only a single entry, using that product ID.

    Then, the person clicks a link similar to "details.php?id=1", where the ID is sent via GET. The ID can then be retrieved by using $_GET["id"].

    Hope that helps. If you need more information, like how to use this in a database, just ask.

      let's assume your DB table looks something like this:

      ITEMS
      ----------------------------------------
      ID NAME           DESCRIPTION
      1  Gnabber        Even more gnabber
      2  Gnuelp         Even more gnuelp
      2  Blubb          Even more blubb
      

      you select the whole table with:

      SELECT * FROM ITEMS ORDER BY NAME
      

      then you output a list with something like:

       
      while( $row = mysql_fetch_assoc($rs) )
      {
      	echo "<a href=\"detail.php?ID={$row['ID']}\">{$row['NAME']}</a><br>\n";
      }
      

      Then you have a detail-page "detail.php" where you can select a single entry with

      SELECT * FROM ITEMS WHERE ID={$_GET['ID']}
      

      easy enough, isn't it? =)
      hope that helps,

      tREXX

        Assuming you use an autoincrement column in your table, do something like this in the master script.

        $query = "SELECT * FROM mytable";

        Then loop through the rows and use mysql_fetch_array or whatever to extract the row data, printing the data and making a link to the details page. (Assuming your autoincrement column is named ID).

        echo "<A HREF='details.php?ID=" . $row["ID"] . "'>details</A>";

        Then, on your details page, create a query like this ...

        $query = "SELECT * FROM mytable WHERE ID = ' " . $_GET["ID"] . "'";

        Extract all the data and print it.

        Hope this makes sense.

          Oops, sorry I left my window open too long, didn't see Trexx's post.

            while( $row = mysql_fetch_assoc($rs) )

            Which variable is that? Or are we just creating it now...I know very little php so I'm not sure where this variable comes from....

              $rs would be the result of querying the database.

                sorry... the "complete" example (without the code to connect to your database) should look like:

                $rs = mysql_query( "SELECT * FROM ITEMS ORDER BY NAME" );
                while( $row = mysql_fetch_assoc($rs) )
                {
                    echo "<a href=\"detail.php?ID={$row['ID']}\">{$row['NAME']}</a><br>\n";
                }
                
                  Write a Reply...