dannybrazil Posted March 12, 2010 Share Posted March 12, 2010 Hello I have no knowlege in JS and I need your help I have this code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Setting cookie and passing to other page in url</title> <script language="javascript" type="text/javascript"> var i = 0; var ids = new Array(); function setCookie(c_name) { c_name += "[]" + i++; ids[i] = c_name; var value = document.getElementById("i1").value; document.cookie = c_name + "=" + escape(value); } function getVarNPost() { var valuestoPost = ""; for (x in ids) { c_start = document.cookie.indexOf(ids[x] + "="); if (c_start != -1) { c_start = c_start + ids[x].length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) c_end = document.cookie.length valuestoPost += ids[x] + "=" + unescape(document.cookie.substring(c_start, c_end)) + "&"; } } window.location = "http://www.classimoveisrn.com/hebrew/js_test.php?" + valuestoPost; } </script> </head> <body> <form id="f1"> <input type="text" id="i1" /> <input type="button" id="submit" value="submit" onclick="setCookie('id')" /> </form> <input type="submit" id="post" value="submit" onclick="getVarNPost()" /> </body> </html> this JS eventually produces this link domain.com?id[]0=123&id[]1=345....id[]i=*** I need it to create a link from type array to be able to GET it from the link with PHP , I need the link to look like that : domain.com?ids[]=123&ids[]=345....ids[]=*** It mean NO # after the ID var' In order to use this ; Code: $ids = array_map('intval', $_GET['ids']); $sql = "SELECT * FROM foo WHERE id IN (" . implode(',', $ids) . ")"; Any help ? Link to comment https://forums.phpfreaks.com/topic/195000-coding-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.