2017-08-13 6 views
0

夕方すべて、ループは1製品の行を返す

私は開発中の電子商取引プラットフォームのバックエンドで次のスクリプト設定をしています。基本的には、製品を引き抜き、現在のカテゴリをすべて引き出して、特定のカテゴリに商品を割り当てることができます。

私の商品編集ページには1件の結果しか表示されません。

最後のSQLクエリに関するスクリプトを削除すると、私の製品は表示されますが、カテゴリオプションは表示されません。このスクリプトでは、1つの製品のみが正しいカテゴリで表示されます。

<?php 
$myusername= $_SESSION['login_user']; 

include '../ecommerce/connection.php'; 

     $sql="SELECT * FROM products where status='yes' "; 

     // Posting Result 
     $result = mysqli_query($connection, $sql); 

     // Counting Results 
     $count=mysqli_num_rows($result); 

      if($count==0) { 

       echo "<div class='no_order_info_box'><br><h1 id='order_h1'>No products setup</h1></div>"; 

      } else { 

        if ($result = mysqli_query($connection, $sql)){ 

          echo "<table id='order_table_small'>";       
          echo "<th>Image</th>"; 
          echo "<th>Product ID</th>"; 
          echo "<th>Name</th>"; 
          echo "<th>Description</th>"; 
          echo "<th>Price</th>"; 
          echo "<th>Weight</th>"; 
          echo "<th>Options </th>";         


          while($row = $result->fetch_array()) 

            { 

            $product_no = $row['product_id']; 

              echo "<tr>"; 

              echo '<td><img src="images/'. $row['image'] . ' " id="product_image_admin">'; 
              echo "</td> "; 

              echo "<td>" .$row['product_id']; 
              echo "</td> ";         

              echo "<td>" .$row['product_name']; 
              echo "</td> "; 

              echo "<td>" .$row['product_description']; 
              echo "</td> "; 

              echo "<td>" .'&pound'.$row['product_price']; 
              echo "</td> "; 

              echo "<td>" .$row['product_weight'].'kg'; 
              echo "</td> "; 

              echo "<td><form action='store_configuration/edit_product' method='post' id='delivery_change_form'>"; 
              echo "<input type='text' name='product' value='$product_no' style='opacity: 0;'/>"; 
              echo "<input type='Submit' value='Edit Product' >"; 
              echo "</form></td>"; 



              echo "<td><form action='store_configuration/change_parent_category' method='post' id='delivery_change_form'>"; 

              echo "Parent Category <select name='category' style='height: auto;' >"; 

              **include '../ecommerce/connection.php'; 

              $sql="SELECT category_name FROM categories where status='yes' "; 

              // Posting Result 
              $result = mysqli_query($connection, $sql); 

              // Counting Results 
              $count=mysqli_num_rows($result); 

               if($count==0) { 

                echo "<div class='no_order_info_box'><br><h1 id='order_h1'>No categories setup</h1></div>"; 

               } else { 

               if ($result = mysqli_query($connection, $sql)){ 

                while($row = $result->fetch_array()) { 

                 $category = $row['category_name']; 

                 echo" <option value='$category' >".$category ."</option>"; 

                } 


               }        


              }**                            


              echo "</select>"; 
              echo "<br><br><input type='Submit' value='Update Category' >";        
              echo "</form></td>"; 

              echo "</tr>"; 


             } 

             echo "</table>";       

          } 

      } 

?>

enter image description here

私はすべてのカテゴリですべての製品を表示することができますどのように上の任意の助けが大好きです。

私は考えることができるすべてを試しました。

ありがとうございました。 スタン。

+3

内部クエリ...と結果セットの名前を変更してみてください。あなたがやっていることは、ループ内で$ sqlと$ result(私の推測です)を再定義することで、クエリを上書きしてしまいます。 – junkfoodjunkie

+0

これは私の問題を解決した、私はそれが何か簡単なことを知っていたが、試行錯誤を繰り返して何時間も座った後、私はどこにもいなかった。ありがとうございました! –

答えて

2

商品とカテゴリのクエリに同じ名前の変数を使用しました。カテゴリは製品のループ内にありますが、その変数を新しいクエリで再割り当てするため、クラッシュします。 2番目のクエリの変数の名前を変更し、スクリプトを修正する必要があります。

<?php 
$myusername= $_SESSION['login_user']; 

include '../ecommerce/connection.php'; 

     $sql="SELECT * FROM products where status='yes' "; 

     // Posting Result 
     $result = mysqli_query($connection, $sql); 

     // Counting Results 
     $count=mysqli_num_rows($result); 

      if($count==0) { 

       echo "<div class='no_order_info_box'><br><h1 id='order_h1'>No products setup</h1></div>"; 

      } else { 

        if ($result = mysqli_query($connection, $sql)){ 

          echo "<table id='order_table_small'>";       
          echo "<th>Image</th>"; 
          echo "<th>Product ID</th>"; 
          echo "<th>Name</th>"; 
          echo "<th>Description</th>"; 
          echo "<th>Price</th>"; 
          echo "<th>Weight</th>"; 
          echo "<th>Options </th>";         


          while($row = $result->fetch_array()) 

            { 

            $product_no = $row['product_id']; 

              echo "<tr>"; 

              echo '<td><img src="images/'. $row['image'] . ' " id="product_image_admin">'; 
              echo "</td> "; 

              echo "<td>" .$row['product_id']; 
              echo "</td> ";         

              echo "<td>" .$row['product_name']; 
              echo "</td> "; 

              echo "<td>" .$row['product_description']; 
              echo "</td> "; 

              echo "<td>" .'&pound'.$row['product_price']; 
              echo "</td> "; 

              echo "<td>" .$row['product_weight'].'kg'; 
              echo "</td> "; 

              echo "<td><form action='store_configuration/edit_product' method='post' id='delivery_change_form'>"; 
              echo "<input type='text' name='product' value='$product_no' style='opacity: 0;'/>"; 
              echo "<input type='Submit' value='Edit Product' >"; 
              echo "</form></td>"; 



              echo "<td><form action='store_configuration/change_parent_category' method='post' id='delivery_change_form'>"; 

              echo "Parent Category <select name='category' style='height: auto;' >"; 

              **include '../ecommerce/connection.php'; 

              $sql2="SELECT category_name FROM categories where status='yes' "; 

              // Posting Result 
              $result2 = mysqli_query($connection, $sql2); 

              // Counting Results 
              $count=mysqli_num_rows($result2); 

               if($count==0) { 

                echo "<div class='no_order_info_box'><br><h1 id='order_h1'>No categories setup</h1></div>"; 

               } else { 

               if ($result2 = mysqli_query($connection, $sql2)){ 

                while($row2 = $result2->fetch_array()) { 

                 $category = $row2['category_name']; 

                 echo" <option value='$category' >".$category ."</option>"; 

                } 


               }        


              }**                            


              echo "</select>"; 
              echo "<br><br><input type='Submit' value='Update Category' >";        
              echo "</form></td>"; 

              echo "</tr>"; 


             } 

             echo "</table>";       

          } 

      } 
?> 
+0

これは私の問題を解決しましたが、ジャンクはそれに打ち勝ちました:)上記のように、私はそれが何かシンプルになることを知っていましたが、試行錯誤を繰り返して何時間も座った後、いえいえこちらこそ! –

関連する問題