Seems pretty straightfo开发者_JAVA百科rward, but not getting an error or result.
<html>
<body>
<?php
$con = mysql_connect("localhost","***","***");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ubook247", $con);
$result = mysql_query("SELECT * FROM buzz_data
WHERE index=4");
while($row = mysql_fetch_array($result))
{
echo $row['buzz_img'] . " " . $row['buzz_title'];
}
?>
</body>
</html>
screenshot of db:
Index is a keyword in SQL, you'll need to escape it for the query to work. Try this:
SELECT * FROM buzz_data WHERE `index` = 4
Try editing the following row:
while($row = mysql_fetch_array($result))
into becoming like this:
while($row = mysql_fetch_assoc($result))
This makes php fetch an array with "labels" for the different fields, instead of naming them 0, 1, 2 and so on.
精彩评论