FT3 Posted November 30, 2010 Report Share Posted November 30, 2010 vjg parbaudes kodu pirms ievietošanas datubaze parbaudaja tads nosaukums(field) jau eksiste - nepievieno ja nosaukums(field) neeksiste tad veidojas mysql insert Cerams sapratat :) Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 30, 2010 Report Share Posted November 30, 2010 if( mysql_num_rows( $query ) !== 0 ) { // Cool stuff comes here... ^__^ } Quote Link to comment Share on other sites More sharing options...
bubu Posted November 30, 2010 Report Share Posted November 30, 2010 Nevis mysql_num_rows, bet gan SELECT COUNT(*) ... Quote Link to comment Share on other sites More sharing options...
FT3 Posted November 30, 2010 Author Report Share Posted November 30, 2010 nejau taja zina :) piem table sastav no ================= id homepage ip ================= es padodu homepage=http://nosukums.lv posts viņš parbauda , ja taja homepage tabula jau ir http://nosukums.lv viņš neko nedara :) Quote Link to comment Share on other sites More sharing options...
mefisto Posted November 30, 2010 Report Share Posted November 30, 2010 Nuuuu ... uzliec lai 'homepage' ieraksi ir UNIQUE ( sql pusē ). Quote Link to comment Share on other sites More sharing options...
FT3 Posted November 30, 2010 Author Report Share Posted November 30, 2010 what ? ^_^ Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted November 30, 2010 Report Share Posted November 30, 2010 (edited) a nevar vienkarshi insert ignore ? bet nu .. $query = mysql_fetch_object(mysql_query("select count(id) as cnt from tabula where homepage='http://www.php.lv'")); if($query->cnt == 0){ mysql_query("insert into table (homepage,ip) values('http://www.php.lv','127.0.0.1')"); } Edited November 30, 2010 by EdgarsA Quote Link to comment Share on other sites More sharing options...
FT3 Posted November 30, 2010 Author Report Share Posted November 30, 2010 $adress = $_SERVER['HTTP_HOST']; $link = $_SERVER['PHP_SELF']; $query = mysq_fetch_object(mysql_query("select count(id) as cnt from clients where adress='$adress'")); if($query->cnt == 0){ mysql_query("insert into clients (adress,link) values ('$adress','$link')"); } Fatal error: Call to undefined function mysq_fetch_object() Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted November 30, 2010 Report Share Posted November 30, 2010 $adress = $_SERVER['HTTP_HOST']; $link = $_SERVER['PHP_SELF']; $query = mysq_fetch_object(mysql_query("select count(id) as cnt from clients where adress='$adress'")); if($query->cnt == 0){ mysql_query("insert into clients (adress,link) values ('$adress','$link')"); } ak dievs.. ak dievs.. bērniņ mīļo, ēd tak no rokām... cerēju jau ka pats tiksi galā ar šo. Quote Link to comment Share on other sites More sharing options...
nikidijs Posted December 1, 2010 Report Share Posted December 1, 2010 Varbūt šādi... $jau_ir=mysql_fetch_array(mysql_query("SELECT * FROM clients WHERE adress=$adress OR link=$link")); if (!$jau_ir){ mysql_query("INSERT INTO clients(adress,link) VALUES('$adress','$link')"); } else { echo"Šāds lauks jau eksistē !"; } Quote Link to comment Share on other sites More sharing options...
Maris-S Posted December 1, 2010 Report Share Posted December 1, 2010 Paskaties šo te: http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html domāju ka varēsi pielāgot, ja tas Tev derēs. 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.