Azu Posted March 27, 2007 Share Posted March 27, 2007 Can someone please tell me if there is a faster way then if(mysql_result(timed_query("select count(*) from table where info='blah'",$DB),0)) to just see if a row exists that matches the where? I don't actually want to retrieve any data from it, just see if it exists.. Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/ Share on other sites More sharing options...
Azu Posted March 29, 2007 Author Share Posted March 29, 2007 Please is there a faster way? X_x Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-217138 Share on other sites More sharing options...
btherl Posted March 29, 2007 Share Posted March 29, 2007 I hope timed_query() does error checking. If you're finding that query is slow, you probably need an index on info. Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-217183 Share on other sites More sharing options...
Azu Posted March 30, 2007 Author Share Posted March 30, 2007 Timed_query is just a mysql_query except it adds time to a variable so I can see how long it took to run ^^ And what exactly is the best way to do an index? Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-218002 Share on other sites More sharing options...
fenway Posted April 4, 2007 Share Posted April 4, 2007 Post the EXPLAIN output... and SHOW CREATE TABLE Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-221190 Share on other sites More sharing options...
gluck Posted April 5, 2007 Share Posted April 5, 2007 Can someone please tell me if there is a faster way then if(mysql_result(timed_query("select count(*) from table where info='blah'",$DB),0)) to just see if a row exists that matches the where? I don't actually want to retrieve any data from it, just see if it exists.. You will have to retrieve data from the DB server. How would the scripting language know if the record exists or not. You could simply return a 1 or 0 instead of columns but yes you would have to return data. Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-222597 Share on other sites More sharing options...
Azu Posted April 6, 2007 Author Share Posted April 6, 2007 I mean is there a way to just ask the DB if the record exists or not, and the DB will just see if it exists and tell PHP if it exists, without actually reading the data in it (except for searching)? Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-222640 Share on other sites More sharing options...
dough boy Posted April 6, 2007 Share Posted April 6, 2007 query: SELECT id FROM table WHERE id = $id LIMIT 0,1 php: if(mysql_num_rows($result) > 0) do something. As stated above you have to return "something". Just make sure that something is as small as possible. Also make sure you have indexed your 'id' field. Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-222932 Share on other sites More sharing options...
gluck Posted April 6, 2007 Share Posted April 6, 2007 query: SELECT id FROM table WHERE id = $id LIMIT 0,1 php: if(mysql_num_rows($result) > 0) do something. As stated above you have to return "something". Just make sure that something is as small as possible. Also make sure you have indexed your 'id' field. You could choose this technique too. Again you will have to execute the query and the result will be returned to the scripting language. Quote Link to comment https://forums.phpfreaks.com/topic/44460-fast-select/#findComment-222945 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.