PDA

View Full Version : PHP. break string



imagined
June 16th, 2005, 08:04 PM
Ok. I have a database with a column where I add products. One of the results looks like this:

PRODUCT NAME
Don Quijote statue, Wooden Ladder

another result:

PRICE:
78.99, 35.99

how could I break the string, so that i create a table like this:

<TABLE>
<TR>
<TD>Don Quijote Statue</TD><TD>78.99</TD>
<TD>Wooden Ladder</TD><TD>35.99</TD>
</TR>
</TABLE>

Please help. Thanks in advance.

Leo :hair:

bigmtnskier
June 16th, 2005, 08:20 PM
$productnames = split(", ",$yourProductResults);
$prices = split(", ",$yourPriceResults);

echo "<TABLE><TR>";
for ($i=0; $i<count($productnames); $i++){
echo "<td>" . $productnames[$i] . "</td>";
echo "<td>" . $prices[$i] . "</td>";
}
echo "</TR></TABLE>";

I hope this helps :)