www.webdeveloper.com
Results 1 to 3 of 3

Thread: links update dynamic data

  1. #1
    Join Date
    Jul 2005
    Posts
    23

    Unhappy links update dynamic data

    I'm not exactly sure what this is called, so it's hard to do a search on it.

    What I'm trying to do is have a webpage that updates the dynamic data from a database based on what links are chosen on the left side of the page.

    - On one side of the page is a list of links. (ie: potato, carrot, apple...)

    - On the other side of the page is a bunch of dynamic data that connects to a MySQL database.

    Depending on what is chosen on the left side of the page, it will show the user that information from the database on the right side.
    Example:
    If you click on the apple link, it pulls the apple row out of the database and presents a picture of an apple, gives some information on an apple, etc.

    I don't think this is very hard but I don't see it in any of the books I have, and have never done it before. Can someone help point me in the right direction or tell me how this is done?

    Thanks,
    Josh

  2. #2
    Join Date
    Aug 2005
    Location
    Los Angeles, CA
    Posts
    52
    An example, where you have a database table named 'fruits' with a column named 'fruit' and a column named 'description'.

    Put this in the left side of the page to display links.
    PHP Code:
    <?php
     $result 
    mysql_query('SELECT fruit FROM `fruits`');
     while (
    $line mysql_fetch_array($result)) {
      echo 
    '<a href="index.php?q=' $line['fruit'] . '">' $line['fruit'] . '</a><br />';
     }
    ?>
    Put this in the right side of the page to display the chosen fruit.
    PHP Code:
    <?php
    if($_GET['q'] != '') {
     
    $fruit $_GET['q'];
     
    $result mysql_query('SELECT * FROM `fruits` WHERE `fruit` = ' $fruit ' LIMIT 1;');
     
    $line mysql_fetch_array($result);
     echo 
    '<p><b>' $line['fruit'] . '</b><br />Description: ' $line['description'] . '</p>';
    } else {
      echo 
    '<p>You have not selected a fruit!</p>';
    }
    ?>

  3. #3
    Join Date
    Jul 2005
    Posts
    23

    resolved

    ok, so playing around with it tonight I finally have it figured out. Apparently I found after testing it out that you cannot use the same name as the field you are ultimately trying to call.
    What I mean is if your table column is called auto.... don't call the parameter auto throughout. It just doesn't like you very much if you do.

    I thought I would post my code for those that are interested.

    The upper code before the <head> starts
    Code:
    <?
    mysql_select_db($database_test, $test);
    $something = $_GET['num'];
    $query_Recordset1 = "SELECT auto, image, `desc`, `comment` FROM test WHERE auto='$something'";
    $Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?>
    The links that call the specific row in the table
    Code:
    <p><a href="test.php?num=1">Set 1</a></p>
    <p><a href="test.php?num=2">Set 2</a></p>
    <p><a href="test.php?num=3">Set 3</a></p>
    <p><a href="test.php?num=4">Set 4</a></p>
    And finally the code that displays the 3 items based upon the 'auto' field
    Code:
    <p><img src="<?php echo $row_Recordset1['image']; ?>" /></p>
    <p>&nbsp;<?php echo $row_Recordset1['desc']; ?></p>
    <p>&nbsp;<?php echo $row_Recordset1['comment']; ?></p>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles