|
|||||||
| SQL For all Structured Query Language, and general database questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hello.
** i postet this on the php forum, but i think it should be here on SQL ** let's say i want to add a row to a table called "todaypics" with this 3 columns: | picnum | imagename | todayhits | and i do this: PHP Code:
| 72 | somepicturename.jpg | 35 | witn no problem. but if the row was already on the tablewith this data:... | 72 | somepicturename.jpg | 34 | ...how sohuld be the query to avoid the duplicate error and update the column "todayhits" value to 35?? ------------------------------------------------------------------ other situation i have: on the other table named "pics", i have hundreds of rows. the columns are: | picnum | imagename | hits | if i want to display the 1st 50 images sort by hits i do this: PHP Code:
if 50 images are to be displayed, but only 25 has some hits, the rest of the images are ordered by picnum.. is there a way to ignore the rows when the "hits" value is zero?
|
|
#2
|
||||
|
||||
|
Code:
If NOT EXISTS (Select imagename from todaypics where imagename = 'somepicturename.jpg') INSERT INTO todaypics (picnum, imagename, todayhits) VALUES('72', 'somepicturename.jpg', '35')
Code:
SELECT TOP 50 * FROM pics ORDER BY hits desc |
|
#3
|
||||
|
||||
|
Thanks yamaharuss...
i'll try it tonight and will let you know. |
|
#4
|
|||
|
|||
|
Keep in mind you're using MySQL and to ignore the pics w/ 0 hits
Code:
SELECT * FROM pics WHERE hits > 0 ORDER BY hits desc LIMIT 50 |
|
#5
|
||||
|
||||
|
yamaharuss:
i tried this: PHP Code:
PHP Code:
----------------------------------------------- ssystems: PHP Code:
PHP Code:
![]() thank you both... ![]() KnightMan |
|
#6
|
|||
|
|||
|
I see your hits column was a varchar
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|