-5

I am trying to create a rumour-based website. In one part of the site, there is a working feature where you are post rumours and the rumours are shown.

But i am working on the homepage so that the two latest rumours are placed into a table. With my code below, there is a table with no rows, despite data being in the mysql table, and this error message:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /websites/123reg/LinuxPackage22/th/eq/li/theqlick.com/public_html/leeds.php on line 212

Any idea? My code is below:

$query = "SELECT * FROM rumour ORDER BY id DESC";
$row = mysql_fetch_assoc($query); 
$id = $row['id'];
$name = $row['name'];
$description = $row['description'];

echo "<table class ='rumour' border='1'>";
echo "<tr>";
echo "<td style = 'font-size:18pt;font-family:Noteworthy-Bold;'> Hot Rumours  </td>";
echo "<tr>";
echo "<td class = 'td1'>". text2link($row['description']). "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class = 'td1'>". text2link($row['description']). "</td>";
echo "</tr>";
echo "</table>";
air4x
  • 5,618
  • 1
  • 23
  • 36
Lily Smith
  • 1
  • 1
  • 3
  • You need to modify the line at `$query = mysql_query("SELECT * FROM rumour ORDER BY id DESC");` – asprin Nov 02 '12 at 12:42
  • You need to have mysql_fetch_assoc on your results than query - $result = mysql_query($sql); and then $row = mysql_fetch_assoc($result) –  Nov 02 '12 at 12:42
  • 2
    Also you need to stop using `mysql_*` functions and go with `pdo` or `mysqli_*` – Leri Nov 02 '12 at 12:43

4 Answers4

0

You're posting a string into mysql_fetch_assoc, and not a mysql_query...

$query = "SELECT * FROM rumour ORDER BY id DESC";

Should be

$query = mysql_query("SELECT * FROM rumour ORDER BY id DESC");
phpisuber01
  • 7,585
  • 3
  • 22
  • 26
0

The manual for that function says:

array mysql_fetch_assoc ( resource $result )

You are passing it a string containing a query, not the result of running a query.

You need to pass it through mysql_query first.

… at least you do if you continue using mysql_*, which you shouldn't. It is obsolete and you should use a modern replacement.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Use are directly using $query in mysql_fetch_assoc($query) which is string type. You forget to get result. Use this instead:

$query="Your query here";
$result=msqyl_query($query);
$row = mysql_fetch_assoc($query); 
ujjwalwahi
  • 342
  • 1
  • 4
  • 13
0

You have forget to execute you query using mysql_query function

Try this code may be help you

$query = "SELECT * FROM rumour ORDER BY id DESC";
$result=mysql_query($query);
$row = mysql_fetch_assoc($result);
Hkachhia
  • 4,463
  • 6
  • 41
  • 76