ray Posted January 17, 2008 Report Posted January 17, 2008 (edited) kāds ir visātrākais kods, lai iegūtu tikai vienu rindu no datubāzes? piem. šādas vaicājumam: mysql_query("SELECT max(id) FROM tabula"); parasti izmantoju while, bet nu nezinu vai tas ir labākais variants. Edited January 17, 2008 by ray
Delfins Posted January 17, 2008 Report Posted January 17, 2008 tur jau arī būs viena rinda. Vai select id from tabul order by id desc LIMIT 1
andrisp Posted January 17, 2008 Report Posted January 17, 2008 (edited) Delfins, viņš laikam domāja PHP kodu. Ja man vajag vienu vērtību tikai, tad: list($max) = mysql_fetch_row(mysql_query("SELECT max(id) FROM tabula")); Un while noteikti nav labākais veids. Tas pat nav normālds veids. Tipa šitā dari ? $result = mysql_query("SELECT max(id) FROM tabula"); while($row = mysql_fetch_row($result)) { $max = $row[0]; } Tā galīgi nav labi. Edited January 17, 2008 by andrisp
ray Posted January 17, 2008 Author Report Posted January 17, 2008 (edited) nepareizi saprati jautājumu. Man vajag izgūt vienu rindu. ir piem. šāds kods: $sql = mysql_query("SELECT max(id) as max FROM tabula"); while($row = mysql_fetch_array($sql)) { $max = $row["max"]; } echo $max; vai šim kodam ir labāks variants? Edited January 17, 2008 by ray
Paulinjsh Posted January 17, 2008 Report Posted January 17, 2008 nevar vienkārši ? mysql_result(mysql_query($query), 0, 0);
andrisp Posted January 17, 2008 Report Posted January 17, 2008 Interesanti, nebija piefiksējis iepriekš šādu funkciju.
Recommended Posts