Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Tablice, Problem z odczytaniem z tablicy
gregi1
post
Post #1





Grupa: Zarejestrowani
Postów: 134
Pomógł: 0
Dołączył: 24.03.2007

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


Mam taki problem otoz mam stworzona funkcje

jakas_funkcja($filename) {
..........
//tutaj jest sprawdzany rozmiar obrazka, typ itd
// nastepnie jest to wrzucane do tablicy

$results['original'] = array(
'img_format' => 'original',
'img_width' => $Info[0],
'img_height' => $Info[1],
'img_mime' => $Info['mime'],
'img_path' => $upload
);

}

zapis do bazy() {
........
// zapis do bazy przez zapytanie insert
}

$objImage= new Image();
jakas_funcka($filename);
$results = jakas_funcka($filename);

i tutaj teraz mam problem
otoz nie wiem jak przypisac nowej zmiennej np

$width= wartosci z tej tablicy abym mogl sobie ten wymiar wstawic pozniej do bazy

Jesli napisze :
$width = $results['original']['img_width'];
// to otrzymuje komunikat o bledzie:
"Cannot use string offset as an array in" w powyzszej linijce.
zapis do bazy()

Prosze o pomoc w przypisaniu tych wartosci z tablicy i wstawieniu ich do bazy.

W tablicy mam string i jak z tego wybrnac!!!!

Ten post edytował gregi1 11.06.2007, 14:05:30


--------------------
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
abc667
post
Post #2





Grupa: Zarejestrowani
Postów: 229
Pomógł: 0
Dołączył: 29.05.2007

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


jeśli chcesz by takie coś przypisywało do zmiennej results tablicę musisz w funkcji użyć return
  1. <?php
  2. $results = jakas_funcka($filename);
  3.  
  4. jakas_funkcja($filename) {
  5.  
  6. $results['original'] = array(
  7. ...
  8.  
  9. return $results;
  10. }
  11. ?>

lub utworzyć results i potem przekazywać do funkcji przez referencję
Go to the top of the page
+Quote Post
gregi1
post
Post #3





Grupa: Zarejestrowani
Postów: 134
Pomógł: 0
Dołączył: 24.03.2007

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


Nie do spoks, mam ten return.... chodzi mi tylko o to ze nie moge przypisac sobie tej zmiennej bo ta tablica jest stringiem. Bo wywyluje sobie var_dump(od_tej_tablicy) i wyrzuca mi string. I wlasnie nie wiem co zrobic aby nie byla stringiem.


--------------------
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #4





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




  1. <?php
  2. function Yo()
  3. {
  4. //test values
  5. $Info[]='test1';
  6. $Info[]='test2';
  7. $Info['mime']='mime';
  8. $upload='test3';
  9.  
  10. $results['original'] = array(
  11. 'img_format' => 'original',
  12. 'img_width' => $Info[0],
  13. 'img_height' => $Info[1],
  14. 'img_mime' => $Info['mime'],
  15. 'img_path' => $upload
  16. );
  17. return $results;
  18. }
  19.  
  20. $arr=Yo();
  21. print_pre($arr); // tablica
  22. print $arr['original']['img_width']; // test1
  23. ?>


Działa normalnie - musisz mieć błąd gdzieś wcześniej, albo coś źle nam przepisałeś.


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.08.2025 - 20:36