1

私がやろうとしているのは、エコーされる行ごとに異なるハイパーリンクアドレスがあるようにすることです。コードは以下のとおりです。

    echo "<table border='1' cellpadding='10'>";
    echo "<tr>  <th>Product Name</th> <th>Product Description</th> <th>Product Price</th> <th>Product Image</th> <th>View Product Details</th></tr>";

    while($row = mysql_fetch_array( $result )) {

            echo "<tr>";
            echo '<td>' . $row['Product_Name'] . '</td>';
    echo '<td>' . $row['Product_Description'] . '</td>';
            echo '<td>' . $row['Product_Price'] . '</td>';
            echo '<td><a href="print_pic.php">Picture Enlarge</a></td>';
            echo '<td><a href="phone1.php?id=1">View Details</a></td>';
            echo "</tr>";

    } 
  echo "</table>";
4

3 に答える 3

2

他の変数と同じように、エコーされたアンカーにphp変数をインラインで配置できます。

データベースのフィールドを使用していると仮定すると、次のidことができます。

echo '<td><a href="phone1.php?id=' . $row['id'] . '">View Details</a></td>';

echophp変数(例)を$row['id']使用すると、HTMLにエコーアウトされます(必ずしもテキストである必要はありません)。したがって、これは(HTMLの)アンカータグに含まれているため、アンカータグにエコーし、id部分を構築します。:)

于 2012-04-30T14:52:33.260 に答える
0
<table border='1' cellpadding='10'>
<tr>  
    <th>Product Name</th> 
    <th>Product Description</th> 
    <th>Product Price</th>
    <th>Product Image</th>
    <th>View Product Details</th>
</tr>

    while($row = mysql_fetch_array( $result )) {

        <tr>
            <td> <?php echo $row['Product_Name']; ?></td>
            <td><?php echo $row['Product_Description']; ?></td>
            <td><?php $row['Product_Price']; ?></td>
            <td><a href="print_pic.php">Picture Enlarge</a></td>
            <td><a href="phone1.php?id="<?php echo $row['tableRowId']; ?>">View Details</a></td>
        </tr>

    } 
</table>

私はおそらくそのようなものに行くでしょう。これは、テーブルが自動インクリメント列のようなものから一意の ID を返すことを前提としています。

これにはエスケープが含まれないため、悪用される可能性があります。テンプレも検討します。プレゼンテーションの助けになるかもしれませんし、html と php が混ざったものを読むのが少し楽になります。

于 2012-04-30T14:54:32.643 に答える
0
"<td align=\"center\" valign=\"top\"><a href=\"$prevMonth\">&lt;&lt;</a>")  . "</td>\n"
于 2012-05-14T11:33:11.290 に答える