MYSQL Display

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Suraski
Forum Newbie
Posts: 10
Joined: Tue Jul 10, 2007 10:30 pm

MYSQL Display

Post by Suraski »

I want to only display only 10 MYSQL rows instead of all of the rows in the table, what's the code?
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

haha. good luck getting code that way.
Suraski
Forum Newbie
Posts: 10
Joined: Tue Jul 10, 2007 10:30 pm

Post by Suraski »

ok, here's my current code. I want to display only ten rows from the table, can you help me out?

Code: Select all

mysql_select_db("news", $con);
$result = mysql_query("SELECT * FROM news");
while($row = mysql_fetch_array($result))
{
if ( $row['cat'] == News){
echo "				<table bgcolor=\"#FFF7CA\" width=\"500\" height=\"100\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: 1px solid #FFD460; margin: 10px; padding: 0;\" >
					<tr>
          				<td valign=\"top\" height=\"15\" style=\"padding: 3px 3px 3px 5px ; border-bottom: 1px solid #FFD460\">
							<d1head> News: &nbsp;" . $row['title'] . "</d1head>
		  				</td>
					</tr>
					<tr>
						<td valign=\"top\" height=\"20\" style=\"padding: 10px\"
							<t2>" . $row['news'] . "</t2><t2><br /> 
							<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row['name'] . "</t2>										
						</td>
					</tr>
					<tr>
						<td valign=\"top\" height=\"20\" style=\"border-top: 1px solid #FFD460\">
							<t2>" . $row['date'] . "</t2>						
						</td>
					</tr>
				</table>
		";
}
else{
echo "				<table bgcolor=\"#FAF0FF\" width=\"500\" height=\"100\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: 1px solid #EC9EFF; margin: 10px; padding: 0;\" >
					<tr>
          				<td valign=\"top\" height=\"15\" style=\"padding: 3px 3px 3px 5px ; border-bottom: 1px solid #EC9EFF\">
							<d1head> Blog: &nbsp;" . $row['title'] . "</d1head>
		  				</td>
					</tr>
					<tr>
						<td valign=\"top\" height=\"20\" style=\"padding: 10px\"
							<t2>" . $row['news'] . "</t2><t2><br /> 
							<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $row['name'] . "</t2>										
						</td>
					</tr>
					<tr>
						<td valign=\"top\" height=\"20\" style=\"border-top: 1px solid #EC9EFF\">
							<t2>" . $row['date'] . "</t2>						
						</td>
					</tr>
				</table>
		";
}
}
mysql_close($con);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

LIMIT 10.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Suraski
Forum Newbie
Posts: 10
Joined: Tue Jul 10, 2007 10:30 pm

Post by Suraski »

Thx everybody
Post Reply