本文整理匯總了PHP中mysqli_fetch_array函數的典型用法代碼示例。如果您正苦於以下問題:PHP mysqli_fetch_array函數的具體用法?PHP mysqli_fetch_array怎麽用?PHP mysqli_fetch_array使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mysqli_fetch_array函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: mySqlUpit
function mySqlUpit($upit, $tip)
{
$konekcija = mysqli_connect("localhost", "root", "", "0007cinevision");
$konekcija->set_charset("utf8");
if (mysqli_connect_errno()) {
printf("Konekcija nije uspela: %s\n", mysqli_connect_error());
exit;
}
$rezultat = mysqli_query($konekcija, $upit);
if (!$rezultat) {
printf("Greska: %s\n", mysqli_error($konekcija));
exit;
}
if ($tip == 0) {
return 0;
}
if ($tip == 1) {
$rez = mysqli_fetch_array($rezultat, MYSQLI_NUM);
$konekcija->close();
} else {
if ($tip == 2) {
$rez = array();
$i = 0;
while (($red = mysqli_fetch_array($rezultat)) != NULL) {
$rez[$i++] = $red;
}
}
}
if (!empty($rez)) {
return $rez;
}
return -1;
}
示例2: login
function login()
{
$link = $this->db_connection();
$pass = $_POST['user_password'];
$user = $_POST['user_name'];
$query = "SELECT password, user_type, name FROM user WHERE user_name='{$user}'";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
if (mysqli_num_rows($result) == 1) {
$result = mysqli_fetch_array($result);
//$hash= password_hash($result[0], PASSWORD_DEFAULT);
//$hash=$result[0];
//echo $hash;
//print_r($result);
// if($result[0]==$pass){
if (password_verify($pass, $result[0])) {
session_start();
$_SESSION['type'] = $result[1];
$_SESSION['name'] = $result[2];
//echo $_SESSION['type'].'<br>'.$_SESSION['name']=$result[2];
header("Location:card.php");
} else {
return $error = TRUE;
}
} else {
return $error = TRUE;
}
}
示例3: get_data
function get_data($id, $all = false)
{
include 'database.php';
$dbhandle = mysqli_connect($hostname, $username, $password, $database) or die("Unable to connect to MySQL");
$selected = mysqli_select_db($dbhandle, "esp");
if (!$selected) {
die("12 Could not select devices");
}
if ($all) {
$sql = "SELECT *\n\t\t\tFROM devices\n\t\t\tORDER BY esp_location ASC, esp_rx_date DESC, esp_rx_time DESC";
$result = mysqli_query($dbhandle, $sql);
while ($row = mysqli_fetch_array($result)) {
$json_arrays[] = array('status' => $row['esp_status'], 'esp' => $row['esp_id'], 'chan' => $row['esp_chan'], 'zone' => $row['esp_zone'], 'time' => $row['esp_rx_time'], 'date' => $row['esp_rx_date'], 'location' => $row['esp_location'], 'level' => $row['esp_rx_level'], 'tresh' => $row['esp_rx_treshold'], 'batt' => $row['esp_batt'], 'actives' => $row['esp_actives'], 'timenow' => date('H:i:s', time()));
}
mysqli_close($dbhandle);
return $json_arrays;
} else {
if ($id) {
$sql = "SELECT *\n\t\t\tFROM devices\n\t\t\tWHERE esp_id = " . $id . "\n\t\t\tORDER BY esp_rx_date DESC, esp_rx_time DESC";
$result = mysqli_query($dbhandle, $sql);
$row = mysqli_fetch_assoc($result);
$json_array = array('esp' => $row['esp_id'], 'chan' => $row['esp_chan'], 'zone' => $row['esp_zone'], 'time' => $row['esp_rx_time'], 'date' => $row['esp_rx_date'], 'location' => $row['esp_location'], 'level' => $row['esp_rx_level'], 'tresh' => $row['esp_rx_treshold'], 'batt' => $row['esp_batt'], 'actives' => $row['esp_actives'], 'timenow' => date('H:i:s', time()));
} else {
if ($id == 0) {
// grab the last active sensor data //
$sql = "SELECT *\n\t\t\tFROM devices\n\t\t\tORDER BY esp_rx_date DESC, esp_rx_time DESC";
$result = mysqli_query($dbhandle, $sql);
$row = mysqli_fetch_assoc($result);
$json_array = array('esp' => $row['esp_id'], 'chan' => $row['esp_chan'], 'zone' => $row['esp_zone'], 'time' => $row['esp_rx_time'], 'date' => $row['esp_rx_date'], 'location' => $row['esp_location'], 'level' => $row['esp_rx_level'], 'tresh' => $row['esp_rx_treshold'], 'batt' => $row['esp_batt'], 'actives' => $row['esp_actives'], 'timenow' => date('H:i:s', time()));
}
}
}
mysqli_close($dbhandle);
return $json_array;
}
示例4: getEmpresa
public function getEmpresa($valRef)
{
$linha = mysqli_fetch_array($this->pesquisar($valRef));
$this->empresa->setCodigo($linha["emp_codigo"]);
$this->empresa->setDescricao($linha["emp_descricao"]);
return $this->empresa;
}
示例5: check_login
function check_login($dbc, $name = '', $password = '')
{
$errors = array();
if (empty($name)) {
$errors[] = 'you forget to input your ID';
} else {
$e = mysqli_real_escape_string($dbc, trim($name));
}
if (empty($password)) {
$errors[] = 'you forget to input your password';
} else {
$p = mysqli_real_escape_string($dbc, trim($password));
}
if (empty($errors)) {
$q = "SELECT name FROM Manager where name= '{$e}' AND Cro = '{$p}'";
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) == 1) {
$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
return array(ture, $row);
} else {
$errors[] = 'your name OR password did not match!';
}
}
return array(false, $errors);
}
示例6: getArraySQL
function getArraySQL($sql, $DB)
{
//Creamos la conexión con la función anterior
$conexion = connectDB();
mysqli_select_db($conexion, $DB);
//selecciono la base de datos
//generamos la consulta
mysqli_set_charset($conexion, "utf8");
//formato de datos utf8
if (!($result = mysqli_query($conexion, $sql))) {
die;
}
//si la conexión cancelar programa
$rawdata = array();
//creamos un array
//guardamos en un array multidimensional todos los datos de la consulta
$i = 0;
while ($row = mysqli_fetch_array($result)) {
$rawdata[$i] = $row;
$i++;
}
disconnectDB($conexion);
//desconectamos la base de datos
return $rawdata;
//devolvemos el array
}
示例7: selectAuthority
function selectAuthority($authority)
{
$conn = tools::connectDatabase();
$allData = array();
$employeeID = array();
$result = mysqli_query($conn, "SELECT RoleID,RoleName FROM Roles WHERE {$authority}='1' ");
while ($row = mysqli_fetch_array($result)) {
array_push($allData, array('roleID' => $row['RoleID'], 'roleName' => $row['RoleName']));
}
for ($i = 0; $i < count($allData); $i++) {
$roleID = $allData[$i]["roleID"];
$result = mysqli_query($conn, "SELECT EmployeeID FROM UserRole WHERE RoleID='{$roleID}'");
while ($row = mysqli_fetch_array($result)) {
array_push($employeeID, $row['EmployeeID']);
}
}
$employee = array();
for ($i = 0; $i < count($employeeID); $i++) {
$id = $employeeID[$i];
$result = mysqli_query($conn, "SELECT EmployeeID,EmployeeName,DepartmentID,Title From Employees WHERE EmployeeID='{$id}'");
while ($row = mysqli_fetch_array($result)) {
array_push($employee, $row);
}
}
array_push($allData, $employee);
echo json_encode($allData);
}
示例8: login2
function login2($user, $pass)
{
$con = new db();
$conc = $con->c();
$kcook = intval($_POST["remember"]);
$q = mysqli_query($conc, "SELECT `id`,`user`,`name`,`email`,`img1`,`img2`,`img3`,`bgcolor` FROM `users` WHERE (`user` = '{$user}' OR `email` ='{$user}') AND pass = '{$pass}'");
if (mysqli_num_rows($q) == 1) {
$r = mysqli_fetch_array($q);
setcookie("u", $r[1], time() + 52 * 60 * 60 * 24 * 7, "/");
$_SESSION["uid"] = $r[0];
$_SESSION["user"] = $r[1];
$_SESSION["name"] = $r[2];
$_SESSION["email"] = $r[3];
$_SESSION["p"] = $pass;
$_SESSION["color"] = $r[7];
$_SESSION["img1"] = $r[4];
$_SESSION["img2"] = $r[5];
$_SESSION["img3"] = $r[6];
$_SESSION["ula"] = md5("{$r['1']} {$pass} {$r['0']}");
$con->close_db_con($conc);
if (!valid_name($_SESSION["user"])) {
$_SESSION["set_user"] = "Please correct your username remove symbols, characters or spaces, and should be less than 20 characters";
header("location: ./?settings");
} else {
if ($kcook == 1) {
setcookie("um", $r[1], time() + 52 * 60 * 60 * 24 * 7, "/");
setcookie("pm", $pass, time() + 52 * 60 * 60 * 24 * 7, "/");
}
return true;
}
} else {
return false;
}
}
示例9: scelta
/** @return Le informazioni del sondaggio tramite un array associativo, dove:
"choices" => array con le scelte, dove:
"id" => id della scelta
"descr" => descrizione della scelta (come inserito dall'utente)
"votes" => numero di voti per questa scelta
"percentage" => percentuale normalizzata (0..1) in relazione al totale dei voti (4 decimali di precisione)
"votes_count" => numero di voti totali
"user_has_voted" => boolean se l'utente corrente ha gia' votato */
function getPollData()
{
global $currentUser;
// Cache
if ($this->poll_data == null) {
$poll_info = unserialize($this->getRaw('poll'));
$choices = array();
$votes_count = 0;
$user_has_voted = false;
foreach ($poll_info as $id => $value) {
// id = numero, value = stringa descrivente la scelta
$choices[] = array("id" => $id, "descr" => $value, "votes" => 0, "percentage" => 0);
}
// Prende i voti dal database
$q = exequery("SELECT user_id, vote FROM forum_poll WHERE topic_id = {$this['id']}");
while ($values = mysqli_fetch_array($q)) {
$choices[$values['vote']]['votes']++;
// perche' indice == id
$votes_count++;
if ($values['user_id'] == $currentUser['id']) {
$user_has_voted = true;
}
}
// Calcola le percentuali
if ($votes_count > 0) {
foreach ($choices as $id => &$values) {
$values['percentage'] = round((double) $values['votes'] / (double) $votes_count, 4);
}
}
$this->poll_data = array("choices" => $choices, "votes_count" => $votes_count, "user_has_voted" => $user_has_voted);
}
return $this->poll_data;
}
示例10: login_check
function login_check($sql)
{
// Überprüfe, ob alle Session-Variablen gesetzt sind
if (isset($_SESSION['nutzerID'], $_SESSION['name'], $_SESSION['login_string'])) {
$nutzerID = $_SESSION['nutzerID'];
$login_string = $_SESSION['login_string'];
$name = $_SESSION['name'];
// Hole den user-agent string des Benutzers.
$nutzer_browser = $_SERVER['HTTP_USER_AGENT'];
$login_ab = "SELECT * FROM nutzer WHERE nutzerID = '" . $nutzerID . "';";
if ($login_an = mysqli_query($sql, $login_ab)) {
if (mysqli_num_rows($login_an) == 1) {
$login = mysqli_fetch_array($login_an);
$login_check = hash('sha512', $login['passwort'] . $nutzer_browser);
if ($login_check == $login_string) {
// Eingeloggt!!!!
return true;
} else {
// Nicht eingeloggt
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
示例11: buscar
function buscar($dato)
{
$sql = "select * \r\n\t\t\tfrom ot\r\n\t\t\twhere folio like '%" . $dato . "%' OR nombre like '%" . $dato . "%' OR modelo like '%" . $dato . "%' OR serie like '%" . $dato . "%' ";
$rs = mysqli_query($this->conn, $sql);
$i = 0;
if (mysqli_num_rows($rs) < 1) {
echo "La busqueda no obtuvo resultados.";
} else {
echo "<table border='1' align='center' class='table_' ><thead>\r\n\t\t\t\t\t<th>Folio</th>\r\n\t\t\t\t\t<th>Nombre</th>\r\n\t\t\t\t\t<th>Apellido</th>\r\n\t\t\t\t\t<th>Modelo</th>\r\n\t\t\t\t\t<th>Serie</th>\r\n\t\t\t\t\t<th>descripcion</th>\r\n\t\t\t\t\t<th>Fallas</th>\r\n\t\t\t\t\t<th>Resultado</th>\r\n\t\t\t\t\t<th>Estatus</th>\r\n\t\t\t\t\t<th>Fecha_Reg</th>\r\n\t\t\t\t\t<th>Fecha_Entr</th>\r\n\t\t\t\t\t<th>Comentario</th>\r\n\t\t\t\t</thead><tbody>";
while ($row = mysqli_fetch_array($rs)) {
echo "<tr><td align='center'>" . $row["folio"] . "</td>";
echo "<td align='center'>" . $row["nombre"] . "</td>";
echo "<td align='center'>" . $row["apellido"] . "</td>";
echo "<td align='center'>" . $row["modelo"] . "</td>";
echo "<td align='center'>" . $row["serie"] . "</td>";
echo "<td align='center'>" . $row["des"] . "</td>";
echo "<td align='center'>" . $row["fallas"] . "</td>";
echo "<td align='center'>" . $row["resultado"] . "</td>";
echo "<td align='center'>" . $row["estatus"] . "</td>";
echo "<td align='center'>" . $row["fechae"] . "</td>";
echo "<td align='center'>" . $row["fecha"] . "</td>";
echo '<td align="center">
<a class="fancybox fancybox.iframe" href="index.php?id=' . $row["id"] . '&folio=' . $row["folio"] . '&nombre=' . $row["nombre"] . '&apellido=' . $row["apellido"] . '&telefono=' . $row["telefono"] . ' " >Comentario</a></td>';
$i++;
}
}
echo "</tbody></table>";
}
示例12: onGetMessage
function onGetMessage($mynumber, $from, $id, $type, $time, $name, $body)
{
$from = chop($from, '@s.whatsapp.net');
$body = strtoupper($body);
$dbservername = "us-cdbr-iron-east-01.cleardb.net";
$dbusername = "b10de5ada49e20";
$dbpassword = "ea88f234";
$dbname = "heroku_3d91432389d0eb8";
$conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM messages WHERE sender = '" . $from . "'";
$result = mysqli_query($conn, $sql);
$lastmessage = mysqli_fetch_array($result, MYSQLI_ASSOC);
if (!$lastmessage) {
$sql = "INSERT INTO messages (sender, time_sent, message, new) VALUES ('" . $from . "', " . $time . ", '" . $body . "', 1)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully<br/>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
} else {
$sql = "UPDATE messages SET time_sent='" . $time . "', message='" . $body . "', prev_message='" . $lastmessage['message'] . "', new=1 WHERE sender='" . $from . "'";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully<br/>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
}
示例13: player
function player($pid)
{
global $con;
$result = mysqli_query($con, "SELECT * from players Where player_id='{$pid}'") or die(mysqli_error($con));
$row1 = mysqli_fetch_array($result);
return $row1['name'];
}
示例14: storeUser
/**
* Storing new user
* returns user details
*/
public function storeUser($name, $email, $gcm_regid)
{
// insert user into database
$c = new DB_Connect();
$d = $c->connect();
$test = mysqli_query($d, "SELECT * class_details where code='{$email}'");
if ($test) {
$result = mysqli_query($d, "INSERT INTO gcm_users(name, email, gcm_regid, created_at) VALUES('{$name}', '{$email}', '{$gcm_regid}', NOW())");
// check for successful store
if ($result) {
// get user details
$id = mysqli_insert_id();
// last inserted id
$result = mysqli_query($d, "SELECT * FROM gcm_users WHERE id = {$id}") or die(mysql_error());
// return user details
if (mysqli_num_rows($result) > 0) {
return mysqli_fetch_array($result);
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
示例15: validate
function validate($dbc, $email = '', $pwd = '')
{
$errors = array();
#Array to store errors.
if (empty($email)) {
$errors[] = 'Enter your email address.';
} else {
$e = mysqli_real_escape_string($dbc, trim($email));
#Escapes any special characters
#to avoid codes being run on the database.
$email = strip_tags($email);
}
if (empty($pwd)) {
$errors[] = 'Enter your password.';
} else {
$p = mysqli_real_escape_string($dbc, trim($pwd));
$pwd = strip_tags($pwd);
}
if (empty($errors)) {
$q = "SELECT customer_id,first_name,last_name\r\n\tFROM customers \r\n\tWHERE email='{$e}'\r\n\tAND password= SHA1('{$p}')";
#Retrieves customer related data
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) == 1) {
$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
return array(true, $row);
} else {
$errors[] = 'Email address and password not found';
}
return array(false, $errors);
}
}