Jump to content

Counting Rows Incrementally using a query via PHP


jdubwelch

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.