Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Mysql + php, składnia
ardex
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 11.02.2015

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


Siemka, proszę o pomoc ze składnią SQL.

Otóż, po kolei. Mam tabelę z dwoma kolumnami, var i cont. Chciałbym po pobraniu całej tabeli, aby na przykład $wynik['var'] zawierał 'cont' z tego samego wiersza.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
Pyton_000
post
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


No dobrze, a teraz co masz i z czym masz problem.
Go to the top of the page
+Quote Post
ardex
post
Post #3





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 11.02.2015

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


  1. public static function GetVariables()
  2. {
  3. require 'config.php';
  4. $qeGetVariables = WCore::$__DbConnection->Query('SELECT content AS variable FROM `variables`');
  5. $result = WCore::$__DbConnection->FetchAssocs($qeGetVariables);
  6.  
  7. return $result;
  8. }


I utknąłem, bo na pewno coś spieprzyłem w składni SQL

A i print_r daje mi takowe coś:

  1. (
  2. [0] => Array
  3. (
  4. [variable] => słowa, kluczowe, i, inne
  5. )
  6.  
  7. [1] => Array
  8. (
  9. [variable] => Tytuł
  10. )
  11.  
  12. )


Ten post edytował ardex 12.02.2015, 11:36:36
Go to the top of the page
+Quote Post
Pyton_000
post
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Przecież jest ok. Masz 2 wiersze więc musisz to w foreach przelecieć
Go to the top of the page
+Quote Post
ardex
post
Post #5





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 11.02.2015

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


Troszku pozmieniałem ale nadal nie wiem jak to zrobić aby było tak jak ja chcę:
  1. SELECT content,variable FROM `variables`

  1. foreach ($pGetVariables as $pageVariables)
  2. {
  3. $pageVariables[$pGetVariables['variable']] = $pGetVariables['content'];
  4. }


I nie działa (IMG:style_emoticons/default/thumbsupsmileyanim.gif)

Założenie miało być takie że:

$tabela['zawartość_variable'] = 'zawartość_content';
Go to the top of the page
+Quote Post
Pyton_000
post
Post #6





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


  1. $vars = GetVariables();
  2.  
  3. foreach($var as $variable => $value){
  4. echo "$variable -> $value".PHP_EOL;
  5. }
Go to the top of the page
+Quote Post
ardex
post
Post #7





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 11.02.2015

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


Niestety dalej nie to:

  1. <b>Notice</b>: Array to string conversion in <b>C:\xampp\htdocs\index.php</b> on line <b>19</b><br />
  2. 0 -> Array
  3. <br />
  4. <b>Notice</b>: Array to string conversion in <b>C:\xampp\htdocs\index.php</b> on line <b>19</b><br />
  5. 1 -> Array
Go to the top of the page
+Quote Post
Pyton_000
post
Post #8





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


  1. foreach($var as $value){
  2. var_dump($value);die();
  3. }
Go to the top of the page
+Quote Post
ardex
post
Post #9





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 11.02.2015

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


Doszedłem jakoś do końca, więcej zmiennych trzeba dać (IMG:style_emoticons/default/smile.gif)

  1. $pGetVariables = WCore::GetVariables();
  2.  
  3. foreach($pGetVariables as $value)
  4. {
  5. $pageVariables[$value['variable']]=$value['content'];
  6. }
  7. print_r($pageVariables);


Pyton_000, dzięki za pomoc!

Ten post edytował ardex 12.02.2015, 18:12:25
Go to the top of the page
+Quote Post

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: 21.12.2025 - 20:18