Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    38
    Thanks
    2
    Thanked 0 Times in 0 Posts

    PHP how to show a single result directed from a results list?

    Hello, I am making a website which has a number of products, I decided to make it MySQL database based (I don't know if my issue belongs in the MySQL section).

    It all works apart from one feature I cannot figure out - how to show a single product/row when one is clicked on from the list?

    My PHP code is here:

    PHP Code:
    <?php 
          
    if(isset($_GET['floorpuzzles'])){ 
          
    $sql="SELECT  ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" FloorPuzzles .  "%'"
          
    $result=mysql_query($sql); 
          while(
    $row=mysql_fetch_array($result)){ 
                  
    $Name  =$row['Name'];
                  
    $ID  =$row['ID']; 
                  
    $Description  =$row['Description'];  
          echo
    " <div class=\"box\">";
          echo
    " <h1>$Name</h1>";
          echo
    "<div class=\"floorbox\"><a href=\"?$ID\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"small\"></a></div>";
          echo
    " <h2>$Description</h2>";
          echo
    " </div>";
    }
    }
        
    ?> 

    <?php
          
    if(isset($_GET['AnotherCategory'])){ 
          
    $sql="SELECT  ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" AnotherCategory .  "%'"
          
    $result=mysql_query($sql); 
          while(
    $row=mysql_fetch_array($result)){ 
                  
    $Name  =$row['Name'];
                  
    $ID  =$row['ID']; 
                  
    $Description  =$row['Description'];  
          echo
    " <div class=\"box\">";
          echo
    " <h1>$Name</h1>";
          echo
    "    <div class=\"floorbox\"><a href=\"?$ID\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"small\"></a></div>";
          echo
    " <h2>$Description</h2>";
          echo
    " </div>";
    }
    }
    ?>

    <?php
          
    if(isset($_GET['$ID'])){ 
          
    $sql="SELECT  ID, Name, Tags, Description, Category FROM products WHERE ID LIKE '%" $ID .  "%'"
          
    $result=mysql_query($sql); 
          while(
    $row=mysql_fetch_array($result)){ 
                  
    $Name  =$row['Name'];
                  
    $ID  =$row['ID']; 
                  
    $Description  =$row['Description'];  
          echo
    " <div class=\"box\">";
          echo
    " <h1>$Name</h1>";
          echo
    " <div class=\"floorbox\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"big\"></div>";
          echo
    " <h2>$Description</h2>";
          echo
    " </div>";
    }
    }
    ?>
    The following code from the above is what I've been working on to attempt to display the single product the viewer selects:

    PHP Code:
    <?php
          
    if(isset($_GET['$ID'])){ 
          
    $sql="SELECT  ID, Name, Tags, Description, Category FROM products WHERE ID LIKE '%" $ID .  "%'"
          
    $result=mysql_query($sql); 
          while(
    $row=mysql_fetch_array($result)){ 
                  
    $Name  =$row['Name'];
                  
    $ID  =$row['ID']; 
                  
    $Description  =$row['Description'];  
          echo
    " <div class=\"box\">";
          echo
    " <h1>$Name</h1>";
          echo
    " <div class=\"floorbox\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"big\"></div>";
          echo
    " <h2>$Description</h2>";
          echo
    " </div>";
    }
    }
    ?>
    Thanks in advance for any assistance.

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,559
    Thanks
    76
    Thanked 105 Times in 104 Posts
    So what you are asking is that you have a whole page of products listed and when a user clicks on one of them, it takes them to the product page for that item?
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #3
    New Coder
    Join Date
    Aug 2009
    Location
    public_html/cgi-bin/
    Posts
    91
    Thanks
    14
    Thanked 1 Time in 1 Post
    Hello Charlie

    If you are only referring to these variables once, you may as well scrap them all together and just directly take them from the row. I can't see why the code wouldn't work to be honest.

    PHP Code:
    <?php 
          
    if(isset($_GET['$ID'])){  
                
    $sql="SELECT  ID, Name, Tags, Description, Category FROM products WHERE ID LIKE '%" $ID .  "%'";  
                
    $result=mysql_query($sql);  
                while(
    $row=mysql_fetch_array($result)) {  
                      echo  
    "<div class=\"box\">"
                      echo 
    "<h1>".$row['Name']."</h1>"
                      echo 
    "<div class=\"floorbox\"><img src=\"images/products/catalogue/big/floorpuzzles/".$row['ID'].".jpg\" class=\"big\"></div>"
                      echo 
    "<h2>".$row['Description']."</h2>"
                      echo 
    "</div>"
                } 
          } 
    ?>
    Try that out and let me know what happens.

    Kind Regards
    Owen Ayres

  • #4
    New Coder
    Join Date
    Oct 2008
    Posts
    38
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by myfayt View Post
    So what you are asking is that you have a whole page of products listed and when a user clicks on one of them, it takes them to the product page for that item?
    That's correct myfayt. Here is the the regular page that isn't connected to a DB but shows how I wish for it to function.

    As far as the database version goes, it shows the page of the link above which is correct, but on clicking the link to the more descriptive page for the selected product, it returns with a blank page.

    Thank you for your suggestion Owener94, but it still has the same outcome as before


  •  

    Posting Permissions

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