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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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