Power4ik Posted November 15, 2010 Report Share Posted November 15, 2010 Kas man ir nepareizi? Neatkarīgi no tā vai rezūltāts ir vai nav, man nerāda neko, bet ja if ($result2 == 1) {...} izņem ārā, tad man pie esoša rezūltāta viss ok, to rāda, bet ja dati nav vēl pievienoti datubāzē rāda kļūdu, kā to var izlabot? mysql_query('set names utf8'); mysql_query('set characters utf8'); $carID = $_GET['rek']; echo "Privāti Rēķini<br/>"; $qeryjob = "SELECT car.IDcar, car.IDclient, car.carNr, car.engine, car.year, car.chasyNr, car.l, car.notes, car.model, car.marka, job.IDjob, job.IDklients, job.IDcar, job.IDstaffPien, job.dateIn, job.dateOut, job.planDescr, job.realDescr, job.many, job.status, client.IDclient AS KlientaID, client.name, client.surname, client.address, client.phone, client.islegal, client.email, client.bank, client.notes, client.temp1, client.temp2 ". "FROM car LEFT JOIN job ". "ON car.IDcar = job.IDcar LEFT JOIN client ON car.IDclient = client.IDclient WHERE car.IDcar = ".$carID." and job.type = 1"; $result2 = mysql_query($qeryjob) or die(mysql_error()); if ($result2 == 1) { while($row5 = mysql_fetch_array($result2)){ echo " "; $sql = "SELECT * FROM job WHERE IDcar='$carID' and type='1'"; $result = mysql_query($sql) or die(mysql_error()); } while($row = mysql_fetch_array($result)){ echo "<a href='inc/view_rek.php?id=".$row['IDjob']."' target='_blank'>".$row['dateIn']."</a>| <a href='?edit_rek=".$carID."&job_id=".$row['IDjob']."'>Labot</a> | <a href='?del_rek=".$row['IDjob']."'>Dzēst</a><br/>"; }} Quote Link to comment Share on other sites More sharing options...
briedis Posted November 15, 2010 Report Share Posted November 15, 2010 Kāpēc tu domā, ka mysql_query var agriezt vērtību 1 ? RTFM: http://php.net/manual/en/function.mysql-query.php Quote Link to comment Share on other sites More sharing options...
Power4ik Posted November 15, 2010 Author Report Share Posted November 15, 2010 Kāpēc tu domā, ka mysql_query var agriezt vērtību 1 ? RTFM: http://php.net/manual/en/function.mysql-query.php Tādā veidā es domāju viņam pateikt, ka ja kautkas ir ierakstīts tad aiziet viss kas ir, bet ja nekā nav tad neko narāda. Kā to varētu izdarīt? K.ko nesaprotu :S Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 15, 2010 Report Share Posted November 15, 2010 Lūk šādi! =) $query = mysql_query(" ... ") or exit( mysql_error() ); if( mysql_num_rows( $query ) === 0 ) { echo 'Nav ierakstu!'; } Quote Link to comment Share on other sites More sharing options...
Power4ik Posted November 15, 2010 Author Report Share Posted November 15, 2010 (edited) Lūk šādi! =) $query = mysql_query(" ... ") or exit( mysql_error() ); if( mysql_num_rows( $query ) === 0 ) { echo 'Nav ierakstu!'; } Viss strādā, paldies !!! :)) Edited November 15, 2010 by Power4ik Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted November 16, 2010 Report Share Posted November 16, 2010 Nu kamdēļ ir jāraksta tik tizli, tak var arī sakārtot. <?php $db = mysql_query("SELECT * FROM tabula LIMIT 1"); if(@mysql_num_rows($db)){ echo "Ir atgriezti rezultati"; }else{ echo "Nav atgriezti rezultati"; } ?> izmantojam @mysql_num... lai nebūtu kļūdu paziņojums gadijumā ja atgriezti 0 rezultāti. 2 metode ir <?php $db = mysql_query("select count(id) as cnt from tabula"); $db = mysql_fetch_object($db); if($db->cnt>0){ echo "Ir atgriezti {$db->cnt} rezultati"; }else{ echo "Nav atgriezti rezultati"; } ?> Quote Link to comment Share on other sites More sharing options...
indoom Posted November 16, 2010 Report Share Posted November 16, 2010 ja būs 0 rezultātu, tad nebūs nekāds kļūdas paziņoums, bet tikai, ja būs kļūdains querijs, jo tad $db būs false, kas nav mysql resurss. Tāpēc labāk ir $db = mysql_query("SELECT 1"); if ($db && mysql_num_rows($db)) // ir rindas Lasam manuāli Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 16, 2010 Report Share Posted November 16, 2010 EdgarsA, kods ar "@" noteikti būs ne-tizlāks... Quote Link to comment Share on other sites More sharing options...
mefisto Posted November 16, 2010 Report Share Posted November 16, 2010 daGrevis, jebkurš koda fragments, kur tiek izmnatots @ vienmēr būs tizlāks. Šāda kļūdu apspiešana ir relatīvi lēns process. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 16, 2010 Report Share Posted November 16, 2010 Pietam, EdgarsA, kā teica Mans draugs... Kamēr kods ir drošs, ātrs un viegli Tev saprotams, tikmēr kods Tev derēs. =) P.S. Nu apmēram tā... x.X Quote Link to comment Share on other sites More sharing options...
cilveks Posted November 16, 2010 Report Share Posted November 16, 2010 Un kļūdu slēpšana galīgi nav labais tonis. Uztaisi papildu pārbaudes, bet ne slēp kļūdas. Tas kurš labos šādu kodu, nebūs laimīgs. Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted November 17, 2010 Report Share Posted November 17, 2010 <?php error_reporting(E_ALL); $db = mysql_query("select * from tabula"); if(mysql_num_rows($db)){ $db = mysql_fetch_object($db); } ?> Bus kludas pazinojums gadijuma ja db atrriezis 0 Quote Link to comment Share on other sites More sharing options...
indoom Posted November 17, 2010 Report Share Posted November 17, 2010 http://lv.php.net/manual/en/function.mysql-query.php "For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. " Būs kļūda, ja tāda tabula "tabula" neeksistē, nejau, ka neviena rinda neatrodas. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.