jdubwelch Posted June 29, 2008 Share Posted June 29, 2008 In phpMyAdmin my query works just fine, however when I paste it into my php code it doesn't work because I don't think I can set user defined variable in MySQL from a PHP query. There's got to be a way to do this. Can anyone help? Here's my MySQL query: set @rank = 0; SELECT FLOOR( (h.clicked / ( (UNIX_TIMESTAMP( ) - h.date_posted ) * 0.000277777778 )) *24) AS clicksPerHour, h.headline_id as id, @rank := ( @rank +1 ) AS rank FROM headlines h WHERE h.date_posted >= ( UNIX_TIMESTAMP( DATE_SUB( NOW( ) , INTERVAL 2 DAY ) ) ) ORDER BY `clicksPerHour` DESC LIMIT 0 , 20 Link to comment https://forums.phpfreaks.com/topic/112420-counting-rows-incrementally-using-a-query-via-php/ Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 I think you need to write a stored procedure or user-defined function to accomplish this but that's just a guess. Link to comment https://forums.phpfreaks.com/topic/112420-counting-rows-incrementally-using-a-query-via-php/#findComment-577201 Share on other sites More sharing options...
jdubwelch Posted June 29, 2008 Author Share Posted June 29, 2008 How does one do that? Link to comment https://forums.phpfreaks.com/topic/112420-counting-rows-incrementally-using-a-query-via-php/#findComment-577357 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 By searching Google and doing some reading/learning Link to comment https://forums.phpfreaks.com/topic/112420-counting-rows-incrementally-using-a-query-via-php/#findComment-577366 Share on other sites More sharing options...
fenway Posted July 1, 2008 Share Posted July 1, 2008 By searching Google and doing some reading/learning Not a particular helpful comment, I suppose. You have to issue your SET statement separately from your SELECT statement. Alternatively, you can use a CASE statement to declare your variable in-line to save the 2nd statement. Link to comment https://forums.phpfreaks.com/topic/112420-counting-rows-incrementally-using-a-query-via-php/#findComment-579101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.