cheechm Posted August 13, 2008 Share Posted August 13, 2008 Hi, Me again. I do this: while ($rowi = db_fetch_array($resulti)) { echo $rowi['name'] .", "; } The comma shows on the last result as well. How can I stop that? Thanks Link to comment https://forums.phpfreaks.com/topic/119566-seperating-mysql-data/ Share on other sites More sharing options...
void Posted August 13, 2008 Share Posted August 13, 2008 some basic thinking ... while ($rowi = db_fetch_array($resulti)) { $names .= $rowi['name'] .", "; } echo substr($names,0,-2); Link to comment https://forums.phpfreaks.com/topic/119566-seperating-mysql-data/#findComment-615983 Share on other sites More sharing options...
cheechm Posted August 13, 2008 Author Share Posted August 13, 2008 Doesn't seem to work. Link to comment https://forums.phpfreaks.com/topic/119566-seperating-mysql-data/#findComment-615993 Share on other sites More sharing options...
Barand Posted August 13, 2008 Share Posted August 13, 2008 $names = array(); while ($rowi = db_fetch_array($resulti)) { $names[] = $rowi['name']; } echo join (', ', $names); Link to comment https://forums.phpfreaks.com/topic/119566-seperating-mysql-data/#findComment-615997 Share on other sites More sharing options...
cheechm Posted August 13, 2008 Author Share Posted August 13, 2008 That neither thanks! Link to comment https://forums.phpfreaks.com/topic/119566-seperating-mysql-data/#findComment-616006 Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 $names = array(); while ($rowi = db_fetch_array($resulti)) { $names[] = $rowi['name']; } echo implode(', ', $names); Link to comment https://forums.phpfreaks.com/topic/119566-seperating-mysql-data/#findComment-616009 Share on other sites More sharing options...
cheechm Posted August 13, 2008 Author Share Posted August 13, 2008 Doesn't seem to work either. I will post a bigger code block: $sqlc = "SELECT name FROM customers WHERE cid = " . $cid . ""; $resultc = db_query($sqlc) or die("MySQL ERROR: " . mysql_error()); while ($rowc = db_fetch_array($resultc)) { if ($row['delivery']) { $delivery = "<li>Delivery: Required</li>"; } echo "<ul class=\"qrequestsf\">"; echo "<li>Quote ID: " . $qid . "</li><li>Customer: " . $rowc['name'] . "</li><li>Notes: " . $row['notes'] . "</li><li>Last Action Taken: " . date('d/m/Y', strtotime($row['date'])) . "</li><li>Date required: " . date('d/m/Y', strtotime ($row['pdate'])) . "</li><li>Return Date: " . date('d/m/Y', strtotime($row['rdate'])) . "</li>" . $delivery . "<li>Kit Required: "; $item = split(', ', $row['items']); $items = array_unique($item); foreach ($items as $value) { $sqli = "SELECT name FROM hire WHERE id = " . $value . ""; $resulti = db_query($sqli) or die("MySQL ERROR: " . mysql_error()); $names = array(); while ($rowi = db_fetch_array($resulti)) { echo $rowi['name'] .", "; } } echo "</li><li>Status: " . $status_is . "</ul>"; } Link to comment https://forums.phpfreaks.com/topic/119566-seperating-mysql-data/#findComment-616014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.