- PHP, PHP. MySQL (, PHP) SELECT SQL:
mysql> SELECT * FROM Artifacts;
, , , mysql_query(); - . mysql_query() , TRUE FALSE. , . - , , . - mysql_field_name(), , . PHP . - mysql_result() mysql_fetch_array().
mysql_result
mysql_result ( result,
row [, field])
mysql_result() . field , tablename. fieldname. ('select foo as bar from...'), .
, , (, mysql_fetch_row(), mysql_fetch_array() ..). , mysql_result(). , , ( ) , .
mysql_result() , .
mysql_fetch_array
mysql_fetch_array ( result
[, result_type])
, (, ) , FALSE, .
mysql_fetch_array() - mysql_fetch_row(). , .
, . , . , , , "photo" .
select Artifacts.photo as art_image,
Persons.photo as pers_image
from Artifacts, Persons
11.1.
, mysql_fetch_array() , mysql_fetch_row(), .
|
|
result_type mysql_fetch_array() : MYSQL_ASSOC, MYSQL_NUM MYSQL_BOTH. PHP 3.0.7. :MYSQL_BOTH.
MYSQL_BOTH, , , . MYSQL_ASSOC , MYSQL_NUM - .
: , , .
Artifacts :
<?
/ * , :
, Artifacts */
$conn=mysql_connect("localhost","nina","123");
$database = "book";
$table_name = "Artifacts";
mysql_select_db($database);
$list_f = mysql_list_fields($database,$table_name);
$n1 = mysql_num_fields($list_f);
// $names
for($j=0;$j<$n1; $j++){
$names[] = mysql_field_name ($list_f,$j);
}
$sql = "SELECT * FROM $table_name"; // SQL
$q = mysql_query($sql,$conn) or die(); //
//
$n = mysql_num_rows($q); //
// HTML-
echo " <TABLE BORDER=0 CELLSPACING=0 width=90%
align=center><tr><TD BGCOLOR='#005533' align=center>
<font color='#FFFFFF'><b>$table_name</b></font></td>
</tr></TABLE>";
echo "<table cellspacing=0 cellpadding=1 border=1
width=90% align=center>";
//
echo "<tr>";
foreach ($names as $val){
echo "<th ALIGN=CENTER BGCOLOR='#C2E3B6'>
<font size=2>$val</font></th>";
}
//
echo "</tr>";
for($i=0;$i<$n; $i++){ //
//
echo "<tr>";
foreach ($names as $val) { //
//
$value = mysql_result($q,$i,$val); //
//
echo "<td><font size=2> $value</font></td>";
//
}
echo "</tr>";
}
echo "</table>";
11.1.1. Artifacts
mysql_fetch_array():
<?
/*... , */
//
//
while($row = mysql_fetch_array($q, MYSQL_ASSOC)) {
echo "<tr>";
foreach ($names as $val){
echo "<td><font size=2> $row[$val]</font></td>";
//
}
echo "</tr>";
}
echo "</table>";
?>
11.1.2. Artifacts . 2
: PHP. , SQL - . , , , (.. , ) .. , , , , web-.
|
|