iRush Posted October 23, 2011 Share Posted October 23, 2011 I need some help on just making a plain and simple php table with rows and columns..then i need to beable to add in data from a text box form and submit button. So say i type in the text box test1 then it should put it in the table at row 1 column 1. Any ideas or help would be great to get me started Quote Link to comment https://forums.phpfreaks.com/topic/249663-php-table/ Share on other sites More sharing options...
gizmola Posted October 23, 2011 Share Posted October 23, 2011 PHP has sessions. You can store an array in a session. In order to start using sessions, you have to start them at the beginning of a script. session_start(); You can then store data to a session variable by assigning it to the $_SESSION superglobal. An html form that makes a php script it's target with method POST will have any form variables available in the $_POST superglobal. So if you had let's say an input variable named "tableinput' then you will get the value of that from: $_POST['tableinput']. So your script could do something like this: // Output form here if (isset($_POST['tableinput'])) { $_SESSION['tabledata'][] = $_POST['tableinput']; } // Output table here: foreach($_SESSION['tabledata'] as $row) { // output $row inside a tr } That is the framework for what I'd suggest. Self contained, and each time you submit, it will add an element to the session variable which will then drive the output of your table. Quote Link to comment https://forums.phpfreaks.com/topic/249663-php-table/#findComment-1281649 Share on other sites More sharing options...
iRush Posted October 23, 2011 Author Share Posted October 23, 2011 So if i post the code i already have that has a list of databases and which also contains me being able to add and remove databases from a list can you help me out as to where i should implant the code so i can do it with a table instead? Quote Link to comment https://forums.phpfreaks.com/topic/249663-php-table/#findComment-1281653 Share on other sites More sharing options...
iRush Posted October 23, 2011 Author Share Posted October 23, 2011 This is my code <?PHP // please add login and pass here// $host = "localhost"; $login = "root" ; $pass = ""; mysql_connect("$host","$login","$pass") OR DIE ("There is a problem with the system. Please notify your system administrator." .mysql_error()); //Seems in this case we can use a general call $connection = mysql_connect("$host","$login","$pass") or die(mysql_error()); $dbs = @mysql_list_dbs($connection)or die(mysql_error()); $db_list="<ul>"; $i =0; while ($i < mysql_num_rows($dbs)){ $db_names[$i] = mysql_tablename($dbs,$i); $db_list .="<li>$db_names[$i]"; $i++; } //Start Create DB// IF (isset($_POST['result'])){ $database=$_POST['database']; $sql="CREATE DATABASE $database "; $result = mysql_query($sql,$connection) or die(mysql_error()); echo "Database $database has been added"; } IF (isset($_POST['delete'])){ $db=$_POST['db']; $query=mysql_query("DROP DATABASE $db"); echo "Database $db has been deleted"; } ?> <html> <head> <title>MySQL Databases</title> </head> <body> <p><strong>Databases on localhost</strong>:</p> <? echo "$db_list"; ?> <?PHP //print_r($_POST); ?> <form action="pretask.php" method="post"> <select name="db"> <?PHP $db_list = mysql_list_dbs($connection); while ($row = mysql_fetch_object($db_list)) { //Here you are listing anything that should not be included if ($row->Database!="information_schema" && $row->Database!="mysql" && $row->Database!="phpmyadmin"){ echo "<option value=\"".$row->Database."\">".$row->Database."</option>"; } } ?> </select> <input type="submit" name="delete" value="Delete"/> </form> <form action="pretask.php" method="post"> Create Database <input type="text" name="database" /> <input type="submit" name="result" value="Create" /> </form> </body> Quote Link to comment https://forums.phpfreaks.com/topic/249663-php-table/#findComment-1281661 Share on other sites More sharing options...
iRush Posted October 24, 2011 Author Share Posted October 24, 2011 anyone have any ideas on how i would incorporate the table into my code Quote Link to comment https://forums.phpfreaks.com/topic/249663-php-table/#findComment-1281673 Share on other sites More sharing options...
Drummin Posted October 24, 2011 Share Posted October 24, 2011 Sounds like you are wanting to setup something like phpMyAdmin for creating the database table. That's going to get complicated selecting the field types etc. To Just create a table see here. http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/create-a-mysql-database-with-php.aspx or do a search for other examples. Making an interface for doing this is another matter. Quote Link to comment https://forums.phpfreaks.com/topic/249663-php-table/#findComment-1281702 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.