Re: while loop - how to remove last comma
I would write the first iteration without the , on it, the at each subsequnet iteration, I'd start with ,  so that only get the separator if there is another line to write.
<?php
include 'xxxxxx.php';
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
//List for brands carried
$manufacturers = mysql_query("SELECT * FROM manufacturers ORDER BY manufacturers_name ASC") or die(mysql_error());
$count = 0;
while ($rrows = mysql_fetch_array($manufacturers)) {
if ($count == 0) {?>
<a href="shop/index.php?main_page=index&manufacturers_id=<?php echo $rrows['manufacturers_id']?>"><?php echo $rrows['manufacturers_name']?></a>
<?php}
else {?>
<, a href="shop/index.php?main_page=index&manufacturers_id=<?php echo $rrows['manufacturers_id']?>"><?php echo $rrows['manufacturers_name']?></a>
}<?php
++$count;
} ?>
Good luck,
Barry.
Edited 1 time(s). Last edit at 12/01/2012 05:49PM by Barry Galbraith.
Subject
Written By
Posted
November 30, 2012 07:48PM
November 30, 2012 08:33PM
November 30, 2012 08:40PM
November 30, 2012 10:33PM
November 30, 2012 11:06PM
Re: while loop - how to remove last comma
December 01, 2012 04:34PM
December 02, 2012 02:56PM
December 03, 2012 07:49PM
December 01, 2012 11:22AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.