Ok...I am making a CMS and I am making a script that is sort of an alternative to phpmyadmin...except all mine does is ask them what fields they want in a certain table.
here:
<?
switch($pg){
default:
echo "Here is where you setup you database:<br><br>",
"<form method=\"post\" action=\"test.php?pg=01\">",
"Table Name: <input type=\"text\" name=\"tablename\" size=\"15\">",
"<br><br>",
"How many fields will be in your database? <input type=\"text\" name=\"fieldnum\" size=\"4\"><br><br>",
"<input type=\"submit\" name=\"submit\" value=\"Continue...\">",
"</form>";
break;
case "01":
echo
"<b>Table Name:</b> ",
"<u>",
$_POST['tablename'],
"</u>",
"<br><br>",
"<b>Number of Fields:</b> ",
"<u>",
$_POST['fieldnum'],
"</u>",
"<form method=\"post\" action=\"test.php?pg=02\">",
"<table border=\"1\" cellspacing=\"0\">",
"<th>Field Name:</th><th>Field Type:</th><th>Char Limit:</th>";
$i=0;
$num="0";
while($i < $_POST['fieldnum']){
echo "<tr>",
"<td width=\"1\">",
"<input type=\"text\" name=\"",
$num,
"field\">",
"</td>",
"<td width=\"1\">",
"<select name=\"",
$num,
"type\">",
"<option value=\"INT\">INT</option>",
"<option value=\"VARCHAR\">VARCHAR</option>",
"<option value=\"TEXT\">TEXT</option>",
"<option value=\"LONGTEXT\">LONGTEXT</option>",
"</select>",
"</td>",
"<td width=\"1\">",
"<input type=\"text\" name=\"",
$num,
"limit\">",
"<input type=\"hidden\" name=\"",
$num,
"number\" value=\"",
$num,
"\">",
"</td></tr>";
$num++;
$i++;
}
echo "<input type=\"hidden\" name=\"field_num\" value=\"",
$_POST['fieldnum'],
"\">";
echo "<input type=\"hidden\" name=\"table_name\" value=\"",
$_POST['tablename'],
"\">";
echo "</table><br><input type=\"submit\" name=\"submit\" value=\"Continue...\"></form>";
break;
case "02":
$f_tablename = $_POST['table_name'];
$f_fieldnum = $_POST['field_num'];
echo "<table border=\"1\" cellspacing=\"0\">",
"<th>Field Name:</th><th>Field Type:</th><th>Char Limit:</th>";
$num2="0";
$i=0;
while($i < $f_fieldnum){
echo "<tr><td>",
$num2,
"field</td><td>",
$num2,
"type</td><td>",
$num2,
"limit</td></tr>";
$num2++;
$i++;
}
break;
}
?>
Okay here's a break-down of the script....
test.php
- asks what the table will be called
- and the number of fields
test.php?id=01
- prints a table containing X number of fields
- asks for field name, type, and if neccasary CHAR limit
test.php?id=02
- this is where I need help...
since the number of fields on ?id=01 is dynamic...I ran the while $i is less than the number of fields again...just to get the number part of the name...
but what I get as an output is:
name | type | charlimit
##field | ##type | ##limit
it is printing type...and I dont want that...what I want it to do is combine whatever # the while statment returns, and either field,type,or limit depending on what field, and i need that to be one variable.
please help!?