jeffery1493 Posted November 15, 2009 Share Posted November 15, 2009 Hi All, Does anybody know of, or have seen online a code block for a simple online PHP list/form tied to a MYSQL table? Basically all I want to do is create a Christmas list online. I don't want any bells and whistles that will confuse the fam.....they are very low tech......... just a straight row of fields down the page linked to a MYSQL table: record, record, record, maybe 2 + columns (name, item, and how much they want it 1-5) and an update button. I looked for quite awhile but most everything is vast overkill. Link to comment https://forums.phpfreaks.com/topic/181566-looking-for-code-simple-php-online-updateable-list/ Share on other sites More sharing options...
trq Posted November 15, 2009 Share Posted November 15, 2009 Why not write one yourself? Sounds like a 10 minute job. Link to comment https://forums.phpfreaks.com/topic/181566-looking-for-code-simple-php-online-updateable-list/#findComment-957684 Share on other sites More sharing options...
jeffery1493 Posted November 15, 2009 Author Share Posted November 15, 2009 Maybe for you! ; )- I just asked if someone had seen any online- I'm not asking anybody to do it for me. Link to comment https://forums.phpfreaks.com/topic/181566-looking-for-code-simple-php-online-updateable-list/#findComment-957686 Share on other sites More sharing options...
jeffery1493 Posted November 15, 2009 Author Share Posted November 15, 2009 Ha hahaaa...... once again I rank first in my searches. This always happens! http://www.google.com/search?hl=en&client=firefox-a&channel=s&rls=org.mozilla%3Aen-US%3Aofficial&hs=xYT&q=online+php+list+updateable&aq=f&oq=&aqi= Link to comment https://forums.phpfreaks.com/topic/181566-looking-for-code-simple-php-online-updateable-list/#findComment-957692 Share on other sites More sharing options...
jeffery1493 Posted November 15, 2009 Author Share Posted November 15, 2009 Okay.... I think this is what I wanted: Pull selected fields, all data existing in single table, and display online as editable form (display.php) <?php // connect to the database mysql_connect(hostname,username,password); // select the database mysql_select_db(database) or die("Unable to select database"); // run the query and put the results in an array variable called $result $result = mysql_query("SELECT * FROM table ORDER BY course"); // start a counter in order to number the input fields for each record $i = 0; // open a form print "<form name='namestoupdate' method='post' action='update.php'>\n"; // start a loop to print all of the courses with their book information // the mysql_fetch_array function puts each record into an array. each time it is called, it moves the array counter up until there are no more records left while ($books = mysql_fetch_array($result)) { // assuming you have three important columns (the index (id), the course name (course), and the book info (bookinfo)) // start displaying the info; the most important part is to make the name an array (notice bookinfo[$i]) print "<input type='hidden' name='id[$i]' value='{$books['id']}' />"; print "<p>{$books['course']}: <input type='text' size='40' name='bookinfo[$i]' value='{$books['bookinfo']}' /></p>\n"; // add 1 to the count, close the loop, close the form, and the mysql connection ++$i; } print "<input type='submit' value='submit' />"; print "</form>"; mysql_close(); ?> And then update routine (referred to as: update.php) <?php // connect to the database and select the correct database mysql_connect(hostname,username,password); mysql_select_db(database) or die("Unable to select database"); // find out how many records there are to update $size = count($_POST['bookinfo']); // start a loop in order to update each record $i = 0; while ($i < $size) { // define each variable $bookinfo= $_POST['bookinfo'][$i]; $id = $_POST['id'][$i]; // do the update and print out some info just to provide some visual feedback // you might need to remove the single quotes around the field names, for example bookinfo = '$bookinfo' instead of `bookinfo` = '$bookinfo' $query = "UPDATE table SET `bookinfo` = '$bookinfo' WHERE `id` = '$id' LIMIT 1"; mysql_query($query) or die ("Error in query: $query"); print "$bookinfo<br /><br /><em>Updated!</em><br /><br />"; ++$i; } mysql_close(); ?> Well thats the basics, for those of us who are PHP impaired. I'd say, "Don't quit your day job, Jeff", except its already been outsourced, lol. Link to comment https://forums.phpfreaks.com/topic/181566-looking-for-code-simple-php-online-updateable-list/#findComment-957718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.