Jump to content

MySQL database stopping at the number 10 (solved)


Loyalar

Recommended Posts

 Hello. I am currently in the progress of making an exam project in my programming subject, where I am making a site such as www.imageshack.us or www.tinypic.com (my page can be seen on www.picdump.xtreemhost.com at the moment), but I am having a problem.  When a person uploads a picture, it will of course be renamed. It will be renamed to "u[user-ID][4-ciffered random]p[number of last pic + 1][4-ciffered random].[type]". As an example, if the user with ID 5 has uploaded so many pictures that his last picture has number 25 (that would be named "u5[random1]p25[random2]", the next picture should be named to "u5[random1]p26[random2]".  Now, I have been trying to make this work with PHP and MySQL, and it works perfectly on my local machine. But as soon as I use the script online, I get a problem. When I reach the number 10 for the number of uploaded pictures, it just stops at 10 and won't increase to 11. It looks something like this: ID   user_ID   nr   type   random1 random2 1    1              1    jpg       gh2b     rwj92    1              2    jpg       c749     hens3    1              3    jpg       8x11     jeyt4    1              4    jpg       84w2    0bz25    1              5    jpg       vuv6    wear6    1              6    jpg       39nt    ghby7    1              7    jpg       bct3    ub5r8    1              8    jpg       gh3n    ryu510  1             10    jpg       rkxe     wey511  1             10    jpg       jatq     xxce12  1             10    jpg       65ng    w62a (I deleted number 9, if you are wondering) The PHP code that changes the numbers in every picture is like this: 

$pictureQuery = mysql_query("select * from pict where user_ID='$_SESSION[user_id]' ORDER BY nr DESC") or die (mysql_error());$pictureArray = mysql_fetch_array($pictureQuery);$next = $pictureArray['nr'] + 1;

The database is using MyISAM, if that would change anything.. I tried both using MyISAM and InnoDB locally, but nothing seems to change it. It just doesn't make sense, because this exact code works the first 10 times, and then it just ignores it completely.  I was wondering if it could be a mistake on the sites MySQL server?  On another note, I have a problem with how the site sorts the results. When I show the pictures, the results are ordered by "nr DESC" where locally, it works perfectly and they are ordered like 10, 9, 8, 7, 6, 5, 4, 3, 2, 1. Online they are ordered like 9, 8, 7, 6, 5, 4, 3, 2, 10, 1... Is this a problem on the server, and is it something I can fix myself? :)  On forehand, thanks! 

Link to comment
Share on other sites

I don't know about your first problem, but I can help with your second.ABS(nr) DESCThat will order your numbers in the correct order.

Link to comment
Share on other sites

I don't know about your first problem, but I can help with your second.ABS(nr) DESCThat will order your numbers in the correct order.
Alright, thanks.. But how exactly do I implement it in my query-line? It is like this.. 
$pictureQuery = mysql_query("select * from pict where user_ID='$_SESSION[user_id]' order by nr desc limit $start, 9") or die (mysql_error());Should I do like this instead: $pictureQuery = mysql_query("select * from pict where user_ID='$_SESSION[user_id]' order by ABS(nr) desc limit $start, 9") or die (mysql_error());

? Again, thanks for your help!

Link to comment
Share on other sites

Yeah, the second one is correct.$pictureQuery = mysql_query("select * from pict where user_ID='$_SESSION[user_id]' order by ABS(nr) desc limit $start, 9") or die (mysql_error());

Link to comment
Share on other sites

Yeah, the second one is correct.$pictureQuery = mysql_query("select * from pict where user_ID='$_SESSION[user_id]' order by ABS(nr) desc limit $start, 9") or die (mysql_error());
Thanks man, it worked perfectly :) Now I wish someone could help me with my other issue! :) 
Link to comment
Share on other sites

Alright! Well, I fixed my problem myself. I figured out that the thing that renamed the pictures used a code that was like $pictureQuery = mysql_query("select * from pict where user_ID='$_SESSION[user_id]' ORDER BY nr DESC")So I figured out that the ABS(nr) should be needed on this query as well. And it worked./thread!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...