Heya!
About time I joined a forum like this, been sticking my nose in books like "Teach yourself PHP, MySQL and Apache in 24 hours", and frankly starting to wonder if this really is so difficult as it seems from the size of these books. What I really need is a dictionary with ALL the code along with examples and explanations of how each command work. If any of you have any recommandations please tell me 🙂 .
However, what I've been struggling with and frankly is about to give up on is rendering a MySQL table in a webrowser using PHP. The problem is that I want to be able to render any table with its records, without knowing the field names nor anything. It is fairly easy to make a script renedering a table I know everything about already, but that seems rather pointless.
I have searched the MySQL website for codes that might help me, but there seem to be no mysql_fieldname(), so there is no point in making a loop gathering all the fieldnames. Also it would be really neat if the script could make all the field names and records into variables somehow, so I could order it all into an HTML table.
Here is my code as it looks now:
<?php
#connecting to MySQL
$conn = mysql_connect("secret","secret","secret")
or die("Could not connect to MySQL");
#create variable to work with:
$jaxeed = "secret";
$record = $_POST["secret"];
#select database
mysql_select_db("secret", $conn);
if($record != NULL)
{
$sql = "SELECT * FROM $record";
$result = mysql_query($sql, $conn) or die (mysql_error());
$number_of_fields = mysql_num_fields($result);
$number_of_rows = mysql_num_rows($result);
$fds = "SHOW COLUMNS FROM $record";
$fields = mysql_list_fields($jaxeed ,$record, $conn);
}
#list tables
$tables = mysql_list_tables($jaxeed, $conn);
for($num=0; $num < mysql_num_rows($tables); $num++)
{$list.= "| " .mysql_tablename($tables, $num). " |" ;};
mysql_close($conn);
?>
<html>
<head>
<title>MySQL Manager</title>
<link href="secret.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#000080" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" id="monitor">
<table width=500 border="0" cellspacing="10" cellpadding="0" class="monitor">
<tr>
<td>
<?php
echo "Tabels in database jaxeed_com :<br>";
echo "*************************************<br>";
echo "$list";
if($record != NULL) {
echo "<br>____________________________________<br>";
echo "| $record | Fields: $number_of_fields | Rows: $number_of_rows |<br>";
echo "$fields";
};
?>
</td>
</tr>
</table>
</body>
</html>
-------------------------------------------------------------------------------
As you can see I'm trying to get hold of the field names in this part:
$fds = "SHOW COLUMNS FROM $record";
$fields = mysql_list_fields($jaxeed ,$record, $conn);
... but funnily enough this returns a nice echo saying:
Resource id #3
errrr... thx.... I think..lol
I hope somebody will be able to give me some hints on how this could be done, or perhaps give me some better ideas on how to render an entire table in a web browser without knowing anything else but the database and table name.
CHEERS!!!