0

Here is the code

    $i=0;
while ($row = mysql_fetch_array($result)) 
    {
    $output.="idno".$i."=".urlencode($row['usr_id']).
    '&'."res".$i."=".urlencode($row['responce']).
    '&'."sex".$i."=".urlencode($row['sex']).
    '&'."com1".$i."=".urlencode($row['com1']).
    '&'."com2".$i."=".urlencode($row['com2']);
     $i++;

    }

OUTPUT i get idno is part of com2 string how do I seperate them.

3 Answers 3

4

You need to add an & when $i is not zero:

   $i=0;
while ($row = mysql_fetch_array($result)) 
        {
    $output .= ($i ? '&' : '') . "idno".$i."=".urlencode($row['usr_id']).
        '&'."res".$i."=".urlencode($row['responce']).
        '&'."sex".$i."=".urlencode($row['sex']).
        '&'."com1".$i."=".urlencode($row['com1']).
        '&'."com2".$i."=".urlencode($row['com2']);
     $i++;

        }
Sign up to request clarification or add additional context in comments.

2 Comments

Aaaah, that's what he meant. +1
Yeah, I had to read the question a few times to figure it out heh
3

Another solution would be using an array and join its elements afterwards:

$array = array();
$i = 0;
while ($row = mysql_fetch_array($result)) {
    $array[] = "idno$i=".urlencode($row['usr_id']);
    $array[] = "res$i=".urlencode($row['responce']);
    $array[] = "sex$i=".urlencode($row['sex']);
    $array[] = "com1$i=".urlencode($row['com1']);
    $array[] = "com2$i=".urlencode($row['com2']);
    $i++;
}
$output .= implode('&', $array);

Furthermore you could use the argName[] declaration that PHP will convert into an array when receiving such a request query string.

Comments

1

Or you could do this:

$array = array();
$i = 0;
while ($row = mysql_fetch_array($result)) {
    $array["idno$i"] = $row['usr_id'];
    $array["res$i"] = $row['responce'];
    //etc.

    $i++;
}

$output = http_build_query($array);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.