Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Zmiana formatu arraya
kam821
post
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 1
Dołączył: 24.10.2009

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


Witam serdecznie.
Zwracam się do was z małym pytankiem.
Potrzebuję zamienić jeden array będący wynikiem zapytania sql, dajmy na przykład taki przypadek:
użyty tak:
Cytat
$row = $db->sql_fetchrow($result);
for($i = 0; $i < count($row); $i++)
{
$user_id = $row['user_id']
$username = $row['username'];
}

Potrzeba mi zamienić taki array, aby można go było użyć tak - cachuje wszystkich userów, a potem gdy chce pobrać username jednego to wpisuje:
Cytat
$user_id = intval($_GET['userid']);
$username = $users[$user_id]['username']; // zmienna array $users to cała zacachowana baza.

Z góry dziękuję
Pozdrawiam.

Ten post edytował kam821 24.10.2009, 23:31:54
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kam821
post
Post #2





Grupa: Zarejestrowani
Postów: 14
Pomógł: 1
Dołączył: 24.10.2009

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


  1. $sql = "SELECT t.topic_title, t.topic_id, t.forum_id
  2. FROM " . TOPICS_TABLE . " t
  3. WHERE t.forum_id = $forum_id
  4. AND t.topic_moved_id = 0
  5. AND next_topic = (t.topic_last_post_id < $topic_last_post_id
  6. ORDER BY t.topic_last_post_id DESC
  7. LIMIT 1)
  8. OR t.forum_id = $forum_id
  9. AND t.topic_moved_id = 0
  10. AND next_topic = (t.topic_last_post_id > $topic_last_post_id
  11. ORDER BY t.topic_last_post_id ASC
  12. LIMIT 1)";


Przykładowy błąd:

Cytat
SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY t.topic_last_post_id DESC LIMIT 1) OR t.forum_id = 154 AND t.t' at line 6

SELECT t.topic_title, t.topic_id, t.forum_id FROM phpbb_topics t WHERE t.forum_id = 154 AND t.topic_moved_id = 0 AND next_topic = (t.topic_last_post_id < 13563 ORDER BY t.topic_last_post_id DESC LIMIT 1) OR t.forum_id = 154 AND t.topic_moved_id = 0 AND next_topic = (t.topic_last_post_id > 13563 ORDER BY t.topic_last_post_id ASC LIMIT 1)


Ten post edytował kam821 25.10.2009, 11:35:45
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: 22.12.2025 - 16:58