As a newb...I really could use some direction here and some code help would be great. This is what I want to do.
I have a script that searches my mysql db. The script returns results in the form of links. User clicks on link and the remaining results are wiped.
I want to store those results in a session. So I start a session on the results page. I then echo the session variable that captures the search results. Problem is, the session only returns the last result. All other results are lost. My code is below.
Results Page: This is just a testing script. I don't have the links set yet.
<?php
session_start();
include ("config.php");
if (isset($_POST['submit'])){
$results = mysql_query("SELECT * FROM countries WHERE value LIKE '$_POST[country]%'")
or die(mysql_error());
while ($row = mysql_fetch_array ($results)) {
echo "<div align =\"left\">$row[0] $row[1]</div>";
$_SESSION["row"] = $row[1] ;
}
}else{
echo "This script should not be accessed directly";
}
echo "<br><br><a href = \"searchform.php\">Search Again</a>";
echo "<br><br><a href = \"search.php\">Test Session</a>";
?>
Say a user clicks on a link: It takes them to the page and echos the results stored in the session.
<?php
session_start();
include ("header.php");
echo $_SESSION["row"] ;
echo "<br><br><a href = \"searchform.php\">Search again</a><br><br>";
include ("footer.php");
?>
Problem is, when there are more than 1 result, the session only echos the last result in the query. I think I need to make a function to create a session for each returned result but I have no idea where to begin.
Can anybody help??
Thanks
Joshua