Location: PHPKode > projects > AJAX MySQL Admin > ajaxmysqladmin/www/api/object.php
<?php
    require_once ('inc/constants.inc');
    require_once ('inc/generic_start.inc');
    $shown = false;

    if ($dbname !== null && isset ($_GET ['title'])) {
        $table = $_GET ['title'];

        $query = "SHOW COLUMNS FROM ". $table;

        $conn = mysql_connect ($dbhost . ":" . $dbport, $dbuser, $dbpass);
        mysql_select_db ($dbname);
        $result = mysql_query ($query, $conn);
        if ($result !== FALSE && mysql_num_rows ($result) > 0) {
            ?>
            {
                page: 1,
                total: <?php echo mysql_num_rows ($result) ?>,
                rows: [
                    <?php
                        $count = 0;
                        while ($row = mysql_fetch_row($result)) {
                            if ($count > 0) echo "," . NL;
                            $id = $count;
                            $name = $row [0];
                            $type = $row [1];
                            if (strpos ($type, '(') !== FALSE && strpos ($type, ')') !== FALSE) {
                                $size = substr ($type, strpos ($type, '(') + 1);
                                $size = substr ($size, 0, strpos ($size, ')'));
                                $type = substr ($type, 0, strpos ($type, '('));
                            } else {
                                $size = '';
                            }
                            echo "{id:'" . $id . "',cell:['" . $id . "','" . $name . "','" . $type . "','" . $size . "']}";
                            $count ++;
                        }
                        mysql_free_result ($result);
                    $shown = true;
                    ?>
                ]
            }
        <?php
        }
        mysql_close ($conn);
    }

    if (!$shown) {
        ?>
        {
            page: 1,
            total: 0
        }
        <?php

    }

    require_once ('inc/generic_finish.inc');
?>
Return current item: AJAX MySQL Admin