ecabrera Posted October 21, 2013 Share Posted October 21, 2013 OK so im using a database from a website that lets you use their embed videos the database contains the name, embed videos , time , keywords , category . The time is a varchar type because when i opened the csv file it wasn't saved as a timestamp it was saved like this '324 sec' , '524 sec' so i made it a varchar what i want to do is make it so that when user click the option to see videos that are 10 mins or longer the can but it doesnt work here is the sql i used SELECT * FROM `videos` WHERE `time` > '600 sec' Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2013 Share Posted October 21, 2013 1. BACK UP YOUR TABLE 2. Run this update query to strip the " sec" from the time column values. UPDATE videos SET time = SUBSTRING_INDEX(time,' ',1); 3 Now change the column type to INT with ALTER TABLE `videos` CHANGE COLUMN `time` `time` INT NULL DEFAULT NULL ; Your query should now work if all the times were in the same format "999 sec"; Quote Link to comment Share on other sites More sharing options...
ecabrera Posted October 21, 2013 Author Share Posted October 21, 2013 (edited) THANK YOU 1. BACK UP YOUR TABLE 2. Run this update query to strip the " sec" from the time column values. UPDATE videos SET time = SUBSTRING_INDEX(time,' ',1); 3 Now change the column type to INT with ALTER TABLE `videos` CHANGE COLUMN `time` `time` INT NULL DEFAULT NULL ; Your query should now work if all the times were in the same format "999 sec"; know i tried to add more option to the sql tags are the keywords im trying to make it so that the user gets videos that have those keywords and or above 10min SELECT * FROM `videos` WHERE `time` > '600' AND `tags` LIKE '%play%' OR `tags` LIKE '%soccer%' OR `tags` LIKE '%ronaldo%' but thats when it gives me different time is it the fact that im using AND Edited October 21, 2013 by ecabrera Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted October 21, 2013 Solution Share Posted October 21, 2013 Use ( )s SELECT * FROM `videos` WHERE `time` > '600' AND (`tags` LIKE '%play%' OR `tags` LIKE '%soccer%' OR `tags` LIKE '%ronaldo%') Quote Link to comment Share on other sites More sharing options...
ecabrera Posted October 21, 2013 Author Share Posted October 21, 2013 Thank you so much 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.