woocha Posted December 18, 2007 Share Posted December 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
papaface Posted December 18, 2007 Share Posted December 18, 2007 Sessions are your friend. e.g on file_a.php session_start(); //some mysql code produces $str $_SESSION['str'] = $str; on file_b.php session_start(); echo $_SESSION['str']; Done. Quote Link to comment Share on other sites More sharing options...
woocha Posted December 18, 2007 Author Share Posted December 18, 2007 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? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 18, 2007 Share Posted December 18, 2007 Because it overwrites itself. Maybe make a multi demension array instead. Also, put session_start(); as your first line of code. Quote Link to comment Share on other sites More sharing options...
woocha Posted December 18, 2007 Author Share Posted December 18, 2007 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. Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted December 18, 2007 Share Posted December 18, 2007 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]; Quote Link to comment Share on other sites More sharing options...
woocha Posted December 18, 2007 Author Share Posted December 18, 2007 Thank you very much for your reply...That is exactly what i am working on right now...I link it will be the best quickest way with the least amount of code. :)Thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.