PHP/MySQL Database/mysql result — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 10:37, 26 мая 2010
function mysql_result() produces a data set.
Its syntax is: int mysql_result (int result_id, int row [, mixed field])
<?
@mysql_connect("localhost", "root","") or die("Could not connect to MySQL server!");
@mysql_select_db("mydatabase") or die("Could not select database!");
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
$x = 0;
print "<table>";
print "<tr><th>ID</th><th>Title</th><th>MyValue</th></tr>";
while ($x < mysql_numrows($result)) :
$id = mysql_result($result, $x, "id");
$name = mysql_result($result, $x, "title");
$price = mysql_result($result, $x, "myvalue");
print "<tr>";
print "<td>$id</td><td>$title</td><td>$myvalue</td>";
print "</tr>";
$x++;
endwhile;
</table>
mysql_close();
?>
mysql_result-2.php
<?php
...
$query = "SELECT productid, name FROM product ORDER BY name";
$result = mysql_query($query);
for ($count=0; $count <= mysql_numrows($result); $count++)
{
$productid = mysql_result($result, $count, "productid");
$name = mysql_result($result, $count, "name");
echo "Product: $name ($productid) <br />";
}
...
?>
mysql_result.php
<?php
...
$query = "SELECT productid, name FROM product ORDER BY name";
$result = mysql_query($query);
$productid = mysql_result($result, 0, "productid");
$name = mysql_result($result, 0, "name");
...
?>