Reputation: 243
Hope I explain this correctly.
I have in my code
$eng[] = "All";
$eng[] = "engine_Sigma";
$eng[] = "engine_K-Series";
$eng[] = "engine_Duratec";
$eng[] = "engine_Suzuki";
$eng[] = "engine_Vauxhall";
$eng[] = "engine_Crossflow";
// query your db
$itemsq = mysqli_query($con,"SELECT * FROM `crm`.`workshop-items` LIMIT 0,100");
$items = mysqli_fetch_assoc($itemsq);
// do/while? should prob just use a while loop
do {
$enginetype = explode(":", $items['engineid']);
foreach ($enginetype as $key) {
echo "$items[wsiid] - $items[code] - $items[incvat] - $eng[$key] <br>
";
}
} while ($items = mysqli_fetch_assoc($itemsq));
However in the DB the engineid's are stored as 1:3:6 for example or even 1:2:3:4:5:6 now what I want to do is if there are multiple values and they have been split up, instead of it just echoing the first item and then echoing the data again for the next id (like this WSIID - CODE INCVAT engine_K-Series ) and so on I want to do display ( WSIID - CODE - INCVAT - engine_Sigma engine_K-Series ) if $eng is 1 & 3 ( 1:3)
Hope you can understand what I mean
Thanks guys
Upvotes: 1
Views: 48
Reputation: 3864
You should echo the first part of the data outside of your foreach
loop, and echo only the engine type inside the foreach
:
<?php
$eng[] = "All";
$eng[] = "engine_Sigma";
$eng[] = "engine_K-Series";
$eng[] = "engine_Duratec";
$eng[] = "engine_Suzuki";
$eng[] = "engine_Vauxhall";
$eng[] = "engine_Crossflow";
// query your db
$itemsq = mysqli_query($con,"SELECT * FROM `crm`.`workshop-items` LIMIT 0,100");
//$items = mysqli_fetch_assoc($itemsq); # you should delete this, see my explanation below
// do/while? should prob just use a while loop
do {
$enginetype = explode(":", $items['engineid']);
echo "$items[wsiid] - $items[code] - $items[incvat] - ";
foreach ($enginetype as $key) {
echo "$eng[$key] ";
}
echo "<br />";
} while ($items = mysqli_fetch_assoc($itemsq));
You should delete your first execution of $items = mysqli_fetch_assoc($itemsq);
, or your do...while
loop will start at the 2nd iteration.
Upvotes: 1