| Newsgroups |
php.notes |
| Message-ID |
<[email protected]> |
<?php
// This is my simple way to load a list of data.
// Load clientes list - return all clientes with fileds: id,nome and email.
// Connect to Mysqli
$mysqli = new mysqli("localhost", "my_user", "my_password", "clientes");
// Prepare your query
$stmt = $this->db->prepare("SELECT id, nome, email FROM clientes");
// Execute your query
$stmt->execute();
// Get results
$result = $stmt->get_result();
// Fetch table fields (id,nome and email)
$fields = $result->fetch_fields();
// Variable to store your data
$data = array();
// Perform your result using fetch_array(MYSQLI_ASSOC)
while($rows = $result->fetch_array(MYSQLI_ASSOC)) {
$row = array();
// Combine the fields of your table with your rows array result.
foreach($fields as $field) {
$row[$field->name] = $rows[$field->name];
}
// Store your data into $data array variable
$data[] = $row;
}
// Close the dataset
$stmt->close();
// Debug to see data return
echo "<pre>";
print_r($data);
echo "</pre>";
// I hope I helped!
// Julio Leles ([email protected])
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 2804:14c:5b80:8141:f97f:6b45:e6db:5a15)
----
Manual Page -- https://php.net/manual/en/mysqli-stmt.fetch.php
Edit -- https://main.php.net/note/edit/130382
Del: integrated -- https://main.php.net/note/delete/130382/integrated
Del: useless -- https://main.php.net/note/delete/130382/useless
Del: bad code -- https://main.php.net/note/delete/130382/bad+code
Del: spam -- https://main.php.net/note/delete/130382/spam
Del: non-english -- https://main.php.net/note/delete/130382/non-english
Del: in docs -- https://main.php.net/note/delete/130382/in+docs
Del: other reasons-- https://main.php.net/note/delete/130382
Reject -- https://main.php.net/note/reject/130382
Search -- https://main.php.net/manage/user-notes.php