Jump to content

concating an array of variables


ScrewLooseSalad

Recommended Posts

I'm trying to build up a long string of variables, but my code only outputs the last entry in the MySQL database, can anyone point out my mistake?

 

$query = "SELECT * FROM `Litem` WHERE 1";
$result = $db->query($query); $i=1;
$i=1;
while ($row = $result->fetch_assoc()) {
if($i=1){$itemlist = "'".$row[Part_Name];}
else{$itemlist .= "','".$row[Part_Name]; }
$i++;
}
$itemlist .= "'";
echo $itemlist;

 

Link to comment
https://forums.phpfreaks.com/topic/275643-concating-an-array-of-variables/
Share on other sites

or

 

    $query = "SELECT Part_Name FROM `Litem` ";
    $result = $db->query($query);
    $i=array();
    while ($row = $result->fetch_assoc()) {
        $i[] = $row['Part_Name'];
    }
    $itemlist = "'" . join("','", $i) . "'";
    echo $itemlist;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.