Hello, folks, and I apologize in advance if I break any rules here. This is
my first post on this list and I couldn't find any archive to review
existing posts for the answer to this question.
experience using FileMaker and Access on IIS with ASP. I finally managed to
put that experience together in this last month when I found an inexpensive
host with PHP and MySQL support.
As a test (http://test.pandorasdream.com), I am building a page with will
initially (currently) find all tables in a database and then iterate a TABLE
dump of each database table. Next, I plan to add forms to make these tables
editable, but that's another ball of wax.
Here're my questions:
I have the below code working exactly the way I want it to, but it was
through some hacking. I want to learn how I SHOULD have done it.
a) How would you change the following the automatically find the tables and
run through the iteration. I'm new at PHP, and I learn by doing, so forgive
me for not doing the RTFM thing, but I just haven't found the answer yet.
So instead I created a table called tableNames with one field, which I
personally populated with the names of all tables.
How should I have done it so that wouldn't be necessary.
b) When I grab the values of the table names using my prepared table
tableNames, I couldn't figure out how to get the TEXT value of that record.
When I put in a debug statement, all I got was a value of "Array", rather
than a name of a table. You'll see below that I hacked a work-around by
using a "foreach()" statement, which works flawlessly.
How can I grab a specific field of an array without using a foreach()?
$hostname = "localhost";
$usernamedb = "margretormaybejoe";
$passworddb = "yeahright";
$dbName = "boohoohaahaa";
$tableNamesTable = "tableNames";
/* Connecting, selecting database */
$link = mysql_connect($hostname, $usernamedb, $passworddb)
or die("Could not connect to database host.");
print "Connected successfully.<br>\n";
mysql_select_db($dbName) or die("<h1>Error</h1><p>Could not select
/* Performing SQL query */
$queryOfTableNames = "SELECT Name FROM $tableNamesTable";
$resultOfTableNamesTable = mysql_query($queryOfTableNames) or
die("<h1>Error</h1><p>Tried Query for all elements of \$tableNamesTable.
while ($tableLine = mysql_fetch_array($resultOfTableNamesTable,
foreach($tableLine as $tableName)
/* Performing SQL query */
$query = "SELECT * FROM $tableName";
$result = mysql_query($query) or die("<h1>Error</h1><p>Tried Query for
all elements of $tableName. Query failed.</p>");
/* Printing results in HTML */
print "<table border=\"1\"">\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
foreach ($line as $col_value)
print "\t\t<td>$col_value </td>\n";
print "</table><br> \n\n";
/* Free result set */
/* Closing connection */
Thanks for your help!