gevo12321 Posted July 10, 2007 Share Posted July 10, 2007 ok i have this code but it doesnt work how can i change it to make it work? else if (isset($edit)) { foreach ($_POST['button'] as $namekey => $namevalue) { $name[$namekey] = $namevalue; } foreach ($_POST['buttonsrc'] as $sourcekey => $sourcevalue) { $source[$sourcekey] = $sourcevalue; } foreach ($_POST['id'] as $idkey => $idvalue) { $id[$idkey] = $idvalue; } mysql_query("UPDATE layout SET 'name'='".$name[$namekey]."', 'source'='".$source[$sourcekey]."' WHERE id='".$id[$idkey]."'"); } Quote Link to comment Share on other sites More sharing options...
Neptunus Maris Posted July 10, 2007 Share Posted July 10, 2007 What is the error message? Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted July 10, 2007 Author Share Posted July 10, 2007 no error the page just comes out blank im sure that the problem is in the way i have set it up because the update needs to loop as well Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 where the echo or the print there Quote Link to comment Share on other sites More sharing options...
Neptunus Maris Posted July 10, 2007 Share Posted July 10, 2007 where the echo or the print there Yeah...do you have a success message...like "Data has been updated successfully!"...? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 ok i have this code but it doesnt work how can i change it to make it work? else if (isset($edit)) { foreach ($_POST['button'] as $namekey => $namevalue) { $name[$namekey] = $namevalue; } foreach ($_POST['buttonsrc'] as $sourcekey => $sourcevalue) { $source[$sourcekey] = $sourcevalue; } foreach ($_POST['id'] as $idkey => $idvalue) { $id[$idkey] = $idvalue; } mysql_query("UPDATE layout SET 'name'='".$name[$namekey]."', 'source'='".$source[$sourcekey]."' WHERE id='".$id[$idkey]."'"); } hmm your code is weird pass the variable into the array to be use while others get array content and pass to variables to be used hmm thats totally different Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 ? would it be possible to put the update into a loop or to put all 3 arrays in the loop? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 yes Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 how? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 1st explain this foreach ($_POST['button'] as $namekey => $namevalue) { $name[$namekey] = $namevalue; } foreach ($_POST['buttonsrc'] as $sourcekey => $sourcevalue) { $source[$sourcekey] = $sourcevalue; } foreach ($_POST['id'] as $idkey => $idvalue) { $id[$idkey] = $idvalue; } Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 ok im looping 3 arrays becuase i need all three for the update Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 bump Quote Link to comment Share on other sites More sharing options...
tapos Posted July 11, 2007 Share Posted July 11, 2007 mysql_query("UPDATE layout SET 'name'='".$name[$namekey]."', 'source'='".$source[$sourcekey]."' WHERE id='".$id[$idkey]."'"); } You should use only name or `name` instead 'name'. another thing this query will work only for last values of the arrays ($name,$source,$id) -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 well plz help me how would i make it work for all values? Quote Link to comment Share on other sites More sharing options...
tapos Posted July 11, 2007 Share Posted July 11, 2007 first let me know: the value and the length of the all three arrays. -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 well the arrays are defined as: foreach ($_POST['button'] as $namekey => $namevalue) { $name[$namekey] = $namevalue; } foreach ($_POST['buttonsrc'] as $sourcekey => $sourcevalue) { $source[$sourcekey] = $sourcevalue; } foreach ($_POST['id'] as $idkey => $idvalue) { $id[$idkey] = $idvalue; } i dont know if that was what u meant by value as for the length, the number of elements in each array is variable i dont know if thats what u meant by length thx Quote Link to comment Share on other sites More sharing options...
tapos Posted July 11, 2007 Share Posted July 11, 2007 You can try this: $i = 0; $info = array(); foreach ($_POST['button'] as $namekey => $namevalue) { $info[$i++]['name'] = $namevalue; } $i=0; foreach ($_POST['buttonsrc'] as $sourcekey => $sourcevalue) { $info[$i++]['source'] = $sourcevalue; } $i=0; foreach ($_POST['id'] as $idkey => $idvalue) { $info[$i++]['id'] = $idvalue; } //queries for($i =0;$i<count($info);$i++) { mysql_query("UPDATE layout SET name='".$info[$i]['name']."', source='".$info[$i]['source']."' WHERE id='".$info[$i]['id']."'"); } -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 thank you it worked but can u please tell me what u did in english and not in php because im fairly new to this and i didnt quite understand what the code says. thx a lot Quote Link to comment Share on other sites More sharing options...
tapos Posted July 11, 2007 Share Posted July 11, 2007 First, u should see the foreach array. 2nd, u have three arrays of three fields of a table. then u should make the query properly. 3rd, u should handle arrays properly. Thanks, -- Tapos Pal 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.