You would like to have the id for each row on your page?

In a form you add an

<input type="hidden" name="rowid[]" value="<?php echo 
$line["your_item_id"] ; /* insert the id column name */ ?>">

tag to each row (i.e. once in your loop). Note the brackets at rowid[]! 
That's the way how you get an array named $rowid on the next page via 
POST or GET (depending on your form method attribute).

Even better (if you would like to provide the functionality to change 
any value): you build your form using arrays for every column and put 
the rowid as array index for each array variable:

printf("<input type=\"text\" name=\"number_ordered[%d]\" value=\"%d\">",
     $line["your_item_id"],
     $line["number_ordered
   );

If you have a "read-only" table (no form) and you would like to provide 
a specific row to an edit form, you may place the following link after 
each row:

printf("<a href=\"edit_item.php?editID=%d\">edit row...</a>",
     $line["your_item_id"]
   );

HTH Steff

Jas wrote:
> Here is my problem:
> <?php
>     /* Connecting, selecting database */
>     $link = mysql_connect("localhost", "", "")
>         or die("Could not connect");
>     mysql_select_db("shopping") or die("Could not select database");
> 
>     /* Performing SQL query */
>     $query = "SELECT * FROM cart";
>     $result = mysql_query($query) or die("Query failed");
> 
>     /* Printing results in HTML */
>     print "<table width=\"100%\" border=\"0\" cellspacing=\"0\"
> cellpadding=\"3\">\n<tr>
>                                   <td colspan=\"6\"><b>Select item(s) for
> purchase</b></td>
>                                 </tr><tr>
>                                   <td width=\"3%\"
> bgcolor=\"#e4e4e4\"><u>ID</u></td>
>                                   <td width=\"10%\"
> bgcolor=\"#e4e4e4\"><u>Name</u></td>
>                                   <td width=\"15%\"
> bgcolor=\"#e4e4e4\"><u>Item Number</u></td>
>                                   <td width=\"18%\"
> bgcolor=\"#e4e4e4\"><u>Description</u></td>
>                                   <td width=\"3%\"
> bgcolor=\"#e4e4e4\"><u>Cost</u></td>
>           <td width=\"3%\" bgcolor=\"#e4e4e4\"><u>Sale</u></td>
>           <td width=\"8%\" bgcolor=\"#e4e4e4\"><u>Add Item</u></td>
>                                 </tr>";
>     while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
>         print "\t<tr>\n";
>         foreach ($line as $col_value) {
>             print "\t\t<td>$col_value</td>\n";
>         }
>         print "<td width=\"10%\"> <form name=\"add_item\" method=\"post\"
> action=\"add_item\">
> </form>
>                                     <input type=\"text\" name=\"add_num\"
> size=\"3\" maxlength=\"6\">
>                                     <input type=\"submit\" name=\"add\"
> value=\"add\"></form>
>                                   </td>\t</tr>\n";
>     }
>     print "</table>\n";
> 
>     /* Free resultset */
>     mysql_free_result($result);
> 
>     /* Closing connection */
>     mysql_close($link);
> ?>
> I use this to query the database and put the results into a form for later
> use... The problem I am having is how would I assign a unique field name for
> each entry displayed?  I am not sure how I can do this with the $col_value
> simply echoing the results onto the page, if anyone could shed some light on
> this I would appreciate it.  Thanks in advance,
> Jas
> 
> 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to