richrock Posted January 15, 2009 Share Posted January 15, 2009 Hi, I've been using a scriptaculous library to process a list of items, and assign the list to an order. This means that items added to a DB are given an item order that is not defined by item id. However, I have a small problem. The array starts the ordering as 0, and I need it to start at 1. Any ideas how I can do this? This is how the items are listed: $number = mysql_num_rows($result); for($x=1;$x<=$number;$x++){ $row = mysql_fetch_array($result); $real_lot = $row['lot_order']; $real_id = $row['id']; $list .= "<li id=\"item_$row[id]\" class=\"catalogue_rows\" >"; $list .= "<table border='0'><tr>"; $list .= "<td width='50'>$real_lot</td>"; $list .= "<td width='400'><strong>$row[title]</strong></td>"; $list .= "<td width='100'>£$row[est_low] - $row[est_high]</td>"; $list .= "<td width='150'>$row[firstname] $row[lastname]</td>"; $list .= "<td>$row[lotrecnum] - $row[reclinenum]</td>"; $list .= "</tr></table>"; $list .= "<input type='hidden' name='lot_order[]' value='$x' />"; $list .= "</li>\n"; And storing the items via ajax : foreach ($_POST[sortlist] as $varname => $varvalue) { $sql = "update jos_bid_auctions set lot_order = ".mysql_real_escape_string($varname)." where id = ".mysql_real_escape_string($varvalue); $result = mysql_query($sql) or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/ Share on other sites More sharing options...
RussellReal Posted January 15, 2009 Share Posted January 15, 2009 you could just do.. for($x = 0;$x < $number;$x++){ Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/#findComment-737644 Share on other sites More sharing options...
richrock Posted January 15, 2009 Author Share Posted January 15, 2009 Hi, I tried it, and it still reorders starting at 0. I also changed $real_lot to $row[lot_order] as seen below, but still no juice. Was up till about 4am last night trying options on this.... $number = mysql_num_rows($result); for($x=0; $x < $number; $x++){ $row = mysql_fetch_array($result); $real_lot = $row['lot_order']; $real_id = $row['id']; $list .= "<li id=\"item_$row[id]\" class=\"catalogue_rows\" >"; $list .= "<table border='0'><tr>"; $list .= "<td width='50'>$row[lot_order]</td>"; $list .= "<td width='400'><strong>$row[title]</strong></td>"; $list .= "<td width='100'>£$row[est_low] - $row[est_high]</td>"; $list .= "<td width='150'>$row[firstname] $row[lastname]</td>"; $list .= "<td>$row[lotrecnum] - $row[reclinenum]</td>"; $list .= "</tr></table>"; $list .= "<input type='hidden' name='lot_order[]' value='$x' />"; $list .= "</li>\n"; } Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/#findComment-737656 Share on other sites More sharing options...
RussellReal Posted January 15, 2009 Share Posted January 15, 2009 ok I don't quite understand you coz now you've confused me.. you want your RESULTS that you OUTPUT to start counting itself E.G. item_1 item_2 starting from 1? can you link me to the page that this is happening on.. and tell me what should be different, because I'm at a loss right now.. Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/#findComment-737661 Share on other sites More sharing options...
Zephyr_Pure Posted January 15, 2009 Share Posted January 15, 2009 you could just do.. for($x = 0;$x < $number;$x++){ ... and change the value of the hidden input to ($x + 1) instead of just $x. If that's not what you're looking for, you'll need to provide more info about what the code is actually doing. Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/#findComment-737664 Share on other sites More sharing options...
richrock Posted January 15, 2009 Author Share Posted January 15, 2009 Okay, I'll try to explain. Unfortunately you can't see it, it's a private system and not gone live... The JS I've used allows me to list a bunch of items, and drag 'n' drop them, updating each change via Ajax, and a sort.php file, which is basically foreach ($_POST[sortlist] as $varname => $varvalue) { $sql = "update jos_bid_auctions set lot_order = ".mysql_real_escape_string($varname)." where id = ".mysql_real_escape_string($varvalue); $result = mysql_query($sql) or die(mysql_error()); } When the page is reloaded in the browser, it shows the new ordering... I've attached a screenshot to show how the lot order looks AFTER reloading the page. And I just need it to show 1,2,3, instead of 0,1,2,... Hope this clears it up a bit more... [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/#findComment-737666 Share on other sites More sharing options...
RussellReal Posted January 15, 2009 Share Posted January 15, 2009 change $list .= "<td width='50'>$row[lot_order]</td>"; to $list .= "<td width='50'>".($row[lot_order]+1)."</td>"; Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/#findComment-737673 Share on other sites More sharing options...
richrock Posted January 15, 2009 Author Share Posted January 15, 2009 Hahahaaaa!!!! ;D ;D Thanks RussellReal - pointed in the right direction. Doing what you suggested gave me order numbers like (0+1), (1+2), etc... I figured to make that into another string - so I wrote: $row_count = $row['order'] + 1; and added it before generating the list, and presto! It works! Thanks so much guys, I'll sleep tonight! ;D Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/#findComment-737680 Share on other sites More sharing options...
RussellReal Posted January 15, 2009 Share Posted January 15, 2009 anytime and mine shoulda worked lol Link to comment https://forums.phpfreaks.com/topic/140935-solved-php-problem-in-storing-array/#findComment-737681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.