cipcaps Posted November 14, 2009 Report Share Posted November 14, 2009 Sakiet vai tas ir iespējams, dabūt AND + OR vienā sql query. Paskaidroju. mysql_query("SELECT * FROM `tabula` WHERE `user` = '12' AND `name` LIKE 'kass%' OR `sname` LIKE 'kass%' OR `email` LIKE 'kass%'"); Šis sql tiek izmantots lai atgrieztu : Info par lietotāju kuram : 1.ID ir 12 UN 2. name sākas ar 'kass' VAI 3. sname sākas ar 'kass' VAI 4. email sākas ar 'kass' Problēma rodas tajā, ka ja ir lietotājs ir ID 543(nevis 12) kuram name/sname/email sākas ar 'kass' tiek atgriezts info par šo lietotāju nevis 'Nav info par useri'. ID ir mysqlrow int(10) Quote Link to comment Share on other sites More sharing options...
briedis Posted November 14, 2009 Report Share Posted November 14, 2009 Un kā php raksti and/or kopā? :) Vai gadījumā, atbilde nebūs - iekavas? Quote Link to comment Share on other sites More sharing options...
cipcaps Posted November 14, 2009 Author Report Share Posted November 14, 2009 $res = mysql_query("SELECT * FROM `tabula` WHERE `user` = '12' AND `name` LIKE 'kass%' OR `sname` LIKE 'kass%' OR `email` LIKE 'kass%'"); $arr = mysql_fetch_array($res); $name = $arr['name']; echo 'Lietotājs '.$name; Šādi arī rakstu(aptuveni) Quote Link to comment Share on other sites More sharing options...
briedis Posted November 14, 2009 Report Share Posted November 14, 2009 Nu, saliec vajadzīgajās vietās iekavas... vai tiešām tas jādara tavā vietā? :) Quote Link to comment Share on other sites More sharing options...
cipcaps Posted November 14, 2009 Author Report Share Posted November 14, 2009 (edited) OK, mysql_query salikt iekavas ja, ok paprovēšu. Paldies Edited November 14, 2009 by cipcaps 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.