lordfirex Posted December 30, 2011 Share Posted December 30, 2011 Hey guys, i am having a problem and for the life of my i can't think of how to get around this problem. All the variables below are arrays and the code below is what i have done so far. The problem is when updating the records it only puts in "Array" in all of the fields being updated. How should i go about re-doing it so that when the first array in $idnumber is called. All the other arrays (Date, Description, Name) have their 1st array information allocated to a variable?? $Date = $_POST['Date']; $Name = $_POST['Name']; $Description = $_POST['Description']; $idnumber = $_POST['ID']; $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Picture_Blog", $con); foreach ($idnumber as $ID) { mysql_query("UPDATE slidorion SET Name = '$Name' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Description = '$Description' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Date = '$Date' WHERE ID = '$ID'"); } Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted December 30, 2011 Share Posted December 30, 2011 What you want to do is use the value within the array stored at the key of ID, so this should work: mysql_query("UPDATE slidorion SET Name = '{$Name['$ID']}' WHERE ID = '$ID'"); This will only work if $ID is NOT an array aswell... Quote Link to comment Share on other sites More sharing options...
lordfirex Posted December 30, 2011 Author Share Posted December 30, 2011 It works! Well sort of because it's edditting it's often getting $ID = 27, but it might be set out like ID[27, 3, 7, 9] And of course im after Description[27, 3, 7,9] So it's not working. Is there a way i can convert ID[27, 3, 7, 9] to say ref[1, 2, 3, 4] ??? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted December 30, 2011 Share Posted December 30, 2011 $id_list = implode(", ", $ID); Don't think that's going to help, but there you have it. I think were going to need to dynamicly generate the SQL on the fly. But if that works for you let me know. Quote Link to comment Share on other sites More sharing options...
lordfirex Posted December 30, 2011 Author Share Posted December 30, 2011 I managed to fix it by adding a count, although i must say thank you you were helpful in making me think $Date = $_POST['Date']; $Name = $_POST['Name']; $Description = $_POST['Description']; $idnumber = $_POST['ID']; $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Picture_Blog", $con); $count = 0; foreach ($idnumber as $ID) { mysql_query("UPDATE slidorion SET Name = '{$Name["$count"]}' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Description = '{$Description["$count"]}' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Date = '{$Date["$count"]}' WHERE ID = '$ID'"); $count = $count +1; } Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted December 30, 2011 Share Posted December 30, 2011 that will do it. I just thought of another one: foreach ($idnumber as $ref => $ID) { mysql_query("UPDATE slidorion SET Name = '{$Name['$ref']}' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Description = '{$Description['$ref']}' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Date = '{$Date['$ref']}' WHERE ID = '$ID'"); } Don't know why I didn't think of that sooner...though it has been a long bloody week :/ Glad you got it working anyway! Quote Link to comment 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.