Jump to content

Php Table


iRush

Recommended Posts

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.