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? 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(); } 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. 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; 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
Archived
This topic is now archived and is closed to further replies.