|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Counting entries
Hey everybody.
Been working on my personal site lately and decided to add a section, 'Random Hotties'. The idea is to search the database for the number of entries, choose a random number and then show that image. My problem comes to counting how many entries are in the table I select. I'm sure it's some really simple MySQL command, but I'm too tired to see it in Google. Any help would be appreciated, and I might not reply back quickly, I will be out of town and away from computers for about a week.
__________________
My Site in the works |
|
#2
|
|||
|
|||
|
You can use this command to count the number of enteries:
$QUERY = mysql_query ( "SELECT * FROM TABLE" ); $COUNT = mysql_num_row( $QUERY ); |
|
#3
|
||||
|
||||
|
It'd probably be easier to do something like the following:
Code:
SELECT id FROM table ORDER BY RAND() LIMIT 1 This gives you a random id without requiring that you first do a count. |
|
#4
|
|||
|
|||
|
wouldnt this also work
PHP Code:
|
|
#5
|
||||
|
||||
|
Bruski, he's wanting a random number, not a count of the id in question. Also, conceivably, the row corresponding to a count of the id could possibly have been deleted, resulting in a display error. Mike_r's method is doable, but would require then taking the count and running a PHP function on it to get a random number not greater than that count. My query does all that work in one step.
|
|
#6
|
|||
|
|||
|
Excellent, thanks guys. I'll try when I get home.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Counting entries |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|