- Impact
- 1,768
Here is my dilemma in a nutshell: I'm trying to empty multiple tables in the same database & post the content of them all on a web page. I've spent hours trying to do this to no avail. Given, I'm not much of a programmer so the answer/solution might be simple. But I can't figure it out. Look at my code (I modded these for obvious reasons):
First page:
And page2.php:
Don't worry about "unused" vars, like $date. They'll be incorporated at a later date.
What is this script supposed to do? The first page enters table donotdelete and pulls out a list of names & the number of the highest ID in the table (using $num. It works for what I need). These are saved in var and passed on to the next page.
On the next page, I tried to use a loop to make a DB call for each table I have, using $tablenames to specify each table. The result was to have all the data from ALL tables named with $tablenames displayed on page2.php (I was then going to save the data via a hidden form element and pass it over to a page3.php). The script displays info for ONE table and will not loop.
Could anyone offer a solution?
First page:
PHP:
All items in this table:<p>
<form method=post action=page2.php>
<?
$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM donotdelete";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$x=$i+1;
$id=mysql_result($result,$i,"id");
$items=mysql_result($result,$i,"items");
echo "<INPUT TYPE=text NAME=tablenames[] value=" . $items . " SIZE=30><br>";
$i++;
}
echo "<p>Last record number in table: <INPUT TYPE=text NAME=total value=" . $num . " SIZE=10><br>";
?>
<p>
<input type=submit>
And page2.php:
PHP:
<?
$tablenames = array();
$tablenames = $_POST['tablenames'];
$total = $_POST['total'];
$i=0;
while ($i < $total) {
$table=$tablename;
$username="xxx";
$password="xxx";
$database="xxx";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM $tablenames";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$number=mysql_result($result,$i,"number");
$date=mysql_result($result,$i,"date");
$name=mysql_result($result,$i,"name");
$email=mysql_result($result,$i,"email");
echo "Email address for number " . $x .": <INPUT TYPE=text NAME=email[] value=" . $email . " SIZE=30><br>";
echo "Full name for number " . $x .": <INPUT TYPE=text NAME=name[] value=" . $name . " SIZE=30><br>";
$i++;
}
$i++;
}
?>
Don't worry about "unused" vars, like $date. They'll be incorporated at a later date.
What is this script supposed to do? The first page enters table donotdelete and pulls out a list of names & the number of the highest ID in the table (using $num. It works for what I need). These are saved in var and passed on to the next page.
On the next page, I tried to use a loop to make a DB call for each table I have, using $tablenames to specify each table. The result was to have all the data from ALL tables named with $tablenames displayed on page2.php (I was then going to save the data via a hidden form element and pass it over to a page3.php). The script displays info for ONE table and will not loop.
Could anyone offer a solution?