Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php + mysql + smarty] Problem z LIKE
sivyer
post
Post #1





Grupa: Zarejestrowani
Postów: 57
Pomógł: 0
Dołączył: 17.04.2002
Skąd: Wrocław

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


Witam,

Mam problem z ponizszym zapytaniem SQL, pierwsze 3 rekordy dla litery A wyciaga poprawnie, pozniej sie sypie z bledem o nieprawidlowym argumencie dla foreach(). Chce, aby kolejno z bazy zawodnikow wyciagane byly nazwiska zaczynajace sie na kolejne litery alfabetu i wyswietlane:

A
nazwiska na A

B
nazwiska na B

itd.

[php:1:efb69e4755]
<?php
$ar = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","R","S","T","U","V","W","X","Y","Z");
for( $i=0; $i<count($ar); $i++ ) {
$pl_loop[] = $i;
$smarty->assign("pl_loop", $pl_loop );
$smarty->assign("pl_litera", $ar );
$litera = $ar[$i];
$res = $db->get_results("SELECT playerID,pl_name,pl_surname FROM pro_players WHERE pl_surname LIKE '".$litera."%'");
foreach( $res as $player ) {
$pl_id[] = $player->playerID;
$pl[] = "$player->pl_surname, $player->pl_name";
}
// ...
?>
[/php:1:efb69e4755]

Probowalem:
[sql:1:efb69e4755]
SELECT playerID,pl_name,pl_surname FROM pro_players WHERE pl_surname LIKE '".$litera."%'
SELECT playerID,pl_name,pl_surname FROM pro_players WHERE pl_surname LIKE '$litera%'
SELECT playerID,pl_name,pl_surname FROM pro_players WHERE pl_surname REGEXP '^$litera.*'
SELECT playerID,pl_name,pl_surname FROM pro_players WHERE pl_surname REGEXP '^$litera.*'
SELECT playerID,pl_name,pl_surname FROM pro_players WHERE pl_surname REGEXP '^".$litera.".*'[/sql:1:efb69e4755]
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
sivyer
post
Post #2





Grupa: Zarejestrowani
Postów: 57
Pomógł: 0
Dołączył: 17.04.2002
Skąd: Wrocław

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


Zapomnialem dopisac. Obiekt $db to obiekt zwracany przez klase Ez_SQL.

Kod
$db->get_results



$db->get_results – get multiple row result set from the database (or previously cached results)



Description



array $db->get_results(string query / null [, OBJECT / ARRAY_A / ARRAY_N ] )



$db->get_row() gets multiple rows of results from the database based on query and returns them as a multi dimensional array. Each element of the array contains one row of results and can be specified to be either an object, associative array or numerical array. If no results are found then the function returns false enabling you to use the function within logic statements such as if.
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: 26.12.2025 - 13:05