2017-11-13 41 views
-1

PHPのセクションにデータベースからの値を持つテーブルを作成するwhileループがあります。各行にアンカーが必要なので、ユーザーがその行をクリックしてそのページに戻ることにします同じ場所に正確に戻ってきます。各テーブル行にアンカータグを追加するにはどうすればよいですか?

しかし、それは完全には機能しませんが、いくつかの値は機能しますが、他のものは使用できません。

while(something){ 
    $product_list .= "<tr id='n$id'><th>$prod_cat</th><th>$sub_cat</th> 
     <th>$prod_name</th><th>$price</th><th>$q_left</th> 
     <th> $id1 </th><th> £$package </th><th><a href='dragNdrop.php 
     pID=$id'>Add more images</a> 
     &nbsp;/&nbsp;<a href='editProduct.php?pID=$id'>Edit</a>&nbsp;/&nbsp; 
     <a href='index.php?delID=$id&prodName=$prod_name'>Delete</a></th></tr>"; 
} 


<table> 
    <tr> 
     <th>Product Category</th> 
     <th>Sub-Cat</th> 
     <th>Product Name</th> 
     <th>Product Price</th> 
     <th>Quantity Left</th> 
     <th>EPOSNOW ID</th> 
     <th>Postage</th> 
</tr> 
    <?php echo $product_list; ?> 
</table> 
+0

あなたの質問は、私たちがよくあなたの問題を理解し、あなたに答えを与えることができるようにあなたの質問を更新してください理解できないです。 –

+0

あなたはstackoverflow答えの仕組みを知っています。どのように答えをリンクとして共有することができるのですか。ユーザーがそのリンクを使用すると、その答えにまっすぐに進みます。私はテーブルの列でそれをしたい、私はアンカーがそれを行う方法であると聞いた。しかしこれはまだうまくいきません。このようにhttps://stackoverflow.com/a/12853037/8782879 – Luke

+0

は答えを確認します –

答えて

1
<?php 
$arr = [ 
    [ 
     "product_category"=> "category1", 
     "product_sub_cateory"=> "subcategory1", 
     "product_name"=> "p1", 
    ], 
    [ 
     "product_category"=> "category2",  
     "product_sub_cateory"=> "subcategory2", 
     "product_name"=> "p2",   
    ], 
    [ 
     "product_category"=> "category3", 
     "product_sub_cateory"=> "subcategory3", 
     "product_name"=>"p3", 
    ], 
    [ 
     "product_category"=> "category4", 
     "product_sub_cateory"=> "subcategory4", 
     "product_name"=> "p4", 
    ] 
]; 
$arrCount = count($arr); 
$index=0; 
?> 
<table> 
    <tr> 
     <td> 
      Product category 
     </td> 
     <td> 
      Product sub category 
     </td> 
     <td> 
      Product name 
     </td> 
     <td>Link</td> 
    </tr> 
    <?php 
while($index < $arrCount){ 
     $url="www.site.com?id=".$index; 
    ?> 
    <tr> 
     <td> 
      <?php echo $arr[$index]['product_category'];?> 
     </td> 
     <td> 
      <?php echo $arr[$index]['product_sub_cateory'];?> 
     </td> 
     <td> 
      <?php echo $arr[$index]['product_name'];?> 
     </td> 
     <td> 
       <a href="<?php echo $url; ?>">Edit</a> 
     <td> 
    </tr> 
    <?php 
    $index++; 
} 
    ?> 
</table> 
+0

それはテーブルを追加するだけですか?または各行にアンカーを追加していますか?もし私に1000の行があるなら。 url./page#anchor599 – Luke

+0

URLを追加するのを忘れて申し訳ありません。 –

+0

@lukeを今すぐレビュー –

関連する問題