Please help me convert this php to CI code |
[eluser]Jbeasley6651[/eluser]
$listingCounter = 1; foreach ($updateRecordsArray as $recordIDValue) { $query = "UPDATE records SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue; mysql_query($query) or die('Error, insert query failed'); $listingCounter = $listingCounter + 1; } I'm use to CAKE as a framework and i'm still learning CI have stand alone php/ajax code that works fine and i really need help converting it to code igniter. I'm placing this inside a controller (i'm opting out of models at the moment). For cake it would be something like... foreach ($updateRecordsArray as $recordIDValue) { $this->Record->id = $recordIdValue; $this->Record->saveField('recordListingID', $listingCounter); }
[eluser]xwero[/eluser]
Code: foreach ($updateRecordsArray as $listingCounter=>$recordIDValue) {
[eluser]Jbeasley6651[/eluser]
i'm getting the error in my firebug console - A Database Error Occurred You must set the database table to be used with your query. Any Ideas?
[eluser]Jbeasley6651[/eluser]
How in your code would i set the table name where the data is being sent? Also, thanks for the fast response, i appreciate it alot. CI is amazing
[eluser]Dam1an[/eluser]
You can set it as a paramter for the update function, see the user guide for more info on updateing (and AR in general)
[eluser]Jbeasley6651[/eluser]
Got it! Thanks! To show how thankful I am heres a little treat for you. Have you ever wanted to drag and drop sort a list item? If anyone wants to do Ajax sortable list item (so you can drag and drop the list items to change order) and have it save to a database automatically upon dropping without refreshing the page in Code Igniter you can download the following... Screen Shots Before Drag <a href="http://img20.imageshack.us/img20/7101/picture1lfe.png">http://img20.imageshack.us/img20/7101/picture1lfe.png</a> During Drag <a href="http://img33.imageshack.us/img33/8241/picture2pxe.png">http://img33.imageshack.us/img33/8241/picture2pxe.png</a> After Drop (notice console data in firebug) <a href="http://img30.imageshack.us/img30/1791/picture3wxi.png">http://img30.imageshack.us/img30/1791/picture3wxi.png</a> Controller: Code: // Boxes Code: function updateBOX() CSS: Code: ul { JS/ajax- (you will need jquery draggable, droppable, sortable, selectable) Code: [removed] View: Code: <div id="contentLeft"> mysql dump: Code: CREATE TABLE `boxes` ( Please let me know if this was helpful. Thanks, Joel Beasley
[eluser]xwero[/eluser]
i blame the weather and a whole day of ASP.NET coding |
Welcome Guest, Not a member yet? Register Sign In |