Jump to content

Form to update table results


hoponhiggo

Recommended Posts

Hi Guys.

 

I have some code which displays the rows of a database table in a html table on my webpage:

 

<?php//to display image from source$dir = "360_covers";echo '<table>';echo '<tr><th>Title</th><th>Cover</th><th>comment</th></tr>';$result = mysql_query("SELECT * FROM xbox_games order by gametitle");while ($row = mysql_fetch_assoc($result)) {    echo "<tr><td>{$row['gametitle']}</td><td><img src=\"$dir/{$row['cover']}\" width='38' height='38'></td><td>{$row['cover']}</td></tr>";}//close out tableecho '</table>';?>

 

What i want to do now is add a form, possibly at the end of each row of the html table, which will allow a session user to update that record.

 

Can anybody advise on the best way to do this?

Link to comment
https://forums.phpfreaks.com/topic/236191-form-to-update-table-results/
Share on other sites

Cleaned up the code for anybody who wants to help

<?php
//to display image from source
$dir = "360_covers";
echo '<table>';
echo '<tr><th>Title</th><th>Cover</th><th>comment</th></tr>';
$result = mysql_query("SELECT * FROM xbox_games order by gametitle");
while ($row = mysql_fetch_assoc($result)){
echo "<tr><td>{$row['gametitle']}</td><td><img src=\"$dir/{$row['cover']}\" width='38' height='38'></td><td>{$row['cover']}</td></tr>";
}
//close out table
echo '</table>';
?>

Why not create a link at the end, which will point them to an edit page. Much cleaner and easier.

<?php
//to display image from source
$dir = "360_covers";
echo '<table>';
echo '<tr><th>Title</th><th>Cover</th><th>comment</th><th>Actions</th></tr>';
$result = mysql_query("SELECT * FROM xbox_games order by gametitle");
while ($row = mysql_fetch_assoc($result)){
echo "<tr><td>{$row['gametitle']}</td><td><img src=\"$dir/{$row['cover']}\" width='38' height='38'></td><td>{$row['cover']}</td><td><a href=\"edit.php?id={$row['id']}\">Edit</a> | <a href=\"delete.php?id={$row['id']}\">Delete</a></tr>";
}
//close out table
echo '</table>';
?>

Based on what i described earlier - this would work (on the premise that i could restrict the fields that can be updated to the 'comment' field only)

 

But in hindsight, i think i need to have another look at what i am ultimately trying to achieve

 

Thank you very much for you help though. Im sure this method will come in handy at some point

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.