Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just can't figure out ARRAYS 2

Status
Not open for further replies.

sd0t1

IS-IT--Management
Mar 14, 2007
131
US
Hi guys, I need a little help. I have sat down and studied arrays, but evidentially not good enough.

I found a function that covers my receiving page. It has a piece of code that looks like this:

...WHERE schedule.id IN ('".implode("', '", $id)."')";

And this code takes my $id Array and implodes it and goes on to do the work.

What I can't figure out, is how to create a link with all the $id's stored in an array and then when the user clicks it. All the $id's are sent to the next page and stored into the $id Array so the above code can implode and read them.


Here is what I got and I don't think it's right. Plus on the recieving page, how do I load the results into an Array called $id with the elements seperaed by commas?

$query = "SELECT id FROM schedule WHERE poid = '$search' ";
$result = mysql_query($query, $user_login) or die(mysql_error());

$id = array();
while ($row = mysql_fetch_array($result))
{
$id []= $row;

}

echo "<a href='s_stat_report.php?id=$id'>Print All Status Reports</a>";
 
why would you want to do that?

but if you must it the code would look something like this

remember that this code assumes that you will append the resulting value to the existing query string. if it represents the only query string you will need to replace the first & with a ? (but only the first one).

Code:
$queryBits = getLinks ($id, 'id');

function getLink($id, $fieldname){
  $return == '';
  foreach ($id as $_id){
    $return .= "&{$fieldname}[]=$id";
  }
}
 
Basically you can 't pass an array in a url query string. you can pass a list of comma separated values. So you can skip a step already.


What I think you want to do is explode your $id array before sticking it into the url query string.

Once you receive it in your processing page, you can just use the string as is.
Code:
 $id = array();
$link="<a href='s_stat_report.php?id=";
        while ($row = mysql_fetch_array($result))
                    {
                       $link.=$row['id'] . ","; //[green]Create list in query string[/green]
                        
                    }
$link=substr($link, 0, -1); [green]//Remove superfluous comma[/green]
$link.="'>Print All Status Reports</a>"; [green]//finish off link[/green]
            echo $link  [green]print out link[/green]

Then its ready to be used in your query as a string. No need to implode.



Code:
.WHERE schedule.id IN ($id);



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ok, first let me thank both of you guys for your input.
I used vacunita's code because I'm just so unfamiliar with arrays at this point and I was able to copy and paste it.

Well the problem now is that when I click the link and the $id's are sent to the next page, I'm using output buffering because it's actually a Dompdf page that takes the id's and generates status reports per id in .pdf.

And to make the Dompdf work I output buffer all the data and then send it to a file that Dompdf creates into a .pdf.

Well in order to make vacunita's code work I had to comment out the ob_start() so now Dompdf doesn't work.

Any idea's on what I need to do now guys?
And I promise I'm going to dive into array's as soon as I can get this project deadline past me.
 
Did you get any error when you had the ob_start()in place?

How did it not work?

Also, i just noticed a missed an ending semicolon ";" after the "echo $link " line.





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
it didn't give an error. I echoed the id's on the screen just to see if they were successfully being transfered. It would only echo if I had the echo statement before the ob_start(). I even tried to set the variable $id =
$_GET['id'] prior to the ob_start() and it still doesn't work.

It goes to the page with no error and just sits there with a blank screen.

Oh and I did catch the missing ; and fixed it.
 
I guess we'll need to see your code if at all possible.
There's something else that's causing that.

There's no reason it should just blank out otherwise.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
It's working now.

I actually tried it on another computer and it worked. I think I was having a cache problem, I've been experiencing that a lot lately with IE 7.

Sorry for wasting your time, and thanks again for your input.
 
No problem. And never a waste of time. Glad you sorted it out.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top