[eluser]zacksyah[/eluser]
I want to create SQL executor with CI, but my code can't display field table dynamically.
this link below my full CI code :
http://scrp.at/aTI
I tried changing the php code below into CI, the php code below can display field table dynamically
Code:
<html>
<!-- Created on: 7/6/2007 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="Unregistered User">
<meta name="generator" content="AceHTML 6 Pro">
</head>
<body>
<?
$host = "localhost";
$user = "root";
$pass = "";
?>
<form action="query.php" method="post">
Pilih databsae untuk query: <br>
<select name="data" size="1">
<?
mysql_connect($host, $user, $pass);
$tabel = mysql_list_dbs();
for ($i = 0; $i < mysql_num_rows($tabel); $i++) {
echo "<option>" . mysql_table_name($tabel, $i++);
}
?>
</select>
Perintah MySQL: <br>
<textarea name="eksekusi" cols="35" rows="5"> </textarea>
<input type="submit" value="coba">
</select>
</form>
<?
if (isset($_POST['eksekusi'])) {
$host = "localhost";
$user = "root";
$pass = "";
$eksekusi = $_POST['eksekusi'];
mysql_connect($host, $user, $pass);
mysql_select_db($_POST['data']);
//$eksekusi=stripslashes($eksekusi);
$hasil = mysql_query($eksekusi);
echo "<B> Hasil Eksekusi:</b> $eksekusi <br>";
if ($hasil == 0) {
echo "Jancok!" . mysql_errno() . ":" . mysql_error() . "<br>";
} else {
echo "<table border=1> <thead> <tr>";
for ($i = 0; $i < mysql_num_fields($hasil); $i++) {
echo "<th>" . mysql_field_name($hasil, $i) . "</th>";
}
echo "</tr> </thead> <tbody>";
for ($i = 0; $i < mysql_num_rows($hasil); $i++) {
echo "<tr>";
$baris_arai = mysql_fetch_row($hasil);
for ($j = 0; $j < mysql_num_fields($hasil); $j++) {
echo "<td>" . $baris_arai[$j] . "</td>";
}
echo "</tr>";
}
}
echo "<tbody> </table>";
echo "<form action=query.php method=post> <input type=submit value=ulang> </form>";
}
?>
</body>
</html>
please help me, thanks in advance