如何在一个数组中$ SESSION个别结果?

时间:2013-11-26 13:46:49

标签: php session-variables php-5.4

您好我是非常新的php,尝试做这个帐户页面,php使用$ session_username从数据库中抽出一行(listingname),将个别结果转换为链接,它们都链接到另一个php。我正在尝试做的是,$ SESSION我点击它时的特定列表名称。

例如,在列表名称的行中有John,Ben,Tom,它们在Array中,它们都是单独的链接,点击它时会转到list.php,我想要做的是。单击John时,$ SESSION _ ['listingname']将是John,如果单击Ben,$ SESSION _ ['listingname']将是Ben等。那么我可以使用该名称从数据库中提取更多信息到List.php。中的那个名字。

感谢您的时间!

PHP

<?php

ini_set('display_errors', 1); error_reporting(E_ALL);

session_start();
include 'connect.php';

echo "Welcome  ".$_SESSION['username'];
echo "</br>";
echo $_SESSION['password'];
echo "</br>";
echo "</br>";



{





?>

<FORM METHOD="LINK" ACTION="Submitlisting5.php">
<INPUT TYPE="submit" VALUE="Go to submit">
</br>
</br>

</FORM>
Existing List
</br>
<?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>';
        }
        $_SESSION['Listingname']=$row['Listingname'];
}



?>

1 个答案:

答案 0 :(得分:1)

您应该将链接传递到下一页。

例如:

echo '<a href="SpecificListing.php?listingName='.urlencode($row['Listingname']).'">'.$row['Listingname'].'</br>';

在SpecificListing.php上你可以设置

$_SESSION['Listingname'] = $_GET['listingName'];