Tuesday, 9 June 2020

how to get data from data base and prints if it is followed the condition

how to get data from data base and prints if it is followed the condition
<?php

require 'dbconnect.php';

$query = 'SELECT `first` , `last` FROM `a_database` WHERE `id`<5  ORDER BY `id` ';
id<5 , then only runs, if id<3, it prints upto 3


if($query_run = @mysqli_query($mycon, $query)){
if(mysqli_num_rows($query_run)! = NULL){
if rows are not null, then while executes
while($row = @mysqli_fetch_assoc($query_run)){
$fname = @mysqli_fetch_assoc;
$sname = $row['last'];
echo $fname .''.$sname .'</br></br>';

}
}else{ echo 'no users found';
}else {
echo 'queryfailed';
}

?>








multi dimensional arrays
https://web-developer-tuts.blogspot.com/2020/06/arrays-and-associative-arrays.html

/*
$laptop = array(
array ("rahul", "dell", 10),
array in array called 2 d array
array ('sonam", "hp", 20),
array ("sumit", "zed", 30)
};

*/
$laptop [0][] = "rahul";
$laptop [0][] = 'dell';
$laptop[0][] = 10;



require
how to write the query to do action write query
how to execute query against connected database @mysqli_query
how to find number of rows mysqli_num_rows
how to convert tables to associative arrays @mysqli_fetch_assoc
how to acess data as a row @mysqli_fetch_assoc
if if while else else

No comments:

Post a Comment