hoponhiggo Posted May 12, 2011 Share Posted May 12, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/236191-form-to-update-table-results/ Share on other sites More sharing options...
jonsjava Posted May 12, 2011 Share Posted May 12, 2011 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/236191-form-to-update-table-results/#findComment-1214347 Share on other sites More sharing options...
hoponhiggo Posted May 12, 2011 Author Share Posted May 12, 2011 Sorry, dont know why the code came out all on the one line. Thanks jonsjava Quote Link to comment https://forums.phpfreaks.com/topic/236191-form-to-update-table-results/#findComment-1214352 Share on other sites More sharing options...
jonsjava Posted May 12, 2011 Share Posted May 12, 2011 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/236191-form-to-update-table-results/#findComment-1214358 Share on other sites More sharing options...
hoponhiggo Posted May 12, 2011 Author Share Posted May 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236191-form-to-update-table-results/#findComment-1214379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.