0

コードに問題があります。

index.php(php、mysql)..thisに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 に答える