ray Posted January 17, 2008 Report Share 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 Link to comment Share on other sites More sharing options...
Delfins Posted January 17, 2008 Report Share Posted January 17, 2008 tur jau arī būs viena rinda. Vai select id from tabul order by id desc LIMIT 1 Link to comment Share on other sites More sharing options...
andrisp Posted January 17, 2008 Report Share 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 Link to comment Share on other sites More sharing options...
ray Posted January 17, 2008 Author Report Share 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 Link to comment Share on other sites More sharing options...
ray Posted January 17, 2008 Author Report Share Posted January 17, 2008 ok, paldies ;) Link to comment Share on other sites More sharing options...
Paulinjsh Posted January 17, 2008 Report Share Posted January 17, 2008 nevar vienkārši ? mysql_result(mysql_query($query), 0, 0); Link to comment Share on other sites More sharing options...
andrisp Posted January 17, 2008 Report Share Posted January 17, 2008 Interesanti, nebija piefiksējis iepriekš šādu funkciju. Link to comment Share on other sites More sharing options...
Recommended Posts