PHP Foreach in Array [SOLVED]
Posted: Sat Apr 07, 2007 1:32 am
Hi,
I'm having problems getting this array to work:
$tempitems is retrieved from the database in previous code and contains a list of items for a certain order using the item code. i.e. DISC-042007. $pieces is the array which is an array of all the different items split by using <br> because each item has a <br> between it in $tempitems. I then use a foreach statement which works perfectly well when I just have:
in the foreach statement, but my aim is to get each code, connect to the database of items and convert all those codes into proper names like Discount Coupon for the code DISC-042007 etc. The thing is, when I add the database code, it only displays the first item and not the other one. I have tried using several different combinations of items in $tempitems and switched them around but it only displays the first one and does not continue throughout the array. Any ideas?
Regards,
Matt
I'm having problems getting this array to work:
Code: Select all
$pieces = explode("<br>", $tempitems);
foreach ($pieces as $codeitems) {
$query = "SELECT * FROM techlist_items";
$result = mysql_query($query);
if($result) {
while($row = mysql_fetch_array($result)){
$tempname = $row["name"];
$tempcode = $row["code"];
if ($tempcode == $codeitems) {
$maincontent .= "<a href=\"?act=show&code=".$items."\">".$tempname."</a><br>";
}
}
}
}
Code: Select all
$maincontent .= "<a href=\"?act=show&code=".$items."\">".$items."</a><br>";Regards,
Matt