0

I want the query to retrieve topics but if the topic repeats I only want one result to show up, no duplicates. I also want it to return username and timestamp. Here is what i have now but I get an error. [mysql_fetch_array() expects parameter 1 to be resource]. Anybody have any ideas of how i should change this?

viewtopics.php

<?php
$sql="SELECT username, timestamp, topic FROM hotspots WHERE topic IN (Select MAX (id) FROM hotspots GROUP BY topic) ORDER BY id DESC";
$result=mysql_query($sql);
 
 
$color="1";
 
echo '<table width="472px" border="0" align="center" cellpadding="2" cellspacing="0" style="border:1px solid #0000ff;">';
while($rows=mysql_fetch_array($result)){
 
if($color==1){
 
echo "
<tr bgcolor='#6698FF' ><td style='border-top:1px solid #0000ff; color:#ffffff;font-weight: bold;'>".$rows['topic']."</td>
<td style='border-top:1px solid #0000ff; color:#ffffff;font-weight: bold;'>".$rows['username']."</td>
<td style='border-top:1px solid #0000ff; color:#ffffff;font-weight: bold;'>".$rows['timestamp']."</td></tr>";
$color="2";
 
} else {
 
echo "<tr bgcolor='#AFDCEC'>
<td style='border-top:1px solid #0000ff;color:#0000ff;font-weight: bold;'>".$rows['topic']."</td>
<td style='border-top:1px solid #0000ff;color:#0000ff;font-weight: bold;'>".$rows['username']."</td>
<td style='border-top:1px solid #0000ff;color:#0000ff;font-weight: bold;'>".$rows['timestamp']."</td></tr>";
$color="1";
}

}
echo '</table>';

?>
3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by karthik_ppts
0

@karthik , yes.
and also you can write like this simply..

SELECT username, timestamp, topic FROM hotspots GROUP BY topic ORDER BY id DESC
Votes + Comments
usefu; post
0

Heres the structure.. I'm testing it in wamp

id int(30)   No None AUTO_INCREMENT               
  topic varchar(250) latin1_swedish_ci  No None                
  comment varchar(1000) latin1_swedish_ci  No None                
  username varchar(30) latin1_swedish_ci  No None                
  timestamp varchar(20)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.