Jump to content

Displaying results in Groups: please help


OB82

Recommended Posts

Dear all,

I am new in this forum. This is my code

  $query = "
  SELECT webdb.id, webdb.writer, writer.picLoc, webdb.title FROM webdb, writer WHERE webdb.writer=writer.name and 
  category = 'Researchworks' and language = 'Farsi' ORDER BY writer DESC"; 
  $resultaat = mysql_query($query, $LinkID);
  $column_count = mysql_num_fields($resultaat) or die (mysql_error()."<br>Couldn't execute query: $SQLquery");
  
  $counter=1;
  echo "<table border=\"0\" width=\"700\" border color=white><tr>";
  while ($row = mysql_fetch_row($resultaat))
  {
  if ($author !== $row[1])
  {
	  $author = $row[1];
	  echo "<td align=right width=220 valign=top style=\"margin: 5px; float: right border-bottom-color:#000; border-left-color:#000;\">";
	  echo "<img width=\"50\" height=\"80\" src=\"admin/writers/$row[2]\" border =\"0\"><br>".$row[1]."<br>";												
	  echo "<a href=\"poems.php?writer=$row[1]\">".$row[3]."</a><br>";
	  echo "</td>";
	  if($counter%3==0) 
	  {
		  echo"</tr><tr>";
	  }
	  $counter++;
	}
  }
  echo"</tr></table>";

 

i have authors with different articles on a certain topic. What i want is, displaying the name of the author only once and all his titles under his name. I also want a dynamic table where i display three authors in each row and soon as there a fourth author a new row must start. My problem now is is the title is also being filtered and i can only display one title.

 

Thanks in advance

perhaps a rough idea (you will need to modify for your particular names & values)...

 

$query = "SELECT * FROM tablename ORDER BY author_name";
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {
$author_name = $row['author_name'];
echo $author_name "<br>";
$query2 = "SELECT * FROM tablename WHERE author_name = '$author_name'";
$result2 = mysql_query($result2);
while($row2=mysql_fetch_array($result2)) {
	echo "    " . $row2['title'] . "<br>";
}
echo "<hr>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.