如何从链接到新页面获取所选行

时间:2015-05-20 22:58:04

标签: php mysql

您好我想要的是获取我在消息中显示的$typeValue,然后显示数据。

在第一页中,我显示带有特定$typeValue的邮件的代码如下所示

//ALERT SYSTEM    
    $query2 = mysql_query("SELECT username, typeValue FROM sensors WHERE (sensorValue < min OR sensorValue > max) AND doctorStatus='0'");
    $query3 = mysql_query("SELECT username FROM sensors WHERE (sensorValue < min OR sensorValue > max) AND doctorStatus='0'");
    //$row3 = mysql_fetch_array($query3);  
    while($row = mysql_fetch_array($query2))
    {
        while($row3 = mysql_fetch_array($query3))
        {
            $p1 = mysql_num_rows(queryMysql("SELECT * FROM connected
            WHERE username='$row3[0]' AND friend='$username'"));
            $p2 = mysql_num_rows(queryMysql("SELECT * FROM connected
            WHERE username='$username' AND friend='$row3[0]'"));
            if (($p1 + $p2) > 1)
            {
                $alert_message= " <b><font color=red><p align='center'>User " . $row['username'] . " Has A Health Problem with his/her ".$row['typeValue']."</font></b>";
                $link_address = "health_problem.php?view=".$row['username']."&typevalue=".$row['typeValue'];
            ?>
            <a href="<?php echo $link_address;?>"> <?php echo $alert_message; ?> </a>
            <?php
            }
        } 

    }

我要显示此数据的另一页的代码

<?php

/**
 * @author Nick Bourlai
 * @copyright 2015
 */

include_once 'header.php';


$result = queryMysql("SELECT * FROM patient WHERE username='$username'");
if(mysql_num_rows($result))
{
    $query = "UPDATE sensors SET status='1' WHERE status ='0' AND username='$username'";
    mysql_query($query)or die(mysql_error());
}
else
{
    $query = "UPDATE sensors SET doctorStatus='1' WHERE doctorStatus ='0' AND username='$view'";
    mysql_query($query)or die(mysql_error());
}

$con = mysqli_connect('localhost','root','smogi','project');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}
$view = ($_GET['view']);
$username2 =$_SESSION['username'];
$typeValue = ($_GET['typeValue']); 
$sql="SELECT typeValue,unit,sensorValue,datetime FROM sensors WHERE username='$view' AND typeValue='$typeValue'";
$result = mysqli_query($con,$sql);
echo $view;
echo $typeValue;
echo "<table>
<tr>


</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr> <b>Type: </b>";
    echo stripslashes($row['typeValue']) . "<br/><b>Unit: </b>";
    echo stripslashes($row['unit']) . "<br/><b>Value: </b>";
    echo stripslashes($row['sensorValue']) . "<br/><b>Date: </b>";
    echo stripslashes($row['datetime']) . "<br/>";
    echo "--------------------------------------------------------------------------------------------------------------";
    echo "<br/></tr>";
}
echo "</table>";

?>

所以我想要的是从点击的链接中获取特定的行,并在另一页中显示该行的数据。

2 个答案:

答案 0 :(得分:2)

  

@ Fred-ii-错误地我在键盘上切换我的语言并且你回答是正确的,关于单词中的小V请写下它作为答案以接受它

  • 根据要求:

您的GET值在网址中使用小写v health_problem.php?view=magda&typevalue=Temperature,而不是与GET数组typeValue中的$_GET['typeValue']相关的大写V

  • health_problem.php?view=magda&typeValue=Temperature
  • 变量区分大小写。

另外,除了我自己在评论中已经说明的内容之外,不同的MySQL API不会相互混合。从连接到查询使用相同的MySQL API。

<强>脚注:

答案 1 :(得分:1)

PHP变量和数组键区分大小写。第二个脚本中的这一行

$typeValue = ($_GET['typeValue']); 

应该是

$typeValue = ($_GET['typevalue']);