Start with something like the following and add  mysql_list_dbs () to query
the system for the available databases.
Hugh

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Input Data Page</title>
<?php include ("css.txt"); ?>
</head>
<body bgcolor="#1D3E81" >
<h1><font color="#ffff33">DATABASE TABLES</font></h1>

<form action="<?php print $php_self?>" method="post">
<?php

print "<table cellpadding=7 border=1 bgcolor=#d5d5d5><tr><td>";
print "<h6>Database name:</h6><input type=text name=db STYLE=width:140px>
</td><td>";
print "<h6>Password:</h6><input type=text name=pass STYLE=width:140px>";
print "</td><td valign=middle align=center><input type=submit value=\" go
\">";
print "<input type=hidden name=start value=1>";
print "</td></tr></table></form><br>";
if ($start=="1")
 {
 $link=mysql_connect("localhost","","$pass");
 if (! $link) die("couldn't connect mysql");
 mysql_select_db($db,$link) or die ("couldn't open $db ".mysql_error());
 $tables=mysql_list_tables($db,$link);
 $num=mysql_num_rows($tables)-1;
 mysql_close($link);
 ?>
 <form action="<?php print $php_self?>" method="post">
 <?php
 print "<table cellpadding=7 border=1 bgcolor=#d5d5d5><tr><td>";
 print "<h6>Table Name: </h6><select type=text name=table
STYLE=width:140px><option>";

 for ($i=0;$i<=$num;$i++)
  {
  print "<option>".mysql_tablename($tables,$i);
  }
 print "</select>";

 print "</td><td><input type=submit value=\" go  \">";
 print "<input type=hidden name=start value=2>";

 print "<input type=hidden name=db value=$db>";
 print "<input type=hidden name=pass value=$pass>";
 print "</td></tr></table></form><br>";
 }

if ($start=="2")
 {
 $link=mysql_connect("localhost","","$pass");
 if (! $link) die("couldn't connect mysql");
 mysql_select_db($db,$link) or die ("couldn't open $db ".mysql_error());

 $results=mysql_query("select * from $table");
 $fields = mysql_list_fields("$db", "$table", $link);
 $columns = mysql_num_fields($fields);
 mysql_close($link);
 print "<table width=95% bgcolor=#d5d5d5 border=1 cellspacing=0
cellpadding=0><tr><td align=center><h3>$table</h3>";
 print "<table width=100% bgcolor=#d5d5d5 border=1 cellspacing=0
cellpadding=4>";
 print "<tr>";
 for ($i = 0; $i < $columns; $i++)
  {
  print "<td align=center bgcolor=#6c6c6c><h5><font
color=white>".mysql_field_name($fields, $i)."</font></h5></td>";
  }
 print "</tr>";
 print "<tr>";
 for ($i = 0; $i < $columns; $i++)
  {
  print "<td align=center bgcolor=#fbfbfb><h5>".mysql_field_type($results,
$i)."</h5></td>";
  }
 print "</tr>";
 while ($a_row=mysql_fetch_row($results))
  {
  print "<tr>";
  foreach($a_row as $field)
   {
   if ($field=="")
    {
    $field="&nbsp;";
    }
   print "<td align=center><h5>".$field."</h5></td>";
   }
  print "</tr>";
  }
 print "</table></td></tr></table>";
 }
?>
</body>
</html>


----- Original Message -----
From: "jtjohnston" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, February 17, 2002 7:34 PM
Subject: [PHP] phpmyadmin-mysql


> Hello,
>
> I'm looking for code to display all my mysql databases in a <select>.
> On change, I want to display all my tables in a <select>.
> Finally, on change, it has to display all record of the table selected:
>
> Print Record
>
>
>         id YR   AU           BT
>          1 1997 Fee, Margery Writing Orality: Interpreting Literature
>  Display                     in English by Aboriginal Writers in North
>                              America, Australia and New Zealand
>
> Can someone give me a hand getting started?
> I would normally use phpmyadmin, but I want to customise something they
> don't offer.
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to