I`m noob in php/mysql but write something. I have problem with put this together. I have no idea how to put all this function + drop and rename table in logical way to one form. Hmm using case ? Maybe someone write somethink like this for training THX for help.
Code: Select all
<?
// --- sometimes define can help, but not always :]
define('NL',"\n");
define('TB',' ');
// ----------------------
$host='localhost';
$tabela='users';
$kto='citizen99';
$pass='XXX';
$db_name='mydb';
// --------------------- db connection -------------------
$moja=mysql_connect($host,$kto,$pass)
or die("Nie mozna polaczyc sie z serverem");
mysql_select_db("$db_name")
or die("Nie mozna sie polaczyc z baza");
$sql="SELECT * from $tabela";
if($filtr)
$sql.= " where $filtr";
$sql= stripslashes($sql);
print "<B>Filtr:</B> $sql <BR>\n";
print "<B>Baza:</B> $listabaz\n\n";
// --------------------- db list ----------------
$listabaz = mysql_list_dbs( $moja );
while( $row = mysql_fetch_row( $listabaz ) ):
print $rowї0].NL.'<BR>';
endwhile;
mysql_free_result( $listabaz );
print "<B>Tablica:</B> $listatab\n\n";
// ----------------------- tb list
print "<SELECT name='$db_name'>\n";
$listatab = mysql_list_tables($db_name);
while ($row = mysql_fetch_row($listatab)){
foreach ($row as $lista)
{
print "<OPTION>$lista</OPTION>\n";
}
}
print "</SELECT><BR><BR>\n\n";
// ------------------- CREATE z dropem jesli exist ---------------
$sql = 'DROP TABLE IF EXISTS `awaria_awaria`';
echo DB dropped alles OK;
mysql_query( $sql, $moja );
$sql = 'CREATE TABLE `awaria_awaria` (
`kompid` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`opis` VARCHAR( 150 ) NOT NULL,
PRIMARY KEY ( `kompid` )
)';
echo 'Tworzenie Tabeli: ''awaria_awaria''....';
mysql_query( $sql, $moja );
// ---------------------- show tabele -----------------------
$wynik=mysql_query($sql) or die("sql_error");
print "<TABLE border =1><TR bgcolor=gray>\n";
$pole = mysql_list_fields($db_name, $tabela, $moja);
$kolumna = mysql_num_fields($pole);
for ($i = 0; $i < $kolumna; $i++)
print ("<TD>".mysql_field_name($pole, $i)."</TD>\n");
while ( $costam=mysql_fetch_row($wynik)){
print "<TR>\n";
foreach ($costam as $cosinnego)
{
print "<TD>$cosinnego</TD>\n";
}
}
mysql_close($moja);
?>
</TABLE>
</BODY>
</HTML>