Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Połączenie wartości w tablicy
winiar789
post
Post #1





Grupa: Zarejestrowani
Postów: 130
Pomógł: 0
Dołączył: 15.11.2011

Ostrzeżenie: (0%)
-----


Mam coś takiego :

Array
(
[0] => Array
(
[data-position] => 1
[data-shopurl] =>nazwaa
[data-offer-price] =>
)

[1] => Array
(
[data-position] =>
[data-shopurl] =>
[data-offer-price] => 458.00
)

[2] => Array
(
[data-position] => 2
[data-shopurl] => nazwaa
[data-offer-price] =>
)

[3] => Array
(
[data-position] =>
[data-shopurl] =>
[data-offer-price] => 469.27
)
)

a chciałbym uzyskać:


Array
(
[0] => Array
(
[data-position] => 1
[data-shopurl] =>nazwaa
[data-offer-price] => 458.00
)

[1] => Array
(
[data-position] => 2
[data-shopurl] => nazwaa
[data-offer-price] => 469.27
)
)

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
winiar789
post
Post #2





Grupa: Zarejestrowani
Postów: 130
Pomógł: 0
Dołączył: 15.11.2011

Ostrzeżenie: (0%)
-----


Dupa ze mnie i tyle - taka prawda. Pomóż mi proszę bo siedzę nad tym już tyle :/

  1.  
  2. $res = $sql->query("SELECT url_link, numer_id FROM moja_tabelka");
  3. if($res>0) {
  4.  
  5. $arRes = $sql->GetResult();
  6. foreach ($arRes as $k => $v) {
  7.  
  8. $numer_id = $v['numer_id'];
  9. $target_url = $v['url_link'];
  10.  
  11. $html = file_get_html($target_url);
  12. foreach($html->find('.clasa_wartosci') as $element) {
  13.  
  14. $va['data-position']= $element->getAttribute('data-position');
  15. $va['data-shopurl'] = $element->getAttribute('data-shopurl');
  16. $va['number-shopid'] = $numer_id;
  17. $va['data-offer-price'] = $element->getAttribute('data-offer-price');
  18. $tab[] = $va;
  19.  
  20. }
  21.  
  22. for($i = 0; $i < count($tab); $i=$i+2) {
  23.  
  24. $sql->query("INSERT INTO moja_tabela (xxx1, xxx2, xxx3, xxx4) VALUES (
  25. '".$tab[$i]['data-position']."',
  26. '".$tab[$i]['data-shopurl']."',
  27. '".$tab[$i+1]['data-offer-price']."',
  28. '".$tab[$i]['number-shopid']."')");
  29.  
  30.  
  31. }
  32. }
  33. }
  34.  
  35.  


O to cały kod - pobiera warość z wcześniej wymienionych stron określonych w tabeli bazy danych,
następnie używa DOM do pobrania wartości.

Łączy w całość i dodaje do bazy danych
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 07:35