0

Seems pretty straightforward, 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:

enter image description here

1
  • add an or die(mysql_error()) to the actual query. Commented Aug 4, 2011 at 18:51

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

2

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.

4 Comments

Sorry, no dice. I've also tried using other values from the table (WHERE buzz_title="4dfj") to no avail.
@ninetwozero, php.net/manual/en/function.mysql-fetch-array.php - are you sure that mysql_fetch_array() returns array with only numeric keys? Dont you talking about mysql_fetch_row()?
Oh shoot, I was certain that mysql_fetch_array returned numerics unless specified other (in parameter 2).
By default MYSQL_BOTH is set - it will return an array with numbers and labels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.