2017-12-02 2 views
-1

私の問題は、私のデータベースに格納されている情報を呼び出すことができないということです。私はそれがデータベース内にある順番にすべてを呼びたいと思います(製品名、イメージ、価格の名前です)index.phpのコードはですここで私のウェブページの見た目を見ることができます:私のデータベース(画像のリンクなし)に保存されている画像、テキスト、および番号を呼び出す方法

screen 1 screen 2

<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<title>Add to Cart</title> 
 
<?php 
 
$mysqli = new mysqli("localhost", "id3764036_alan", "agro12345", "id3764036_agrotienda"); 
 

 

 
?> 
 
<link rel="stylesheet" href="style.css" type="text/css"> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"> 
 
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed|Rubik" rel="stylesheet"> 
 
<style> 
 
a{text-decoration:none; color:inherit} 
 
#undr{width:100%; height:580px; position:absolute; top:75px; left:0px;} 
 
.bdimg{width:100%; height:100%} 
 
#lowrbdy{ position:absolute; top:90px; left:0px;width:100%; height:100px} 
 
.outer{width:270px; height:270px; background:rgba(255,255,255,0.8); float:left; margin-left:55px; margin-bottom:10px} 
 
.imgdv{width:100px;height:140px;margin:10px auto;} 
 
.imgdv img{width:100%; height:100%} 
 
.pname{ text-align:center; width:100%; height:20px; font-size:15px; margin-top:-14px; margin-bottom:10px} 
 
.prs{ text-align:center; font-size:24px; margin:0px} 
 
.butndv{width:140px; height:40px; margin:auto; margin-top:-10px} 
 
.butn{width:100%; height:100%; background:rgba(78,172,240,1.00); border:none; color:#fff; font-size:18px; border-radius:6px} 
 
.outer:hover{ background:#fff} 
 
.outer:hover .butn{ background:#4A7FDC; transition:all 0.2s ease-in-out; cursor:pointer} 
 
</style> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
</head> 
 

 
<body> 
 
\t <header> 
 
\t \t <?php 
 
\t \t \t include('head.php'); 
 
\t \t ?> 
 
\t </header> 
 
\t \t 
 
    <div id="undr"> 
 
\t \t <img class="bdimg" src="bg.jpg"> 
 
\t </div> 
 
    \t 
 
    <div id="lowrbdy"> 
 
<?php 
 
$select_query=""; 
 
$sql = mysqli_query($mysqli,'SELECT * FROM `product`'); 
 

 

 
while ($row = $sql->fetch_row()) 
 

 

 
{ 
 
    
 

 
?>    
 
\t  <a href="view.php?product=<?=$row["id"]?>"> 
 
     \t <div class="outer"> 
 
      \t \t <div class="imgdv"><img src="carrillo/imeg/<?=$row["pro_image"]?>"/></div> 
 
       
 
       
 
\t \t \t </div> 
 
\t \t </a> 
 
<?php 
 

 
} 
 
?> 
 
    \t 
 
    </div> 
 
</body> 
 
</html>

+0

あなたはデシベルではない画像にファイル名を格納するのでinstated mysqli_fetch_assocを使用する必要がMySQLiの手続き で試すことができます。.. 'carrillo/imeg /'に実際に画像ファイルがあることを確認してください – nogad

+0

画像はhttps://agro-tienda.000webhostapp.com/carrillo/imeg/に保存されています。私が望むのは、自分のDBに新しい情報を追加すると、自動的に新しいページがWebページに生成されるということです。 –

答えて

0

変更:ここで

あなたは私のデータベースにあるデータを表示することができます~。 fetch_row()を使用すると、$ row変数に数値インデックスを持つ配列が含まれます。 fetch_assoc()を使用すると、$ row変数は列名をインデックスとして連想配列を格納します。

+0

私はちょうど私を試みたが、それでも仕事をしない –

+0

心配して、それはちょうど、働いた、ありがとう –

+0

あなたは大歓迎です。私を答えとしてマークしてください –

-1

は、プリペアドステートメントに

<?php 
$select_query=""; 
// $sql = mysqli_query($mysqli,'SELECT * FROM `product`'); 
$sql="SELECT id, pro_image,name,price FROM product"; 
if ($stmt = $conn->prepare($sql)) { 
     $stmt->execute(); 
     $stmt->bind_result($id, $pro_image, $name); 
     while ($stmt->fetch()) { 
     ?> 
     <a href="view.php?product=<?php echo $id;?>"> 
      <div class="outer"> 
       <div class="imgdv"><img src="carrillo/imeg/<?php echo $p_image;?>"/></div> 
      </div> 
     </a> 

<?php 
} 
}?> 

を使用してみてくださいまた、あなたがfetch_row

$sql = "SELECT * FROM `products`"; 
$result = mysqli_query($conn, $sql); 
if (mysqli_num_rows($result) > 0) { 
while($row = mysqli_fetch_assoc($result)) { 
?>    
     <a href="view.php?product=<?php echo $row["id"];?>"> 
      <div class="outer"> 
       <div class="imgdv"><img src="carrillo/imeg/<?php echo $row["pro_image"];?>"/></div> 
      </div> 
     </a> 
<?php 
} 
} 
else { 
    echo "0 results"; 
} 

mysqli_close($conn); 

?> 
関連する問題