开发者

How can I list all mySQL records and provide an update button for each?

My first post, how exciting!! I just can't seem to figure this out, I am pulling customer records from a specific table and listing all the content (name, payables, dates, ect) in an html table. I wanted to include an 'update record' button next to each row but I'm not sure the best way to do it. I have experimented with creating a button within the foreach loop that echos the data and naming the buttons after one of the row values to identify it. I am sure there is a better way of doing this!

Here's what I have (I am just getting my feet wet with serious php):

while($row = mysql_fetch_row($result)) {

        echo '<tr>';
        foreach($row as $cell) {

            echo "\n<td>$cell</td>";
    }

    echo '<td><form method="POST" action="userupdate.php">
    <input name="update" type="button" value="Update 开发者_StackOverflowRecord" />
    <input type="hidden" name="'.$row[1].'" /></form></td></tr>';
    echo "\n\n";
 }

but now I cant figure out how to call the hidden input name. I am sure that this is about the stupidest way to accomplish this (don't be too hard on me!), but I need some help! Maybe there is a better way of doing this other than the button.

There are at least 200 rows in the table.


Change the name attribute to something fixed, like 'row_id'. Then, set the value to $row[1]... this can then be accessed like any other CGI parameter


foreach($row as $cell) {
    echo "<tr>";
    echo "\n<td>$cell['name']</td>"; //this will be all other details you want to show
    echo "\n<td><a href="update.php?id=<?php print $cell['id']; ?>"</td>";
    echo "</tr>";
}

in your update.php file

<?php

$id = floor($_GET['id']);

if($id > 0)
{
    //do your update query and other stmts
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜