Page 1 of 1

modifiing code problem

Posted: Wed May 11, 2011 10:40 am
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

Re: modifiing code problem

Posted: Wed May 11, 2011 10:42 am
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

Re: modifiing code problem

Posted: Wed May 11, 2011 10:48 am
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?

Re: modifiing code problem

Posted: Wed May 11, 2011 11:23 am
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>";
	}
}

Re: modifiing code problem

Posted: Wed May 11, 2011 11:54 am
by EcazS
If you want 3 separate lists you need the UL inside the while loop.