andrewgarn Posted April 30, 2008 Share Posted April 30, 2008 Hi I'm trying to create a mySQL admin type page. The page needs to retrieve the values from a column in mySQL and place them into a drop down box. The user then selects one of the values and clicks a button to run a query, which will then submit / delete etc I have this so far: <? $result = mysql_query("select username from officials"); if (mysql_num_rows($result) > 0) { print "<select name=\"select_name\">"; while ($row = mysql_fetch_array($result)) { print "<option value=\"" . $row['username'] . "\">" . $row['username'] . "</option>\n"; } print "</select>"; } ?> This loads the usernames from the table and puts them into a drop down box. But what I dont know how to do is then run a query? Help would be appreciated Link to comment https://forums.phpfreaks.com/topic/103588-retrieving-mysql-row-information-then-using-it-in-a-query/ Share on other sites More sharing options...
benphp Posted April 30, 2008 Share Posted April 30, 2008 I'm not sure if what you're asking is this simple: print "<form action=mysql.php method=post>"; $result = mysql_query("select username from officials"); if (mysql_num_rows($result) > 0) { print "<select name=\"select_name\">"; while ($row = mysql_fetch_array($result)) { print "<option value=\"" . $row['username'] . "\">" . $row['username'] . "</option>\n"; } print "</select>"; } print "<input type=submit>"; print "</form>"; Link to comment https://forums.phpfreaks.com/topic/103588-retrieving-mysql-row-information-then-using-it-in-a-query/#findComment-530458 Share on other sites More sharing options...
andrewgarn Posted April 30, 2008 Author Share Posted April 30, 2008 Thank you for the quick reply That added a submit query button (how does it know its submit query?) which would then presumably feed the selected variable to the next page? How would i get the page to feed the variable back into itself and run the query without loading a page, ie if it was a select query return the results onto the screen into boxes which could be edited and saved back to the database? I also want to have multiple drop down boxes leading to multiple queries so that the user can add delete / add entries as well as searching and modifying all on one page. I was thinking of something like using divs, and a javascript hide/block feature to keep it simple? Link to comment https://forums.phpfreaks.com/topic/103588-retrieving-mysql-row-information-then-using-it-in-a-query/#findComment-530472 Share on other sites More sharing options...
benphp Posted April 30, 2008 Share Posted April 30, 2008 The only way to get dynamic content without reloading the page is by using javascript. Otherwise, you could set the form action to the pagename.php and make it refresh using the new variable. For multiple buttons, you can name them btnAdd, btnUpdate, btnDelete, then set the form action to an all-SQL php page that runs SQL based on the button pressed. FormPage.php > SQLPage.php > FormPage.php(results) and use header() to redirect them from the SQLPage.php. Link to comment https://forums.phpfreaks.com/topic/103588-retrieving-mysql-row-information-then-using-it-in-a-query/#findComment-530503 Share on other sites More sharing options...
andrewgarn Posted April 30, 2008 Author Share Posted April 30, 2008 So, the mysql.php the form was submitting to would have something like this on it? $username = $_POST['username']; then: <?php if (isset($_POST['submit'])) { do something? } then how would it feed the information back to the original page? The only current link I have between pages is a session check to see if the user has gone through the login page and not directly to the php Link to comment https://forums.phpfreaks.com/topic/103588-retrieving-mysql-row-information-then-using-it-in-a-query/#findComment-530549 Share on other sites More sharing options...
947740 Posted April 30, 2008 Share Posted April 30, 2008 Actually, you can use AJAX for dynamic content too. $username = $_POST['username']; then: <?php if (isset($_POST['submit'])) { do something? } You would want to check if the form is submitted before assigning a variable a value from the form. Link to comment https://forums.phpfreaks.com/topic/103588-retrieving-mysql-row-information-then-using-it-in-a-query/#findComment-530551 Share on other sites More sharing options...
andrewgarn Posted April 30, 2008 Author Share Posted April 30, 2008 this to check for submit? if ( empty( $username ) ) { include 'database.php'; } else { and how will the query result be fed back to database.php? Link to comment https://forums.phpfreaks.com/topic/103588-retrieving-mysql-row-information-then-using-it-in-a-query/#findComment-530559 Share on other sites More sharing options...
andrewgarn Posted April 30, 2008 Author Share Posted April 30, 2008 Also how would I change the button name? //print "<form action=\"$self\" method=\"post\">"; print "<form action=mysql.php method=post>"; $result = mysql_query("select username from officials"); if (mysql_num_rows($result) > 0) { print "<select name=\"select_name\">"; while ($row = mysql_fetch_array($result)) { print "<option value=\"" . $row['username'] . "\">" . $row['username'] . "</option>\n"; } print "</select>"; } print "<input type=submit>"; print "</form>"; Link to comment https://forums.phpfreaks.com/topic/103588-retrieving-mysql-row-information-then-using-it-in-a-query/#findComment-530570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.