Hello misbahkuy !
you are stuck at 'debug level' , by Php you have few functions to organize 'debug' :
the 'print_r( $_var );' function can dig and display all contents in all types of vars .
this function works with Objects , Arrays and all the others vars through Php .
the 'r' in this function is about 'Recursion' , obviously the 'print_r()' function can fetch in n-dimensions Arrays , and in Objects hierarchy by Design .
print_r($result);
That all about debug until now .
I take few more lines to make you advices :
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo '<div class="card">';
echo '<img src="/online_shop/' . $row['image'] . '" class="card-img-top" alt="Product Image">';
echo '<div class="card-body">';
echo '<h5 class="card-title">' . $row['name'] . '</h5>';
echo '<p class="card-text">' . $row['description'] . '</p>';
echo '<p class="card-text">Price: ' . $row['price'] . '</p>';
echo '</div>';
echo '</div>';
}
} else {
echo '<p>No products found.</p>';
}
if ($result && $result->num_rows > 0) {
$output = "" ;
while ($row = $result->fetch_assoc()) {
$output .= '<div class="card">';
$output .= '<img src="/online_shop/' . $row['image'] . '" class="card-img-top" alt="Product Image">';
$output .= '<div class="card-body">';
$output .= '<h5 class="card-title">' . $row['name'] . '</h5>';
$output .= '<p class="card-text">' . $row['description'] . '</p>';
$output .= '<p class="card-text">Price: ' . $row['price'] . '</p>';
$output .= '</div>';
$output .= '</div>';
}
echo $output ;
} else {
echo '<p>No products found.</p>';
}
_another detail about Php_ :
when using 'super global vars' $_GET / $_POST / $_SERVER / $_COOKIE , and the others ,
keep in mind those vars are :
- arrays : you can fetch all those by a loop of your choice .
- in code use : they are used in all Php Scope , no limits with those super global 'vars'
- its contents and values : you don't need to copy them in one another vars
$twins = $_POST['the_data_I_need'] ;
- OOPs / Classes / Objects :
Php is OOPs friendly , you can build classes , try to build a short 'conn' or 'DB' class , and use it every time you need it.
You will gain a lot of times, and your 'code design' will be more simple.
Class DB{
private $server;
private $db;
private $user;
private $pwd ;
private $conn ;
private $result ;
public function __construct($se , $dbase , $usr ; $pass){
$this->server = $se ;
$this->db = $dbase ;
$this->user = $usr ;
$this->pwd = $pass ;
$this->conn = new mysqli($this->server, $this->db, $this->pwd, $this->user);
}
public function execute_query( $the_query ){
$this->result = $this->conn->query( $the_query );
return $this->result ;
}
}
by using this Class :
<?php
$myDB = new DB($se,$Dbase,$user,$pwd)
$datas_all_in = $myDB->execute_query("select * from TABLES") ;
unset( $myDB , $datas_all_in );
?>