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
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>';
?>

Link to comment
Share on other sites

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>';
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.