Jump to content

[SOLVED] Pass the content of a variable to new php file


woocha

Recommended Posts

Hey guys...

 

  I am writing another script as I learn here so I have another question.  I have a two file script here.  file_a.php and file_b.php.....

file_a.php executes some code and querrys mysql and generates a fills a variable with mysql data, is it possible to pass the variable o file_b.php without doing the same querry that was done in file_a.phph?

thanks guys

thank you very much...that worked out great, but I have one more question on the topic.

If I am using this code while statement:

<?php
$query = "select * from catalog where merchant=$merchadmin order by $sort";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result))
{
$item_numb = $r['item_numb'];
echo "$item_numb";
  session_start();
  //some mysql code produces $str
  $_SESSION['str'] = $item_numb;
}
?>

the passed session variable only grabs the last result from the querry....do you have any suggestion?

crap...I was hoping to not have to go there just yet...I am still not 100% comfortable with multi demension arrays yet....But i suppose I will give it a shot. 

 

What i was hoping for, was to be able to use <a href="file_b.php"> and pass the variable throught the link, but i have no idea if that is even possible.

So you want to pass the variable to the second page via hyper link

This will create a hyper link for every record in the database pulled by your query string!

<?php
$query = "select * from catalog where merchant=$merchadmin order by $sort";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result))
{
$item_numb = $r['item_numb'];
echo "<a href='file_b.php?item_numb=".$item_numb."'>".$item_numb."</a><br>";
}
?>

Second page use the get function to set the variable passed in the url

$item_numb = $_GET[item_numb];

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.