How to use PHP variable in other pages [duplicate]

0

I have a script that brings the results of a sql search as follows:

$sql = (...);
$result = $db->query($sql);
while ($obj = mysqli_fetch_object($result)) {
    $ids = $obj->id_prestador.",";
}

If I make an echo $ ids after creating the $ ids, it brings for example: "710, 720, 730,".

On another page I would like to be able to get this information so I can run a script that sends these ID's to an application, how can I do it?

I tried a cookie that would be best for me, but then it only brought the 1st result ("710,").

$sql = (...);
$result = $db->query($sql);
while ($obj = mysqli_fetch_object($result)) {
    $ids = $obj->id_prestador.",";
    setcookie("cookieprestador",$ids)
}

I wanted to be able to grab any $ ids page such as "710, 720, 730,".

UPDATING: I have an array and I used implode and it worked, but when I do the setcookie it gives warning message: Can not modify header information already sent by output started at .....

Below is how it was:

$files = array();
 while ($obj = mysqli_fetch_array($result)) {
  $files[] = $obj["id_prestador"];
 }
$string = implode(', ', $files);
setcookie("cookieprestador",$string);
    
asked by anonymous 07.08.2017 / 19:48

1 answer

0

This error: Warning: Can not modify header information - already started by output started at

I've been through it several times, it happens when you text output before saving a cookie or session , if you look at it and if it is not this ... in my case I have already passed for this problem and had no data output before saving the cookie and the solution was to create a new file and paste everything I had in one file in the other new and then solved.

    
07.08.2017 / 20:36