Techmate Posted July 25, 2011 Share Posted July 25, 2011 This should be super simple for you guys . Mysql in my table are columns id, name, image, position. Here is all I need in the position column I need the position to be in numerical order when an image is uploaded. Can someone give me a code line to do that? Quote Link to comment https://forums.phpfreaks.com/topic/242690-need-help-with-adding-a-number-to-a-image/ Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 You could select the highest number, then increase it by one. $sql="SELECT position FROM table ORDER BY position DESC LIMIT 0, 1"; if ($query=@mysql_query($sql)) { $position = 1; if (mysql_num_rows($query) > 0) { $position = mysql_result($query, 0, 0) + 1; } } else { echo "Error: ".mysql_error(); } Quote Link to comment https://forums.phpfreaks.com/topic/242690-need-help-with-adding-a-number-to-a-image/#findComment-1246476 Share on other sites More sharing options...
phpSensei Posted July 25, 2011 Share Posted July 25, 2011 edit: I misunderstood. Quote Link to comment https://forums.phpfreaks.com/topic/242690-need-help-with-adding-a-number-to-a-image/#findComment-1246479 Share on other sites More sharing options...
Techmate Posted July 25, 2011 Author Share Posted July 25, 2011 You could select the highest number, then increase it by one. $sql="SELECT position FROM table ORDER BY position DESC LIMIT 0, 1"; if ($query=@mysql_query($sql)) { $position = 1; if (mysql_num_rows($query) > 0) { $position = mysql_result($query, 0, 0) + 1; } } else { echo "Error: ".mysql_error(); } Your awesome, but. As soon as I posted that I figured it out...lol. I ended up going with: //Querys the last postion in the colum $result = mysql_query ("SELECT column FROM table ORDER BY column DESC LIMIT 0,1"); // while($row = mysql_fetch_array($result)){ $column = $row['column']; } echo ++$name; Quote Link to comment https://forums.phpfreaks.com/topic/242690-need-help-with-adding-a-number-to-a-image/#findComment-1246480 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.