xwishmasterx Posted December 29, 2008 Share Posted December 29, 2008 Hello I have a very simple question. I need a button to change a single value in a table: How should the code look, if I want to change a value to 1 (without the database connection)? Link to comment https://forums.phpfreaks.com/topic/138748-simple-button-for-changing-a-single-table-value/ Share on other sites More sharing options...
UpcomingPhpDev Posted December 29, 2008 Share Posted December 29, 2008 I think you need Js for the way you wrote the question. Php would do it, But it would have to refresh the page Link to comment https://forums.phpfreaks.com/topic/138748-simple-button-for-changing-a-single-table-value/#findComment-725439 Share on other sites More sharing options...
xwishmasterx Posted December 29, 2008 Author Share Posted December 29, 2008 refreshing the page will not be a problem. Link to comment https://forums.phpfreaks.com/topic/138748-simple-button-for-changing-a-single-table-value/#findComment-725442 Share on other sites More sharing options...
Zane Posted December 29, 2008 Share Posted December 29, 2008 function changeCell(o, n) { o = document.getElementById(o) o.innerHTML = n; } </pre> <table> </table> <br><inut type="'button'" name="'change'" value="'Change" cell onclick="changeCell('2a', 'New Value')"></inu Link to comment https://forums.phpfreaks.com/topic/138748-simple-button-for-changing-a-single-table-value/#findComment-725455 Share on other sites More sharing options...
xwishmasterx Posted December 29, 2008 Author Share Posted December 29, 2008 I mean changing the value of a mysql database table. A single cell value needs to be changed to 1 with the push of a button. I am a noob at php, but it can't be to hard....any ideas of a code? Link to comment https://forums.phpfreaks.com/topic/138748-simple-button-for-changing-a-single-table-value/#findComment-725528 Share on other sites More sharing options...
Zane Posted December 29, 2008 Share Posted December 29, 2008 I would use AJAX myself, if of course you're going to have a lot of these buttons. function startAJAX() { try { xmlhttp = new XMLHttpRequest(); } catch(e) { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } } return xmlhttp; } function action(x, target) { var ajax = startAJAX(); var url = "update.php?id=" + x; ajax.open('GET', url); ajax.onreadystatechange = function() { if(ajax.readyState == 4) { target.value= "1"; } } // ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajax.send(null); } then have update.php do your updating and return the update, based on $_GET['id'] then make your buttons Link to comment https://forums.phpfreaks.com/topic/138748-simple-button-for-changing-a-single-table-value/#findComment-725610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.