Hi there i’ve 2 fields in a mysql database with similar content:
Field 1: a>b>c
Field 2: 1>2>3
I wish to put them in different rows, exploded.
Example:
-----------------
|Field 1|Field 2|
|----------------
|a |1 |
|b |2 |
|c |3 |
Here a snippet for the code that should make the work:
$result = mysql_query($insert_cat);
while ($row = mysql_fetch_assoc($result))
{
//assegno variabili per l'array associativo
$idcat = $row["id_categorie"];
$descat = $row["categoria"];
//inizio a ciclare all'interno degli array per ricavare le categorie
$ar_id=explode('>',$idcat);
$ar_des=explode('>',$descat);
foreach($ar_id as $value_id)
{
foreach($ar_des as $value_des)
{
}
echo $value_id.'|'.$value_des."\n";
}
}
The problem is: how can I (for testing) echoing what should be inserted in the table?
I’ve tried but with no luck.
Have you tried using the
array_combinefunction – see the php docs on the subject.This will merge two arrays, with the first as they keys for the second. As a result you can replace your
foreachloops with something like this