Jump to content


Php script help.


3 replies to this topic

#1 nygorn

    Young Padawan

  • Members
  • Pip
  • 53 posts
  • Gender:Male
  • Location:Sweden

Posted 27 January 2009 - 07:22 PM

okay, my problem is that i need "WHERE id='$id'" for the news script to display a certain news alone.
But now i need "WHERE author ='$author'" there aswell to display on that news, the number of news that the author of the news has written.
$query = "SELECT COUNT(rubrik) FROM news_table WHERE author ='$author'";


$result = mysql_query("SELECT * FROM communitynews WHERE id='$id' ") or die(mysql_error()); 
while($row = mysql_fetch_array( $result ))
{

	echo "<div id='news'><div id='news-info'><div style='margin-top:20px;margin-left:10px;'>Användare: ";
	echo $row['author'];
	echo " <img src='images/country/";
	echo $row['locate'];
	echo ".gif'>";
	echo "<br /> Nyheter:".$row['COUNT(rubrik)']."</div></div><div style='float:left;margin-left:10px;margin-top:15px;'><b>";
	echo $row['rubrik'];
	echo "</b> skrivet av <b><i>";
	echo $row['author'];
	echo "</i></b> den <i>";
	echo $row['date'];
	echo "</i><br /><i>Kategori: ";
	echo $row['cat'];
	echo "</i><br />";
   	echo $row['content'];
	echo "<br /><a class='read' href='?id=";
	echo $row['id'];
	echo "'></a>
				<a href='?edit=";
	echo $row['id'];
	echo "'>Ändra</a> <a href='?delete=";
	echo $row['id'];
	echo "'>Ta bort</a>
			</div>
		</div>";

I've no idea on how to do this :S

#2 derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 341 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 28 January 2009 - 12:17 AM

WHERE id = '$id' AND author = '$author'

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 January 2009 - 12:55 AM

You have already provided the pieces to the puzzle. Now you need only put the puzzle together. I'll give you the edge pieces:
$query = mysql_query("SELECT COUNT(rubrik) AS `count` FROM `news_table` WHERE `author` ='".$r['author']."'") or die(mysql_error());
$r = mysql_fetch_assoc($query);
echo 'Nyheter: '.$r['count'];
I may just be tired at the moment, but i doubt that you can select the single topic and post count in one query (unless `news_table` and `communitynews` are two separate tables, then we can possibly work something out).

Edited by rc69, 28 January 2009 - 12:56 AM.


#4 023-jimmy

    Young Padawan

  • Members
  • Pip
  • 44 posts

Posted 28 January 2009 - 10:04 AM

This is also a way to do it:

$query = mysql_query("SELECT * FROM `news_table` WHERE `author` ='".$r['author']."'") or die(mysql_error());
echo 'Nyheter: '. mysql_num_rows($query);






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users