Answers for "mysql get data from database"

PHP
0

mysql get data from database

//creating a connection to the db
$conn = new mysqli('host ip addr','uname','pwd','dbname');


//the selection query with a where clause to filter out the data
$sel = "SELECT * FROM `table` WHERE `something`='something'";

//the result returned from the query
$result = $conn->query($sel);

//checking if there are more than one rows in the result
if($result->num_rows > 0){
  
  	//getting all the rows from the result with a while loop
	 while($row = $result->fetch_assoc()){
     	 echo $row['data1'] . ' ' . $row['data2'];//get all the data from the row array
     }
}
Posted by: Guest on June-05-2021

Code answers related to "mysql get data from database"

Browse Popular Code Answers by Language