Jump to content


Photo

POSTING PROBLEM


  • Please log in to reply
2 replies to this topic

#1 Wstar

Wstar
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 07 September 2006 - 07:26 PM

Alright, I'm new to these forums so I hope I can explain my problem right.

WHAT I WANT is a table that displays information gathered from a database.  Each item in the table can be clicked on to edit the item. 

Each item is the database has a product_id and prodcut_name.  The table is generated by the following code.

          <table class="sort-table" id="table-1" cellspacing="0" align="center">
	        <col style="text-align: center" />
	        <col style="text-align: left" />
	        <thead>
		      <tr>
			    <td>ID</td>
			    <td>Product</td>
		      </tr>
	        </thead>
	      <tbody>
	        <?php
	          //  open  connection to the server
              @mysql_pconnect("","","")
                or die("Could not connect to MySQL server!");
  
              //open connection to the database
              @mysql_select_db("")
                or die("Could not select database!");
                 
              //  start inserting into database 
              $products_table__query = "SELECT products_id, products_name
                                        FROM products_description
                                        ORDER BY products_id";

             $products_table = mysql_query($products_table__query);
                 
               
             for($count=0; $count <= (mysql_numrows($products_table)-1); $count++){
               echo '<tr>';
             ?>
               <td><A HREF="reviews.php"><?php echo mysql_result($products_table, $count, "products_id") ?></A></td>
               <td><A HREF="reviews.php"><?php echo mysql_result($products_table, $count, "products_name") ?></A></td>
            <?php
               echo '</tr>';
             }
           ?>
         </tbody>
       </table>

When the user clicks on a product name, php file loads again and gives the user fields to type in and edit the product.

What I'm having trouble with is knowing what product link the user clicked on.  When the file loads again, all he variables are reset.

I've tryed onlclick="" and had no luck.  What else can I do?
Thank you for any information you can give!

|Wstar|

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 07 September 2006 - 07:37 PM

You could pass it in the url...

So have the code from the db generate links like this...

<a href="reviews.php?id=1">Product 1</a>
<a href="reviews.php?id=2">Product 2</a>

Then have you next page (reviews.php) do another select from the database based on the $_GET['id']and propogate the forms accordingly.

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 Wstar

Wstar
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 08 September 2006 - 02:43 PM

Thank you!  I've always wondered why and how you did that witht he url.  Thanks for the help, works perfectly!

|Wstar|




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users