By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,406 Members | 1,507 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,406 IT Pros & Developers. It's quick & easy.

Strange query problem php/mysql

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
*** sm***********@gmail.com wrote/escribió (4 May 2005 23:05:44 -0700):
Please help is something wrong with my query.


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
--
Jul 17 '05 #2

P: n/a
Hi,

thanks but where is the help??

Bye

Jul 17 '05 #3

P: n/a
Can you post the code where you loop and output the results?

Steve
smilesinbl...@gmail.com wrote:
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


Jul 17 '05 #4

P: n/a
sm***********@gmail.com wrote:
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.

what's the data type of the field 'hits'?

<snip />

s
Jul 17 '05 #5

P: n/a
*** sm***********@gmail.com wrote/escribió (5 May 2005 01:36:11 -0700):
thanks but where is the help??


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
--
Jul 17 '05 #6

P: n/a
Hi,
Forgive me for not giving the php code.

the datatype for hits is varchar(10).

The query is :

$query_mostwanted = "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_mostwanted = mysql_fetch_assoc($mostwanted)); ?>
Please help and let me know if you need any more info.

Thanks once again
Bye

Jul 17 '05 #7

P: n/a
Hi,

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

Thanks
Bye

Jul 17 '05 #8

P: n/a
sm***********@gmail.com wrote:
Hi,
Forgive me for not giving the php code.

the datatype for hits is varchar(10).

The query is :

$query_mostwanted = "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_mostwanted = mysql_fetch_assoc($mostwanted)); ?>
Please help and let me know if you need any more info.

Thanks once again
Bye

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

<?php

$query_mostwanted = "SELECT * FROM table ORDER BY hits DESC";
$result_mostwanted = mysql_query($query_mostwanted);
$serialid = 1;

while ($row_mostwanted = mysql_fetch_assoc($result_mostwanted)) {
echo
"<tr><td>$serialid</td><td>{$row_mostwanted['hits']}</td><td>{$row_mostwanted['artist']}</td></tr>\n";
$serialid++;
}

JP

--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #9

P: n/a
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

Jul 17 '05 #10

P: n/a
*** sm***********@gmail.com wrote/escribió (5 May 2005 06:38:19 -0700):
<?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_mostwanted = mysql_fetch_assoc($mostwanted)); ?>


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 htmlspecialchars() 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
--
Jul 17 '05 #11

P: n/a
*** sm***********@gmail.com wrote/escribió (5 May 2005 20:37:55 -0700):
I am so sorry but isnt there anyone who can help?


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
--
Jul 17 '05 #12

P: n/a
Hi,

I apologize....

Bye

Jul 17 '05 #13

P: n/a
*** sm***********@gmail.com wrote/escribió (6 May 2005 00:30:13 -0700):
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.


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
--
Jul 17 '05 #14

P: n/a
sm***********@gmail.com wrote:
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


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

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

s
Jul 17 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.