MySQL Forums
Forum List  »  PHP

Re: while loop - how to remove last comma
Posted by: Barry Galbraith
Date: December 01, 2012 04:34PM

I would write the first iteration without the ,  on it, the at each subsequnet iteration, I'd start with ,&nbsp 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 {?>
<,&nbsp;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.

Options: ReplyQuote


Subject
Written By
Posted
Re: while loop - how to remove last comma
December 01, 2012 04:34PM


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.