Displaying data in 3 div side by side in a row - php

wants to display data in 3 boxes side by side, followed by 3, etc.
code:
<div class="row">
<?php
$sql = 'SELECT * FROM zlecenia';
$result = mysqli_query($mysqli, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "<div class='zlecenia_on col-md-8'>";
echo "<center><h1>Zlecenie: " . $row["nazwa"]. "</h1></center><br>";
echo "<table cellpadding='2'><tbody><tr><td> Ilość znakow: " . $row["ilosc_znakow"] . "</td><td>Dead line: " . $row["dead_line"]."</td></tr></tbody></table>";
echo "</div>";
}
} else {
echo "0 results";
}
?>
currently there is one below the other

Related

php clicking on users name to display profile

So i have this code to display all the users in my database and to access them. That works fine but is there any way to get where it says click here just to display a variable in this case the leader name(aka user name)?
<?php
require_once "config.php";
$sql = "SELECT id , leader_name, nation_name, power FROM nation_info";
$result = $link->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$nationList = [];
$userid = $row['id'];
echo ' click here '; // the click here on this line
// echo '<a class="viewProfile" href="viewnation.php?id=' . $userid . '"><button>View Profile</button></a>'; old method of viewing profile
echo " Nation Name: " . $row["nation_name"]. " Leader Name " . $row["leader_name"]. " Power " . $row["power"];
echo "<br>";
}
} else {
echo "0 results";
}
$link->close();
?>
Are you talking about this? Just printing the name in place of click here?
<?php
require_once "config.php";
$sql = "SELECT id , leader_name, nation_name, power FROM nation_info";
$result = $link->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$nationList = [];
$userid = $row['id'];
echo ' ' . $row["leader_name"] . ' '; // the click here on this line
// echo '<a class="viewProfile" href="viewnation.php?id=' . $userid . '"><button>View Profile</button></a>'; old method of viewing profile
echo " Nation Name: " . $row["nation_name"]. " Leader Name " . $row["leader_name"]. " Power " . $row["power"];
echo "<br>";
}
} else {
echo "0 results";
}
$link->close();
?>

How can I post my data that i get from SQL into divs in php

I need to make a page that shows posts from database. It has to have a Title and text in the post. I get all of the information from database already, but I don't know how to make it so they are placed into divs. Currently the data I get is set into tables, but I would like to get them into divs. Current code: (note: I have the php and sql connection working)
$sql = "SELECT title, txt FROM xxxxx";
$result = $con->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "<table><tr><th>Title</th><th>Text</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["title"]. "</td><td>" . $row["txt"]. " </td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
Also by that I was looking for bootstrap panel-group classes, but I was not able to implement that.
It seems you forgot to include your divs:
if ($result->num_rows > 0) {
// output data of each row
echo "<div><table><tr><th>Title</th><th>Text</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["title"]. "</td><td>" . $row["txt"]. " </td></tr>";
}
echo "</table></div>";
} else {
echo "0 results";
}
or if you don't want to include a table but only the divs, simply do it like so:
if ($result->num_rows > 0) {
// output data of each row
echo "<div class='title'><h1>Title</h1>";
while($row = $result->fetch_assoc()) {
echo "<p>" . $row["title"]. "</p><p>" . $row["txt"]. " </p>";
}
echo "</div>";
} else {
echo "0 results";
}

How to put mysqli while result into one variable and echo it in html

How do I put ALL the while result in mysqli select into one variable and echo into the html document?
Code are based on W3school
PHP
$sql = "SELECT firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
//previously it was echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "
";
$parsedcontent = '<div class="col-md-4">'.$row["firstname"].'</div><div class="col-md-4">'.$row["lastname"].'</div>';
}
} else {
echo "0 results";
}
HTML
<div class="row">
<?php echo $parsedcontent; ?>
</div>
$data = array();
// output data of each row
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
// push retrieved data to data array in order for return later
array_push($data, $row);
}

Select Data by Id PHP

I have trouble to select a set of specific data using ID from the database. For example, employee one has a unique id of e000000001, when I click the view button in the index will lead to employee detail page which shows the detail of that particular employee instead of all the employees' detail. Thank you.
//from index.php page
<?php
require_once 'db/dbEmpList.php';
$sqlStr = "SELECT * FROM employees;";
$result = $connection->query($sqlStr);
if ($result->num_rows > 0) {
echo "<table class='table table-sm'><thread><tr><th>Full Name</th><th>Employee ID</th><th>Position</th><th>View Employee's Details</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>"
. $row["empName"]. "</td><td>"
. $row["empID"]. "</td><td>"
. $row["position"]. "</td>"
. "<td> <a href='employeedetail.php?id={$row["empID"]}'>View</a>"
. "</td></tr>";
}
}
// from employee page
require_once 'db/dbEmpDetail.php';
$sql = "SELECT * FROM employees where empID = '{$row["empID"]}' ";
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result)) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>' .'<td>' .$row["empName"].'</td>'.'<td>'. $row["position"].'</td>' .'<td>'.$row["empNRIC"].'</td>' .'<td>'.$row["empID"].'</td>' .'<td>'.$row["empEmail"].'</td>' .'<td>'.$row["empPwd"].'</td>' . "</tr>";
}
} else {
echo "0 results";
}
mysqli_close($connection);
?>
// FROM EMPLOYEE PAGE
The way you retrieve URL query string is wrong. You should be using $_GET to get the query string from URL. In your case it should be $_GET['id']. See the code below:
require_once 'db/dbEmpDetail.php';
$employeeid = trim(mysqli_real_escape_string($_GET['id']));
$sql = "SELECT * FROM employees where empID = '".$employeeid."' ";
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result)) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>' .'<td>' .$row["empName"].'</td>'.'<td>'. $row["position"].'</td>' .'<td>'.$row["empNRIC"].'</td>' .'<td>'.$row["empID"].'</td>' .'<td>'.$row["empEmail"].'</td>' .'<td>'.$row["empPwd"].'</td>' . "</tr>";
}
}
else {
echo "0 results";
}
mysqli_close($connection);
?>

Display row that is not repeated linking with database

I am new in php. I make a quiz app and I want to show questions that is not repeated again . here's my code.
Please help me to show require result.
<?php
include('connect.php');
$sql = "SELECT * FROM quiz_question WHERE theme_id= 2 ORDER BY RAND ()";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row['id'];
echo "
<h2>" . $row["question"]. "</h2>";
break;
}
}
$check_id = array ($row['id']);
echo $check_id['0'];
if(array ($row['id']) == $check_id){
echo "no question ";
}
else{
echo "
<h2>" . $row["question"]. "</h2>";
}
?>
Your question is not clear. But I guess, you can solve it by array_unique($array).
array_unique($array);
<?php
include('connect.php');
$sql = "SELECT * FROM quiz_question WHERE theme_id= 2 ORDER BY RAND ()";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row['id'];
$question = $row['question'];
echo "
<h2>" . $row["question"]. "</h2>";
$check_id = array($id);
}
}
$check_id_unique=array_unique($check_id);
?>

Categories