Jump to content

coding help


dannybrazil

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.