Results 1 to 4 of 4

Thread: Passing values to another PHP page

  1. #1

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Passing values to another PHP page

    I have a listProducts.php page that querys a table in my phpMyAdmin database. It takes the information and puts it out onto the page using a while loop. Here is the code:

    PHP Code:
    <?php 
    include("db.inc.php"); 

    $db=open_db("test");
    $sql="Select image, name, description, price from ss02_products";
    $result=query_db($sql);
    ?>

    <table summary="">
    <tr>
    <th></th><th>Name</th><th>Description</th><th>Price</th>
    </tr>
    <?php while($row get_row_array($result)){ ?>
    <tr>
    <td><a href="productInfo.php"><img alt="<? echo $row['name'];?>" src="<? echo $row['image'];?>" width="200" height="200"/></a></td>
    <td><a href="productInfo.php"><? echo $row['name'];?></a></td>
    <td><? echo $row['description'];?> </td>
    <td>$<? echo $row['price'];?> </td>
    </tr>
    <?php ?>
    </table>
    My question is this: How do I pass a value to another PHP page that way I can have it dynamically bring up just that product info, instead of putting them all on the page. Its kinda like a link to a more detail product info page.

    I was thinking that I need some sort of count variable that I incrememnt each time through the loop that corresponds to the productID in my phpMyAdmin table. How would I pass this variable to another PHP page which will then use it in an SQL statement that will get the info for that productID from the table in the Database. How would I put it into an HREF tag to send it to that page?

    Something like

    <a href="productInfo.php?index=<?php echo $i++ ?>" > Some product<a/>

    What do you think? SHould i do it this way or should I possible try something with Smarty or a Session or cookie?

    Thanks for the help.
    Otaku no Kamisama – God of the Geeks

  2. #2

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Re: Passing values to another PHP page

    I got this working. What do you think?

    Here is my listProducts.php which just lists each product and a short description in a table.
    PHP Code:
    <?php 
    include("db.inc.php"); 

    $db=open_db("test");
    $sql="Select image, name, shortdescription, price from ss02_products";
    $result=query_db($sql);
    $i=1;
    ?>

    <table summary="">
    <tr>
    <th></th><th>Name</th><th>Description</th><th>Price</th>
    </tr>
    <?php while($row get_row_array($result)){ ?>
    <tr>
    <td><img alt="<? echo $row['name'];?>" src="<? echo $row['image'];?>" width="200" height="200"/></td>
    <td><a href="productInfo.php?id=<?php echo $i++ ?>"><? echo $row['name'];?></a></td>
    <td><? echo $row['shortdescription'];?> </td>
    <td>$<? echo $row['price'];?> </td>
    </tr>
    <?php ?>
    </table>
    Here is my productInfo.php page that gets an index, then querys the table to get that products info.

    PHP Code:
    <?php 
    include("db.inc.php");
    $index $_SERVER['QUERY_STRING'];
    $db=open_db("test");
    $sql="Select image, name, description, price from ss02_products where $index";
    $result=query_db($sql);
    $row get_row_array($result);
    ?>

    <html> 
    <head> 
    <title><? echo $row['name'];?></title> 
    </head> 
    <body> 
    <table summary="">
    <tr>
    <th></th><th>Name</th><th>Description</th><th>Price</th>
    </tr>
    <tr>
    <td><img alt="<? echo $row['name'];?>" src="<? echo $row['image'];?>" width="200" height="200"/></td>
    <td><a href="productInfo.php?index=<?php echo $i++ ?>"><? echo $row['name'];?></a></td>
    <td><? echo $row['description'];?> </td>
    <td>$<? echo $row['price'];?> </td>
    </tr>
    </table>

    </body> 
    </html>
    Otaku no Kamisama – God of the Geeks

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Passing values to another PHP page

    Does each produce have an ID in the table. If so, add this to the feilds in your select querry and append that to the URL.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Passing values to another PHP page

    By the way, phpMyAdmin is a frontend for MySQL, so it's a "MySQL database"

Posting Permissions

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



Click Here to Expand Forum to Full Width