Введение в СУБД MySQL


Example.12.1


<?php

$db = mysql_connect("localhost", "root");

mysql_select_db("mydb",$db); // display individual record

if ($id)

{

$result = mysql_query("SELECT * FROM employees WHERE id=$id",$db);

$myrow = mysql_fetch_array($result);

printf("First name: %s\n
", $myrow["first"]);

printf("Last name: %s\n
", $myrow["last"]);

printf("Address: %s\n
", $myrow["address"]);

printf("Position: %s\n
", $myrow["position"]);

}else

{

// show employee list

$result = mysql_query("SELECT * FROM employees",$db);

if ($myrow = mysql_fetch_array($result))

{

// display list if there are records to display

do{

printf("%s %s
\n", $PHP_SELF, $myrow["id"],

$myrow["first"], $myrow["last"]);

}while ($myrow = mysql_fetch_array($result));

}else

{

// no records to display

echo "Sorry, no records were found!";

}

}

?>




Начало  Назад  Вперед