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]."'"); } Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/ Share on other sites More sharing options...
Neptunus Maris Posted July 10, 2007 Share Posted July 10, 2007 What is the error message? Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294817 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294819 Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 where the echo or the print there Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294826 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!"...? Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294828 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294834 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? Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294868 Share on other sites More sharing options...
teng84 Posted July 11, 2007 Share Posted July 11, 2007 yes Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294877 Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 how? Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294880 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; } Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294884 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-294890 Share on other sites More sharing options...
gevo12321 Posted July 11, 2007 Author Share Posted July 11, 2007 bump Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-295034 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-295060 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? Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-295063 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-295066 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-295069 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-295077 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-295082 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 Link to comment https://forums.phpfreaks.com/topic/59346-solved-loop-help-plz/#findComment-295087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.