SQL counting

Discussion in 'Software' started by PeterK2003, Apr 21, 2006.

  1. PeterK2003

    PeterK2003 Private E-2

    ok i have a mySQL database which i strored visitors to my web page browser type in.(that sounds wierd to me so i hope it makes sense) What i want to do is count up how many of of each browser there is in the database. I know how to do some thing like this: select count(*) from database where BROWSER = "firefox 1.5". But i would like to make it automatic so when firefox 2.0 comes out it will pick it up by itself aka i don't want to have to hard code each browser in. Is there anyway to do this without iterating thought the whole database?
     
  2. Publius

    Publius Sergeant

    If I understand your question correctly, you just need to generalize your queries.

    Instead of:
    Use:
    As long as your db tracks the browser by the name first this should work fine. In fact, you can use the wild-card (%) on both sides of defined parameters, so as long as there is some part of a string that is specific to each browser you should be able to track the browser independent of the version that a visitor is using.

    Hope that helps.
     
  3. PeterK2003

    PeterK2003 Private E-2

    not quite--i want say firefox 1.5 and firefox 2.0 to show up as different browsers. What i want is something so that everytime a new browser comes out i don't have to hard code it into my page. So in english i want to say "hey database i want to know all the different browser that were used to view my page and i want to know how many times each was used." Does that make sense? I know exacltly what i want but it is a little hard to convey. Thanks for the help!
     
  4. covert215

    covert215 Private E-2

    i don't know the language, but i'll help clarify

    he wants to program it so that he does not have to set categories. when someone using firefox 1.5 visits the site, a category called firefox 1.5 will be started. if someone using xyz comes the site, a category for xyz will be started
     
  5. talk2bks

    talk2bks Private E-2

    If I understand correctly, you will need 1 table with 2 rows (1: browser type, 2: number of hits).

    1. in PHP set a variable that contains the name of the user's current browser.
    2. connect to the database and count how many times that name appears.
    3. if ( that browser != 0)
    {add one to the "row count" where browser = "current browser"};
    if (that browser = 0)
    {add a new row with "that browser"}

    4. to Display the information
    select all the rows
    number the affected rows
    write loop to display all the affected rows.
    echo out the names of all the browsers with the number of times it has been used.

    hope this helps
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds