开发者

trying to display data from db using sql and php

开发者 https://www.devze.com 2023-03-26 03:57 出处:网络
Seems pretty straightfo开发者_JAVA百科rward, but not getting an error or result. <html> <body>

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:

trying to display data from db using sql and php


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消