RE: Re: question about columns in a table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As Pete has said, the design of your database is bad.

The table should look like this :-

-----------------------
| page         | hits | 
|=====================|
| aboutus.php  |  6   |
| contactus.php|  4   |
| links.php    |  8   |
-----------------------

When someone loads a page, do a "SELECT hits FROM visits WHERE page =
'$pagename';"

If the number of rows returned from the query is zero, then the page doesn't
exist in the table, so you can create a new row and set the hits value to 1.

If the number of rows is greater than zero, then add 1 to the number of hits
returned and update the row with the new value.

Your "SELECT SUM(hits) FROM visits;" will then work properly.

Robert.

-----Original Message-----
From: php-objects@xxxxxxxxxxxxxxx [mailto:php-objects@xxxxxxxxxxxxxxx] On
Behalf Of sudhakar
Sent: 05 November 2007 01:06
To: php-objects@xxxxxxxxxxxxxxx
Subject: Re:  Re: question about columns in a table

I tried with the + sign following was the message=
"Resource id #3"

The page does not show the numeric figure. please
advice how to go about with this.

--- Pete <cgrp@xxxxxxxxxxxx> wrote:

> In message <fglirt+bu5a@xxxxxxxxxxx>, Sudhakar
> <finals27@xxxxxxxxx>
> writes
> >as suggested not to create a field which would add
> the numeric 
> >values in the tables, i used the select sum query
> however it does 
> >not work.
> >The table has 2 fields defined as aboutus &
> contactus as integer. In 
> >this case as i will be updating the columns every
> time there is a 
> >visit, this table will only have 1 row at all
> times. Is it because 
> >of this the query is not being executed.
> >
> >$count="SELECT SUM(aboutus, contactus) FROM
> visits"; 
> 
> SELECT aboutus + contactus FROM visits;
> 
> If you think of it like a spreadsheet, SUM works
> *down* the columns, and
> you need '+' to go across.
> 
> -- 
> Pete Clark
> 
> Sunny Andalucia
> http://hotcosta.com/Andalucia.Spain
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux