modifiing code problem

Ask about a PHP problem here.
Post Reply
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

modifiing code problem

Post by ta2shop »

hy guys, i want to style a bit the shopping cart, and i need to add <ul> an <li> tags to the products function, the problem is the code loks like this:
function products() {
	$get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER BY id DESC') or die(mysql_error());
	if(mysql_num_rows($get)==0) {
		echo "There are no products to display!";
	}
	else {
		while($get_row = mysql_fetch_assoc($get)) {
			echo'<p><b>'.$get_row['name'].'</b><br/>'.$get_row['description'].'<br/>'.number_format($get_row['price'],2).'€ <a href="cart.php?add='.$get_row['id'].'">Add</a><p/>';
		}
	}
}
aaa where exactly thoes the html have to go! do i have to put the starting ul tag above the while loop? and the li inside of it?
thanks
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: modifiing code problem

Post by EcazS »

ta2shop wrote: aaa where exactly thoes the html have to go! do i have to put the starting ul tag above the while loop? and the li inside of it?
thanks
Yep! And the closing ul under the while loop :P
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: modifiing code problem

Post by ta2shop »

ok, but when the code look so mesii like this one, how can i brakeit down, like put every element one under the odher?
Image
User avatar
ta2shop
Posts: 179
Joined: Sat May 07, 2011 9:07 am
Location: madrid, Spain
Contact:

Re: modifiing code problem

Post by ta2shop »

hey i did it! but now as i have 3 products, all of them show uo in the same list, and not 3 separate lists. any ideea on how to change that?
thanks
*edit: i forgot the code!
function products() {
	$get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER BY id DESC') or die(mysql_error());
	if(mysql_num_rows($get)==0) {
		echo "There are no products to display!";
	}
	else {
		echo"<ul id='products'>";
		while($get_row = mysql_fetch_assoc($get)) {
			echo'<li><b>'.$get_row['name'].'</b></li>
			<li>'.$get_row['description'].'</li>
			<li>'.number_format($get_row['price'],2).
			'€ <a href="cart.php?add='.$get_row['id'].'">Add</a></li>';
		}
		echo"</ul>";
	}
}
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: modifiing code problem

Post by EcazS »

If you want 3 separate lists you need the UL inside the while loop.
Post Reply