Welcome Guest, Not a member yet? Register   Sign In
How to display table fields dynamically?
#1

[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">
                &lt;?
                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++);
                }
                ?&gt;
            </select>
            Perintah MySQL: <br>
            &lt;textarea name="eksekusi" cols="35" rows="5"&gt; &lt;/textarea&gt;
            &lt;input type="submit" value="coba"&gt;



            </select>

        &lt;/form&gt;  
        &lt;?
        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 "&lt;form action=query.php method=post&gt; &lt;input type=submit value=ulang&gt; &lt;/form&gt;";
        }
        ?&gt;
    &lt;/body&gt;
&lt;/html&gt;
please help me, thanks in advance




Theme © iAndrew 2016 - Forum software by © MyBB