Answers for "Mysqli fetch"

SQL
3

mysqli_fetch_assoc

<?php
	/* Connect to your database */
	$con = mysqli_query("hostname", "username", "pwd", "database");
    /* Select Columns from table*/
    $sql = "SELECT * FROM `TABLE`";
    /* Query your SQL code to SQLDatabase */
    $result = mysqli_query($con, $sql);
    /* Find rows in table*/
    $check = mysqli_num_rows($result);
    if($check > 0){
    while($data= mysqli_fetch_assoc($result)){
    /* Print all of your data*/
    echo $data["ColName"];
    }
    }
?>
Posted by: Guest on December-29-2019
0

php mysqli fetch all

$mysqli = new mysqli("host", "user", "password", "database", 'port', 'socket');

$result = $mysqli->query("SELECT Name, Type, Color FROM Fruit");

/**
 * This optional parameter is a constant indicating what type of array should
 * be produced from the current row data. The possible values for this parameter
 * are the constants MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH.
 */
$rows = $result->fetch_all(MYSQLI_ASSOC);

foreach ($rows as $row) {
  printf("%s - %s - %sn", $row["Name"], $row["Type"], $row["Color"]);
}
Posted by: Guest on August-26-2021
1

mysqli load result into array

$resource = $db->query("SELECT * FROM users WHERE userid = '".$userid."'");
while($row = $resource->fetch_array()) { $the_rows[] = $row; }
		/// later use like:
		//	foreach($the_rows as $row)
		//	{
		//		echo $row['product'];
		//	}
Posted by: Guest on July-29-2020

Code answers related to "SQL"

Browse Popular Code Answers by Language