문제

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>";
        }
도움이 되었습니까?

해결책

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.

다른 팁

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>';
        }
}



?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top