rain13 Posted August 25, 2014 Share Posted August 25, 2014 Hello. I am stuck with sql. I want to insert row if it does not exist. This sql worked on localhost but does not work on other server. Any ideas? INSERT INTO hashtags SELECT DISTINCT 'test','2','1' FROM hashtags WHERE NOT EXISTS (SELECT * FROM hashtags WHERE Tag='test' AND ForumID = '2') Link to comment Share on other sites More sharing options...
justsomeguy Posted August 25, 2014 Share Posted August 25, 2014 It wouldn't insert any rows if the subquery is returning records, so if it's not inserting rows then the subquery is returning records. Link to comment Share on other sites More sharing options...
niche Posted August 25, 2014 Share Posted August 25, 2014 mysqli_num_rows() will tell you how many rows you selected http://www.w3schools.com/php/func_mysqli_num_rows.asp Link to comment Share on other sites More sharing options...
rain13 Posted August 25, 2014 Author Share Posted August 25, 2014 Tnx.Btw how much slowert it is to use *_num_rows() and *_query() instead of creating single query? would it become problem with greater quantities of visitors? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 25, 2014 Share Posted August 25, 2014 I'm not sure what you're asking. What is "creating single query?" Link to comment Share on other sites More sharing options...
niche Posted August 26, 2014 Share Posted August 26, 2014 I'm showing you how to debug your query. mysqli_num_rows() simple lets you check the part of your query that doing the selection. Obviously, no selection means no insert. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now