quick question

Ask about a PHP problem here.
Post Reply
rstinohio1
Posts: 7
Joined: Sun Dec 11, 2011 9:37 pm
Location: USA - OHIO

quick question

Post by rstinohio1 »

i wrote this to display user posts on a news feed type page, how would i be able to display only users with something in the post row of my database?
<div class="container">
	<?php
	$result = mysql_query("SELECT * FROM posting ORDER BY id");

		
	//foreach(fetch_users() as $users){
	//echo '{$users}';
	echo "<table border='0'>

<tr>

<th>UserName</th>

<th>Most Recent Post</th>

</tr>";

while($row = mysql_fetch_array($result))

 {

 echo "<tr>";

 echo "<td>" . $row['usr'] . "</td>";

 echo "<td>" . $row['post'] . "</td>";

 echo "</tr>";

 }

echo "</table>";		
	?>  
	</div>  
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: quick question

Post by jacek »

SELECT `columns`, `you`, `need` FROM `postings` WHERE `post_body` != '' ORDER BY `id`
I guess would work.

Why would you have empty posts in the table at all though ? :?
Image
rstinohio1
Posts: 7
Joined: Sun Dec 11, 2011 9:37 pm
Location: USA - OHIO

Re: quick question

Post by rstinohio1 »

Its like a user status box, some of them have it left blank so i dont want to show them as having a new status if they dont have one. im going to try your code now.
rstinohio1
Posts: 7
Joined: Sun Dec 11, 2011 9:37 pm
Location: USA - OHIO

Re: quick question

Post by rstinohio1 »

thanks, i got it to work, i dont know why your full code didnt work, so i had to play around a bit. thanks!
<div id="main">


	<div class="container">
	<?php
	$result = mysql_query("SELECT * FROM posting WHERE `post` != '' ORDER BY id");

		
	//foreach(fetch_users() as $users){
	//echo '{$users}';
	echo "<table border='0'>

<tr>

<th>UserName</th>

<th>Most Recent Post</th>

</tr>";

while($row = mysql_fetch_array($result))

 {

 echo "<tr>";

 echo "<td>" . $row['usr'] . "</td>";

 echo "<td>" . $row['post'] . "</td>";

 echo "</tr>";

 }

echo "</table>";		
	?>  
	</div>    
</body>
</html>
Post Reply