Reputation:
I have the following code below which is meant to keep the $_SESSION value when its goes to the next PHP page 'individual_item_page.php'
NOTE: I have hard coded the longitude & latitude for the SQL query
<table class="center">
<!-- SEARCH BY LOCATION -->
<?php
$LOCATION = $_POST['location'];
$result = $conn->prepare("SELECT dog_park_name,3956*2*ASIN(SQRT(POWER(SIN((-27.318672099999997 - latitude)*pi()/180/2),2)+COS(19.286558 * pi()/180)
*COS(latitude * pi()/180)*POWER(SIN((152.8500067 -longitude)* pi()/180/2),2)))
as distance FROM dog_parks.items having distance < $LOCATION ORDER BY distance;");
$result->execute();
for($i=0; $row = $result->fetch(); ){
$_SESSION["LOCATION".$i] = $row[0];
?>
<tr><!-- Adding the first table row -->
<th>Dog Park</th><!-- Adding the table header -->
</tr>
<tr><!-- Adding the second table row -->
<td>
<a href="individual_item_page.php?location='<?php $row[$i] ?>' " >
<?php echo $row[$i] ?>
</a>
</td>
</tr>
<?php } ?>
</table>
Here is the result in the URL when the script is executed. Only showing "
I'm thinking it is because there are multiple items being selected in the SQL query eg: dog_park_name,longitude and latitude.
I need only for the dog_park_name to be followed across to the next page...
Any ideas?
Upvotes: 0
Views: 62
Reputation: 11
You made a mistake in passing the url from one page to another. That's why it is not redirecting.
<a href="individual_item_page.php?location='<?php echo $row[$i]; ?>' " >
Upvotes: 1
Reputation: 9113
The problem is that you are not echoing your $row[$i]
.
Change:
<a href="individual_item_page.php?location='<?php $row[$i] ?>' " >
To:
<a href="individual_item_page.php?location='<?= $row[$i] ?>' " >
Upvotes: 1
Reputation: 121
From code I am missing an session_start()
other than that your for is missing i++
I think you ment to use something like:
echo "<table>";
while($row = $result->fetch())
{
$_SESSION["LOCATION".$i] = $row[0];
echo "<tr>". //Adding the first table row
"<th>Dog Park</th>". //Adding the table header
"</tr><tr>". //Adding the second table row
"<td><a href='individual_item_page.php?location=". $row[$i] ."'>".
// line above will give you URL Problems in my opinion
// since you are adding not replaceing
$row[$i] ."</a></td>".
"</tr>".
}
echo "</table>";
Honestly why not paste it in the URL? Not like you are useing regex to clean up your URL.
Upvotes: 0