0

我的代码有问题。

我在 index.php (php, mysql) 中有 html 表..这个:

<?php
    require ('../../inc/config.inc.php');
    require ('../../inc/ini.php');
    mysql_set_charset('utf8');
    $sql = "SELECT * FROM {$cfg['tbl_dily']}";
    $result = mysql_query($sql)or die(mysql_error());

    echo "<table class=\"vypis\">";
    echo "<h1 id=\"vypis\">Nabídka náhradních dílů</h1>\n";

    $i = 0; //defaultní hodnota pro obarvení řádku

    //start cyklu pro výpis z tbl_dily
    while ($row = mysql_fetch_array($result)){
        //přístup ke sloupcum tbl_dily
        $part_id    =$row['part_id'];
        $img150     =$row['img150'];
        $nazevdilu  =$row['nazev'];
        $vyrobce    =$row['vyrobce'];
        $model      =$row['model'];
        $cena       =$row['cena'];

        //start --- coloring every 2nd row of table
        $i=1-$i;
        $trclass="radek".$i;
        //end --- coloring every 2nd row of table
        echo "<tr class=\"".$trclass."\">\n";
            if($img150 == null){ // podmínka pro existenci fotografie produktu
                echo "<td class=\"img150\"> <a href=\"./detail.php?id=".$part_id."\"> <img class=\"obrazek\" src=\"fotoneni.gif\"/> </a> </td>\n";
            }
            else {
                echo "<td class=\"img150\"> <a href=\"./detail.php?id=".$part_id."\"> <img class=\"obrazek\" src=\"".$img150."\"/> </a> </td>\n";
            }
            echo "<td class=\"nazevdilu\"><a href=\"./detail.php?id=".$part_id."\">".$nazevdilu."</a></td>\n";
            echo "<td class=\"modely\">".$vyrobce." ".$model."</td>\n";
            if($cena == 0){ //podmínka pro existenci přesné ceny produktu nebo "dohodou"
                echo "<td class=\"cena\">dohodou</td>\n";
            }
            else{
                echo "<td class=\"cena\">".$cena." Kč"."</td>\n";
            }
            echo "</tr>\n";
    }
    //konec cyklu pro výpis z tbl_dily
        echo "</table>\n";
?>

所以我已经毫无问题地链接了part_id。当我想查看某些产品的详细信息时会出现问题。我的 detail.php 现在看起来像这样:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">

<head>
<?php
require ('../../inc/config.inc.php');
require ('../../inc/ini.php');
mysql_set_charset('utf8');
$part_id=$_GET['part_id'];
$data = mysql_query("SELECT * FROM {$cfg['tbl_dily']} WHERE part_id='$part_id'") or die(mysql_error());
while ($detail = mysql_fetch_array($data)){
$id =$detail['part_id'];
}
?>
<title><?php $id; ?></title>
</head>
<body>
<div class="detail">
    <span id="detail_id">Výpis nabídky id <?php $id; ?></span>
    <div class="detail_foto">
    </div>
    <div class="detail_info">
    </div>
</div>
</body>
</html>

我至少需要帮助在 detail.php 的页面标题中获取 part_id 编号。我不太了解 $_GET 的工作原理..我希望有人告诉我如何..

谢谢你的协助:))

4

1 回答 1

0

Your explanation is not terribly nice. You should maybe edit the Question and explain where the problem is at. But for now, let me just explain '$_GET'

'$_GET' is a way to deliver Data from one PHP Script to another. You can find them in almost every Formular. As you can see in the Code below, there is a simple way that sends Data to an "action.php" - the attribute "method" is for telling the formular what you want to do. You should maybe take a look at both options because GET displays the data you want to deliver in the link. Your user could start manipulating that which would be a very unsafe thing in your case because you work with mysql-Databases. Also you should take a look at Mysql String escaping.

Back to the topic: The HTML below would redirect $_GET['name'] AND $_GET['age'] to the action.php where you can work with those.

<form action="action.php" method="get">
<p>Your ame: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
于 2014-11-14T08:32:25.057 回答