Jump to content

Row numbering help???


New Coder

Recommended Posts

Hello All,

 

I have a comments table:

 

ID int autoincrement,

Name varchar(50),

Comments varchar(2000),

Safe char(1) default (N).

 

Select * from comments;

 

ID      Name                Comment            Safe

1 Joe Bloggs Comment 1 Y

2 John Doe            Comment 2 N

3 Jane Doe Comment 3 Y

4 Joe Bloggs Comment 4 Y

5 John Doe Comment 5 Y

6 Joe Bloggs Comment 6 Y

 

I am using the following query to output 4 random site comments that has been approved and set as safe.

 

SELECT * FROM tbl_dyk where safe=’Y’ ORDER BY RAND() limit 4

 

ID      Name                  Comment          Safe

1 Joe Bloggs Comment 1 Y

3 Jane Doe Comment 3 Y

4 Joe Bloggs Comment 4 Y

6 Joe Bloggs Comment 6 Y

 

Which works a treat.

 

What I also need is to assign the rows a new number from 1-4 like so:

 

ID      Name                  Comment          Safe        Row_num

1 Joe Bloggs Comment 1 Y 1

3 Jane Doe Comment 3 Y 2

4 Joe Bloggs Comment 4 Y 3

6 Joe Bloggs Comment 6 Y 4

 

Is this possible?

Many Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/187394-row-numbering-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.