deluxenathan deluxenathan - 6 months ago 9
SQL Question

PHP - Data not being transferred to next page

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 "
Result

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?

Answer

The porblem 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] ?>' " >
Comments