continue this question:chaîne Parse et le stocker dans db
Je cette chaîne:
$table_summary = '
[Category Name 1=>Title x:Description y,Title q:Description n,Title r:Description m,]
!£|£!
[Category Name 2=>Title z:Description a,Title j:Description k,Title p:Description f,]
!£|£!
';
Comme vous le voyez, il y a un séparateur dans la chaîne comme !£|£!
, et j'ai 2 tables:
products_spec_subjects
id product_id val
products_spec_details
id title description subject_id
Je veux stocker la chaîne dans ces tableaux mentionnés, alors que category name
seront stockées dans la 1ère table, et il est des détails comme le titre et des La cription sera stockée dans la 2ème table et sera liée à la 1ère table en utilisant subject_id comme clé étrangère.
donc après tout, la chaîne doit être mentionnée dans db stocké comme (e.x $product_id=12
):
products_spec_subjects
1 12 Category Name 1
2 12 Category Name 2
products_spec_details
1 Title x Description y 1
2 Title q Description n 1
3 Title r Description m 1
4 Title z Description a 2
5 Title j Description k 2
6 Title p Description f 2
Voici mon code incomplet jusqu'à présent:
$technical_specifications_arr = explode('!£|£!', $table_summary);
unset($technical_specifications_arr[count($technical_specifications_arr) - 1]);
foreach($technical_specifications_arr as $main_value){
$i = 0;
$this_arr = explode('=>', $main_value);
foreach($this_arr as $value){
$cat_name = substr($this_arr[0], 1);
$details = substr($this_arr[1], 0, -1);
if($i == 0){
$tech_main_insert = mysql_query("INSERT INTO products_spec_subjects (product_id, val) VALUES ('$product_id', '$cat_name')") or die(mysql_error());
$this_main_id = mysql_insert_id($link);
}
$i++;
$another_arr = explode(',', $details);
unset($another_arr[count($another_arr) - 1]);
foreach($another_arr as $another_val){
$final = explode(':', $another_val);
foreach($final as $final_value){
// now I can't separate the titles and description here
}
}
}
}
Je vous remercie de toute aide.
Quelle est la sortie de votre code? c'est-à-dire qu'est-ce que vous obtenez lorsque vous renvoyez '$ final_value'? – verbumSapienti
quelques cordes f *** ed qui n'a en fait rien à voir avec ce dont j'ai besoin! avant le dernier foreach: 'foreach ($ another_arr comme $ another_val) {' tout est OK, il insère les principaux chats bien – behz4d
Je ne sais pas pourquoi vous auriez besoin de 'unset()' s dans votre code, peut-être qu'ils sont les problème – verbumSapienti