cfgcjm Posted January 22, 2008 Share Posted January 22, 2008 I need to create a web based interface to update fields in a database. What i want it to do is have 2 combo boxes the first which will contain both the last name (last_name is the field name in db) a comma then the first name (first_name is the field name in db). In the other combo box will be either a yes or a no (which will read from the db from the field client). The trick about this part is that the database has a 0 or 1, 0=false 1=true...obviously. What i would like is for the yes/no field to auto update if the choice in the other combo box changes to it's current value in the database. I want the user to be able to change the yes/no field then click a 'Go' button to post the change to the database in the row of the persons name as displayed in the other database. I know that's kinda confusing, but it seems like a simple concept to me i just have no clue how to do it Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/ Share on other sites More sharing options...
btherl Posted January 22, 2008 Share Posted January 22, 2008 Is there more than one thing you want there? It's a little unclear. 1. If the database changes, then the form should be updated 2. If the user edits the form, then the change should be posted to the database after clicking the Go button. Is that right, or is it just #2? Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-445829 Share on other sites More sharing options...
cfgcjm Posted January 22, 2008 Author Share Posted January 22, 2008 I believe it is both 1 & 2. 2 for sure 1 - i believe so if your saying that if you make a change through the form it will be reflected in the form's data after a reload (or maybe not a reload if there's a way to do it realtime) Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-445836 Share on other sites More sharing options...
cfgcjm Posted January 22, 2008 Author Share Posted January 22, 2008 any ideas? ??? Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446143 Share on other sites More sharing options...
revraz Posted January 22, 2008 Share Posted January 22, 2008 Plenty of ideas. Start writing the code on how you explain it and ask where you need help. Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446150 Share on other sites More sharing options...
cfgcjm Posted January 22, 2008 Author Share Posted January 22, 2008 Ok, this is what i have...I have the two combo boxes and they are reading from the db but i can only get the last result of the loop to display in the boxes... <?php $session = mysql_connect("localhost", "xxx", "xxx"); mysql_select_db("xxx"); $query = "select * from users"; $result = mysql_query($query); if ( !$result ) { echo ( "<P>Error doing a select: " . mysql_error() . "</P>" ); } else { // succesful read - how many records ? print (" Number of rows read " . mysql_num_rows($result)."</br>"); $rr=mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr // loop over rows, counts the total number and prints them for ($i=0; $i<$rr; $i++) { $nextresult = mysql_fetch_array($result); $username = $nextresult['username']; $client = $nextresult['client']; print ($username."<br>"); print ($client."<br>"); } } // close the connection mysql_close($session); ?> <html> <head> </head> <body> <form name="form1" method="post" action=""> <select name="name" id="name"> <option><?php print($username); ?></option> <option selected "$user_input"></option> </select> <select name="client" id="client"> <option><?php print($client); ?></option> <option selected "$user_input"></option> </select> <input name="change" type="button" value="Change"></form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446165 Share on other sites More sharing options...
revraz Posted January 22, 2008 Share Posted January 22, 2008 Use a while loop to loop through the array. Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446171 Share on other sites More sharing options...
cfgcjm Posted January 22, 2008 Author Share Posted January 22, 2008 I'm having trouble with this while loop, i can get it to loop the proper number of times but in the combo box it just displays the last result a number of times <?php $session = mysql_connect("localhost", "xxx", "xxx"); mysql_select_db("xxx"); $query = "select * from users"; $result = mysql_query($query); if ( !$result ) { echo ( "<P>Error doing a select: " . mysql_error() . "</P>" ); } else { // succesful read - how many records ? print (" Number of rows read " . mysql_num_rows($result)."</br>"); $rr=mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr // loop over rows, counts the total number and prints them for ($i=0; $i<$rr; $i++) { $nextresult = mysql_fetch_array($result); $username = $nextresult['username']; $client = $nextresult['client']; print ($username."<br>"); print ($client."<br>"); } } // close the connection mysql_close($session); ?> <html> <head> </head> <body> <form name="form1" method="post" action=""> <select name="name" id="name"> <?php $j=0; while($j<$rr){ echo "<option>{$nextresult['username']}</option>"; $j++; }?> </select> <select name="client" id="client"> <option><?php print($client); ?></option> <option selected "$user_input"></option> </select> <input name="change" type="button" value="Change"></form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446231 Share on other sites More sharing options...
cfgcjm Posted January 22, 2008 Author Share Posted January 22, 2008 ok I've found a way to get the proper readouts in the both the name and client combo boxes but i've looked around and can't find anthing on auto updating. I want the user to select a persons name from the name box and the client box to be auto updated to it's proper value any ideas? current code: <?php $session = mysql_connect("localhost", "xxxx", "xxxx"); mysql_select_db("xxxx"); $query = "select * from users"; $result = mysql_query($query); if ( !$result ) { echo ( "<P>Error doing a select: " . mysql_error() . "</P>" ); } else { // succesful read - how many records ? print (" Number of rows read " . mysql_num_rows($result)."</br>"); $rr=mysql_num_rows($result); //this is calculating the number of rows read from database and puts it into variable rr // loop over rows, counts the total number and prints them $user = array(); // define array students for ($i=0; $i<$rr; $i++) { $nextresult = mysql_fetch_array($result); $fname = $nextresult['first_name']; $lname = $nextresult['last_name']; $journal = $nextresult['client']; $username="$lname, $fname"; $user[$i] = $username; $client[$i]=$journal; } } mysql_close($session); sort($user); ?> <html> <head> </head> <body> <form name="form" method="post" action=""> <select name="name" id="name"> <?php foreach ( $user as $user_name ) { echo "<option>{$user_name}</option>"; } ?> </select> <select name="client" id="client"> <option> <?php foreach ( $client as $yesno ) { if($yesno==1){ echo "<option>Yes</option>";} if($yesno==0){ echo "<option>No</option>";} } ?> </option> <option selected "$user_input"></option> </select> <input name="change" type="button" value="Change"></form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446289 Share on other sites More sharing options...
cfgcjm Posted January 22, 2008 Author Share Posted January 22, 2008 ...and maybe instead of a combo box for the yes no section, radio buttons? thought? Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446308 Share on other sites More sharing options...
cfgcjm Posted January 23, 2008 Author Share Posted January 23, 2008 Anyone? I'm really stuck. I need a way for either another combo box or radio buttons to be automatically updated when the main combo box is updated (containing names) to their appropriate values in the db. Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446492 Share on other sites More sharing options...
Ken2k7 Posted January 23, 2008 Share Posted January 23, 2008 Anyone? I'm really stuck. I need a way for either another combo box or radio buttons to be automatically updated when the main combo box is updated (containing names) to their appropriate values in the db. Okay I get the updating the database part, but what in the world is ^ that supposed to say? ??? Automatically update to what? Can you lay out 2 examples please? One where the radio buttons automatically update and one where it's not. Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446494 Share on other sites More sharing options...
cfgcjm Posted January 23, 2008 Author Share Posted January 23, 2008 Ok i am looking to have one of the following setups: The values in the combo box on the left and the yes/no in either object on the left are stored in the database they are being read from. What i want to happen is if a user were to change the combo box on the left the object on the right would update to reflect it's value in the database. I hope that helps... Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446500 Share on other sites More sharing options...
revraz Posted January 23, 2008 Share Posted January 23, 2008 You are talking about changing things on the fly, you can't do that with PHP, you'll need to use Javascript or Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-446540 Share on other sites More sharing options...
btherl Posted January 25, 2008 Share Posted January 25, 2008 Well, PHP can be involved. Revraz is saying it can't be done with pure php. What you can do is have javascript call a php script to do the update, without loading a new page. That kind of idea is called Ajax. Ajax is too complex to explain here, so if you're serious about providing that kind of functionality, I would do some tutorials. It won't take long before you can do what you're trying to do (trigger a database update based on an action such as button click or change of a combo box value. Quote Link to comment https://forums.phpfreaks.com/topic/87157-interface-to-update-database/#findComment-448444 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.