Jump to content
php.lv forumi

Php HELP


Power4ik

Recommended Posts

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/>";

}}

Link to comment
Share on other sites

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";
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...