Question

I want to pass my primary key all id value in single url parameter :

PRODUCT TABLE :

id    -- int 11 , primary key
name  -- varchar
desp  -- varecha

table data :

    id | name   |   desp 
  ------------------------
    1  |  A     |    f
    2  |  B     |   fg
    3  |  C     |   ghb
    4  |  g     |   bn

below code :

$sql = "SELECT id from product";
$result = mysqli_query($db,$sql);


while ($myrow = mysqli_fetch_array($result)){

$id = $myrow['id'];

// echo $id : 1234
}

hence i am getting id value but i need to pass this "id" value in single URL PARAMETER:

<a href="test.php?test=".$_GET['tes']."&pid=".$id." " >url parameter</a>

note : i cant keep this anchor link in my while loop , as i want this a single link that will be shown in another table

hence my link would be something like :

test.php?test=as&pid=1234

but i am unable to get pid=1234

hence please let me know how i can get the same

Was it helpful?

Solution

Editing answer, as I got your idea wrong.

All you have to do is:

while ($myrow = mysqli_fetch_array($result)){
//.= means that it will connect all values, not override them
$id .= $myrow['id'];

// echo $id : 1234
}

THen echo $id from anywhere.

OTHER TIPS

declare an array outside the while loop : $arr = array(); then write this statement inside your while loop : arr[] = $myrow['id']; this way the array will contain all the IDs and it will increment automatically (you don't have to specify the array index each time). Then you can use that array to get the IDs any time you want. Please if that is not what you want, tell me and explain to me more (because I answered your question based on what I understood so please explain more to me about what you need if it is not the answer). Thanks :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top