Strange query problem php/mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • smilesinblues@gmail.com

    Strange query problem php/mysql

    Hi all,

    I have a table with a lot of songs. All songs have a field called hits.
    Everytime a song page is seen hits becomes hit++, everything smooth
    going.

    I also have a page where I run the query

    select * from table order by hits DESC

    No error all fine but songs that have 1000+ hits is not shown above
    songs with 50 hits...until... they cross 1500.

    This is a strange problem.

    the page is here http://tinyurl.com/b8qr8

    all songs that cross 100+ hits disapear...but they are in the DB and
    the hits are going up but they wont show up on this page until they
    cross one more digit.

    Please help is something wrong with my query.

    I use mysql 4.022 with php 4.3.11

    Thanks once again

    Bye

  • Alvaro G Vicario

    #2
    Re: Strange query problem php/mysql

    *** smilesinblues@g mail.com wrote/escribió (4 May 2005 23:05:44 -0700):[color=blue]
    > Please help is something wrong with my query.[/color]

    Yep, there's probably a problem with your code.


    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- http://bits.demogracia.com - Mi sitio sobre programación web
    -- Don't e-mail me your questions, post them to the group
    --

    Comment

    • smilesinblues@gmail.com

      #3
      Re: Strange query problem php/mysql

      Hi,

      thanks but where is the help??

      Bye

      Comment

      • deja@2404.co.uk

        #4
        Re: Strange query problem php/mysql

        Can you post the code where you loop and output the results?

        Steve


        smilesinbl...@g mail.com wrote:[color=blue]
        > Hi all,
        >
        > I have a table with a lot of songs. All songs have a field called[/color]
        hits.[color=blue]
        > Everytime a song page is seen hits becomes hit++, everything smooth
        > going.
        >
        > I also have a page where I run the query
        >
        > select * from table order by hits DESC
        >
        > No error all fine but songs that have 1000+ hits is not shown above
        > songs with 50 hits...until... they cross 1500.
        >
        > This is a strange problem.
        >
        > the page is here http://tinyurl.com/b8qr8
        >
        > all songs that cross 100+ hits disapear...but they are in the DB and
        > the hits are going up but they wont show up on this page until they
        > cross one more digit.
        >
        > Please help is something wrong with my query.
        >
        > I use mysql 4.022 with php 4.3.11
        >
        > Thanks once again
        >
        > Bye[/color]

        Comment

        • Sadara

          #5
          Re: Strange query problem php/mysql

          smilesinblues@g mail.com wrote:[color=blue]
          > Hi all,
          >
          > I have a table with a lot of songs. All songs have a field called hits.
          > Everytime a song page is seen hits becomes hit++, everything smooth
          > going.[/color]
          what's the data type of the field 'hits'?

          <snip />

          s

          Comment

          • Alvaro G Vicario

            #6
            Re: Strange query problem php/mysql

            *** smilesinblues@g mail.com wrote/escribió (5 May 2005 01:36:11 -0700):[color=blue]
            > thanks but where is the help??[/color]

            My excuses... That was all the help I could provide with the information I
            have. You posted a link to the resulting HTML and all I can tell you is
            that your HTML is fine, the problem must be in the underlying code (either
            PHP or SQL).

            --
            -- Álvaro G. Vicario - Burgos, Spain
            -- http://bits.demogracia.com - Mi sitio sobre programación web
            -- Don't e-mail me your questions, post them to the group
            --

            Comment

            • smilesinblues@gmail.com

              #7
              Re: Strange query problem php/mysql

              Hi,
              Forgive me for not giving the php code.

              the datatype for hits is varchar(10).

              The query is :

              $query_mostwant ed = "SELECT * FROM table ORDER BY hits DESC";

              I repeat the <tr> using:

              <?php do { ?>
              <tr>
              <td><?php echo $serialid++; ?></td>
              <td><?php echo $row_mostwanted['song']; ?> - <?php echo
              $row_mostwanted['hits']; ?></td>
              <td><?php echo $row_mostwanted['artist']; ?></td>
              </tr>
              <?php } while ($row_mostwante d = mysql_fetch_ass oc($mostwanted) ); ?>


              Please help and let me know if you need any more info.

              Thanks once again
              Bye

              Comment

              • smilesinblues@gmail.com

                #8
                Re: Strange query problem php/mysql

                Hi,

                I am so sorry but isnt there anyone who can help?

                Thanks
                Bye

                Comment

                • Jan Pieter Kunst

                  #9
                  Re: Strange query problem php/mysql

                  smilesinblues@g mail.com wrote:[color=blue]
                  > Hi,
                  > Forgive me for not giving the php code.
                  >
                  > the datatype for hits is varchar(10).
                  >
                  > The query is :
                  >
                  > $query_mostwant ed = "SELECT * FROM table ORDER BY hits DESC";
                  >
                  > I repeat the <tr> using:
                  >
                  > <?php do { ?>
                  > <tr>
                  > <td><?php echo $serialid++; ?></td>
                  > <td><?php echo $row_mostwanted['song']; ?> - <?php echo
                  > $row_mostwanted['hits']; ?></td>
                  > <td><?php echo $row_mostwanted['artist']; ?></td>
                  > </tr>
                  > <?php } while ($row_mostwante d = mysql_fetch_ass oc($mostwanted) ); ?>
                  >
                  >
                  > Please help and let me know if you need any more info.
                  >
                  > Thanks once again
                  > Bye
                  >[/color]


                  I find that style of mixing of code and HTML rather unreadable. How
                  about this:

                  <?php

                  $query_mostwant ed = "SELECT * FROM table ORDER BY hits DESC";
                  $result_mostwan ted = mysql_query($qu ery_mostwanted) ;
                  $serialid = 1;

                  while ($row_mostwante d = mysql_fetch_ass oc($result_most wanted)) {
                  echo
                  "<tr><td>$seria lid</td><td>{$row_mo stwanted['hits']}</td><td>{$row_mo stwanted['artist']}</td></tr>\n";
                  $serialid++;
                  }

                  JP

                  --
                  Sorry, <devnull@cauce. org> is a spam trap.
                  Real e-mail address unavailable. 5000+ spams per month.

                  Comment

                  • smilesinblues@gmail.com

                    #10
                    Re: Strange query problem php/mysql

                    Hi,
                    I can't belive i can be such a big dump.....i just had to change the
                    varchar(10) to int. thats it. its working now.

                    thanks to everyone who tool out time.

                    Thanks

                    Comment

                    • Alvaro G Vicario

                      #11
                      Re: Strange query problem php/mysql

                      *** smilesinblues@g mail.com wrote/escribió (5 May 2005 06:38:19 -0700):[color=blue]
                      > <?php do { ?>
                      > <tr>
                      > <td><?php echo $serialid++; ?></td>
                      > <td><?php echo $row_mostwanted['song']; ?> - <?php echo
                      > $row_mostwanted['hits']; ?></td>
                      > <td><?php echo $row_mostwanted['artist']; ?></td>
                      > </tr>
                      > <?php } while ($row_mostwante d = mysql_fetch_ass oc($mostwanted) ); ?>[/color]

                      You first use $row_mostwanted before giving it any value, so in the first
                      iteration its contents are unpredictable. Fix this first.

                      Also, it's a good idea to always use htmlspecialchar s() to output text into
                      HTML, otherwise you may face problems when your strings contain certain
                      chars.


                      --
                      -- Álvaro G. Vicario - Burgos, Spain
                      -- http://bits.demogracia.com - Mi sitio sobre programación web
                      -- Don't e-mail me your questions, post them to the group
                      --

                      Comment

                      • Alvaro G Vicario

                        #12
                        Re: Strange query problem php/mysql

                        *** smilesinblues@g mail.com wrote/escribió (5 May 2005 20:37:55 -0700):[color=blue]
                        > I am so sorry but isnt there anyone who can help?[/color]

                        I've never understood why people post messages like this. This is not a pay
                        help desk where operators spend eight hours a day helping customers (or
                        fourteen if in China). If you are in a hurry, it's unlikely that posting
                        twice will make group fellows log in sooner. Oh, come on, get a glass of
                        warm milk and relax on the coach for a while. Answers will come; if they
                        don't, it's normally because:

                        * Poster didn't write an informational "subject" line
                        * Poster didn't provide enough info
                        * Nobody knows the answer (some times happens)


                        --
                        -- Álvaro G. Vicario - Burgos, Spain
                        -- http://bits.demogracia.com - Mi sitio sobre programación web
                        -- Don't e-mail me your questions, post them to the group
                        --

                        Comment

                        • smilesinblues@gmail.com

                          #13
                          Re: Strange query problem php/mysql

                          Hi,

                          I apologize....

                          Bye

                          Comment

                          • Alvaro G Vicario

                            #14
                            Re: Strange query problem php/mysql

                            *** smilesinblues@g mail.com wrote/escribió (6 May 2005 00:30:13 -0700):[color=blue]
                            > I can't belive i can be such a big dump.....i just had to change the
                            > varchar(10) to int. thats it. its working now.[/color]

                            Before it was working too, only that not as expected: alphabetical order is
                            not very useful when dealing with numbers :)


                            --
                            -- Álvaro G. Vicario - Burgos, Spain
                            -- http://bits.demogracia.com - Mi sitio sobre programación web
                            -- Don't e-mail me your questions, post them to the group
                            --

                            Comment

                            • Sadara

                              #15
                              Re: Strange query problem php/mysql

                              smilesinblues@g mail.com wrote:[color=blue]
                              > Hi,
                              > I can't belive i can be such a big dump.....i just had to change the
                              > varchar(10) to int. thats it. its working now.
                              >
                              > thanks to everyone who tool out time.
                              >
                              > Thanks[/color]

                              that was the reason i asked about the datatype of 'hits' yesterday!

                              don't worry: i tool out time without batting an eyelid.

                              s

                              Comment

                              Working...