Question

I am trying to return an array of results from php, and each result is a link. When a link is clicked, it will go into another php that echo the details that are related to link/array clicked. But i am not very sure how to do that. What i attached below is the array echoed out. Please any thoughts would be good. Thanks for your time.

<?php
ini_set('display_errors', 1); error_reporting(E_ALL);


include 'connect.php';
$username=$_SESSION['username'];


$result=mysqli_query($con,"SELECT * FROM Listing WHERE username = '$username'")or die( mysqli_error($con));
$solutions = array();
while ($row = mysqli_fetch_assoc($result))
        {

          print $solutions[0]=$row['Listingname']."</br>";
        }
Was it helpful?

Solution

I think i know what you mean.
That when you have this:

while ($row = mysqli_fetch_assoc($result))
{    
   echo '<a href="/names/'.$row['Listingname'].'">'.$row['Listingname'].'</br>';
}

That you get a list of names as a link.
Alfredo (www.MySite.com/names/Alfredo)
Sandra (www.MySite.com/names/Sandra)

And somebody clicks on a link, like Sandra. He goes to the url:

www.MySite.com/names/Sandra

And on that page, you can get the url with $_SERVER['REQUEST_URI']

$parts = explode("/", $_SERVER['REQUEST_URI']); 
$name = $parts['4'];

Example of the query can be:

"SELECT * FROM Names WHERE name = '$name'"

And than you can get the results from the url into the query to get the results of the name. That you can show on the page.

OTHER TIPS

Thanks for your help, i built up on your answer and got what i needed.

<?php
ini_set('display_errors', 1); error_reporting(E_ALL);


include 'connect.php';
$username=$_SESSION['username'];


$result=mysqli_query($con,"SELECT * FROM Listing WHERE username = '$username'")or die( mysqli_error($con));

while ($row = mysqli_fetch_assoc($result))
        {

          echo '<a href="SpecificListing.php">'.$row['Listingname'].'</br>';
        }
}



?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top