niche Posted October 3, 2010 Share Posted October 3, 2010 I'm under the impression that the asterisk in this command includes every single column for that table.If so how would I rewrite this command to only include the two relevant columns (begin and end)?i.e.: $result = mysql_query("SELECT * FROM plan WHERE DATE('2010-10-05 00:00:00') BETWEEN DATE(begin) AND DATE(end)")Is there a W3school reference for this task of other ref if w3s not avail? Is the non-asterisk approach faster?Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted October 3, 2010 Share Posted October 3, 2010 You just separate the column names with commas. It's typically more efficient to only select what you need instead of everything. If you want to speed up the search you can also define indexes on each column in the WHERE clause. Link to comment Share on other sites More sharing options...
niche Posted October 3, 2010 Author Share Posted October 3, 2010 This works:$result = mysql_query("SELECT * FROM plan WHERE DATE('2010-10-10 00:00:00') BETWEEN DATE(begin) AND DATE(end)");This didn't:$result = mysql_query("SELECT begin, end FROM plan WHERE DATE('2010-10-10 00:00:00') BETWEEN DATE(begin) AND DATE(end)");Or, is there a conflict between specifying columns and using WHERE? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 3, 2010 Share Posted October 3, 2010 Not there, I don't see a reason why that wouldn't work. What do you mean it doesn't work, is there an error? Link to comment Share on other sites More sharing options...
niche Posted October 3, 2010 Author Share Posted October 3, 2010 Seems $results limited the returned array to the specified columns (I should have thought/know that) while the code I used also required additional keys to be present in the array. I added additional fields to be selected and Voila!Lessen learned. I think. Please let me know if not or if you have additional info. Link to comment Share on other sites More sharing options...
niche Posted October 3, 2010 Author Share Posted October 3, 2010 Thanks again for your help justsomeguy. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.