3 Replies - 332 Views - Last Post: 08 November 2011 - 06:31 AM Rate Topic: -----

#1 Syfer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 190
  • Joined: 08-October 10

looping the data that is fetched

Posted 08 November 2011 - 05:30 AM

if my code is like this
<div style="overflow:auto;position:absolute;left:350px;top:30px;text-align:left;border: 5px solid #c4c8cc;
  -moz-box-shadow: 5px 5px 7px #888;
  -moz-border-radius-bottomright: 15px;
  -webkit-box-shadow: 5px 5px 7px #888;
  -webkit-border-bottom-right-radius: 15px;width:550px;">
  
  <?php
    $query=mysql_query("SELECT * from news ORDER by news_id");
	$rowss= mysql_fetch_array($query);
	
	echo "<h1>Daily news</h1><br/>";
	echo "<hr/>";
	echo "<p style='font-size:16px;font-family:arial black;'>".$rowss['news_title']."</p>"."";
	echo "<p style='font-size:16px;font-family:courier new;'>".$rowss['news_content']."</p>"."<br/>";
	echo "<p style='font-size:16px;font-family:courier new;'>".$rowss['news_pic']."</p>"."<br/>";
	echo "<p style='position:absolute;left:380px;font-size:12px;font-family:courier new;'>".$rowss['news_date']."</p>"."<br/><br/>";
	echo "<hr/>";
  ?>
</div>



how would i loop or print all the datas inside my tbl named news?


any help would be appreciated :)

Is This A Good Question/Topic? 0
  • +

Replies To: looping the data that is fetched

#2 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: looping the data that is fetched

Posted 08 November 2011 - 05:34 AM

$query = mysql_query("YOUR SELECT QUERY HERE");

while($row = mysql_fetch_assoc($query))
{

echo "Stuff. E.g.: " . $row['news_title'];

}



Was This Post Helpful? 2
  • +
  • -

#3 Syfer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 190
  • Joined: 08-October 10

Re: looping the data that is fetched

Posted 08 November 2011 - 05:39 AM

View PostDuckington, on 08 November 2011 - 05:34 AM, said:

$query = mysql_query("YOUR SELECT QUERY HERE");

while($row = mysql_fetch_assoc($query))
{

echo "Stuff. E.g.: " . $row['news_title'];

}




oh i forgot i only lack the word while TROLOLOL .. silly me
thanks anyways :D
Was This Post Helpful? 0
  • +
  • -

#4 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: looping the data that is fetched

Posted 08 November 2011 - 06:31 AM

It's not just that you lacked the word while, you were not looping through the result set. while loops will continue to run a block of code while a given expression evaluates to true.

In this case
while($row = mysql_fetch_assoc($query))



Will run until mysql_fetch_assoc returns false, which it will do when there are no results left in the $query resource.

It's not just a matter of knowing where things go you should also understand why they go there.

This post has been edited by Jstall: 08 November 2011 - 06:32 AM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1