SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Threaded View

  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help for a query that makes a table to depend of another table to execute.

    The first query is put in an Ul at the left side of the web page that contain three kind of shoes,
    HTML Code:
    <ul><li>
    Sneakers
    Dress shoes
    Boots</li></ul>
    Then the second query presents a table of the sneakers, dress shoes or Boots, or whatever kind you click on the <ul>, in other words the content of the second query will depend on the kind of shoe you choose or click on from the <ul> at the left side of the page similar to the illustration above. Now what I am trying to accomplish is to JOIN the two queries, where whenever a user click on a kind of shoe on the <ul> then it presents all the kinds of that kind in the table which is going to be at the right side of the page containing the second query.

    What I have done so far is to create a database with two table one named Shoe_kind and the other Shoe. in both tables I have created a field called kind_id so it can connect together. The first kind of shoe has 8 shoes and all and each shoe has the integer of (1) assigned to its kind_id field, then the second kind of shoe has 8 shoes as well and each shoe has the integer of (2) assigned to its kind_id field, and so on.... but so far I haven't get them connected, what am I missing? so that when a user click on a kind of shoes all the shoes kinds of that specific kind appears according to the relationship they have through the kind_id field.


    The question is How can I improve the coding to reach that command?

    Help please.

    PHP Code:
    <?php
    if(isset($_GET['shoe'])){
    $sel_shoe $_GET['shoe'];
    }else { 
    $sel_shoe "";
    }

    ?>


    <td style="left:2px;" bordercolor="#666666" bgcolor="#ffffff" border="1" width="156"><ul class="shoe"><?php 
       $query 
    "SELECT * 
                  FROM shoe_kind
                  ORDER BY position ASC"
    ;
      
    $result mysql_query($query$connection);
      if(!
    $result){
      die(
    "Database query failed: " mysql_error());
      }
      while(
    $row mysql_fetch_array($result)){
      echo 
    "<li"
      if (
    $row["kind_id"] == $sel_shoe) {
      echo 
    " class=\"selected\"";
      }
      echo 
    "><a href=\"example1.php?shoe=" urlencode($row["kind_id"]) ."\">{$row["shoename"]}</a></li>";
      }
    ?></ul> </td>

     <?php $query "SELECT shoe.shoename, shoe.price, shoe.moreinfo 
    FROM shoe
    INNER 
    JOIN shoe_kind 
    ON shoe.kind_id=shoe_kind.kind_id"

    $result mysql_query($query$connection);
    while (
    $row mysql_fetch_array($result)) {
    echo 
    "<table style=\"float:left\">
    <td width=\"150\" style=\"text-align:center;\">" 
    $row['shoename'] . "</td>
    <tr>
    <td height=\"100\" width=\"100\"   style=\"position:relative;\">
    <img src=\"../images/shoesname.jpg\" alt=\"sd\" width=\"97\" height=\"80\"  border=\"1\" style=\"border-color:#FF6600;\" />
    </td></tr>
    <tr>
    <td width=\"5\" height=\"21\" ></td><td>" 
    $row['price'] . "</td>
    </tr>
    <td>" 
    $row['moreinfo'] . "</td>
    </table>"
    ;

    ?>
    Last edited by co.ador; May 10, 2009 at 19:47.


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
  •