Пример разбора php-кода в связке с mysql

<?
function db_query($sql)
{
    $result = mysql_query($sql);
      
    while ($arr = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        $new[] = $arr;
    }
    return $new;
}

function dump($var)
{
    echo "<pre>";
    print_r($var);
    echo "</pre>";
}

$connect = mysql_connect('localhost', 'root', '')
    or die('hello!');
  
mysql_select_db ('New_db', $connect)
    or die('Hello222!');


$publisher = db_query("SELECT `title` FROM `publishers` WHERE `id` = {$_GET['publisher']}");
echo "<h1>{$publisher[0]['title']}</h1>";


$arr1 = db_query('SELECT * FROM `publishers` WHERE 1');
echo '<table border = "1">';
foreach ($arr1 as $value)
{
    echo "<tr><td>{$value['id']}</td><td>{$value['title']}</td></tr>";
}
echo '</table>';

$arr1 = db_query('SELECT * FROM `publishers` WHERE `id` > 2');

echo '<select>';
echo '<option value=0>..</option>';

foreach ($arr1 as $value)
{
    echo "<option value={$value['id']}>{$value['title']}</option>";
}

echo '</select>';

?>

No comments :

Post a Comment