PHP MySQL only displays Blank Table - php

Good Day! Im having a problem displaying the data from table. I have already inputted 6 data and it will show how many base from my $i++ but it does not show the userno, fullname and udate. i would really appreciate it Please and thank you! Table Display Here is my code:
table class="table table-striped table-sm">
<thead>
<tr>
<th>No</th>
<th>User No</th>
<th>User Name</th>
<th>Date Registered</th>
</tr>
</thead>
<tbody>
<?php
$i=0;
$uquery= mysqli_query($conn, "SELECT * FROM users");
while ($uresult=mysqli_fetch_array($uquery)){
$i++;
?>
<tr>
<td><?php echo $i;?></td>
<td><?php $uresult ['userno'];?></td>
<td><?php $uresult ['fullname'];?></td>
<td><?php $uresult ['udate'];?></td>
<?php }; ?>
</tbody>
</table>

You forgot to echo your results.
Change
<td><?php $uresult ['userno'];?></td>
<td><?php $uresult ['fullname'];?></td>
<td><?php $uresult ['udate'];?></td>
To
<td><?php echo $uresult ['userno'];?></td>
<td><?php echo $uresult ['fullname'];?></td>
<td><?php echo $uresult ['udate'];?></td>
Or
<td><?= $uresult ['userno'];?></td>
<td><?= $uresult ['fullname'];?></td>
<td><?= $uresult ['udate'];?></td>

$sql = "SELECT userno, fullname, udate FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br> userno: ". $row["userno"]. " - Full Name: ". $row["fullname"]. " - udate: " . $row["udate"] . "<br>";
}
} else {
echo "0 results";
}
//Don't Forget To:
$conn->close();
This'll be your PHP, adjust it accordingly to your table, hope this helps!

First of all, you have missed end</tr>, second do you really have to use variable i and increment it? where you can echo all ID? and why there's semi-colon after your closing bracket.Lastly, you should have put echo in variables uresult Hope this could help you
<table class="table table-striped table-sm">
<thead>
<tr>
<th>No</th>
<th>User No</th>
<th>User Name</th>
<th>Date Registered</th>
</tr>
</thead>
<tbody>
<?php
$uquery= mysqli_query($conn, "SELECT * FROM users");
while ($uresult=mysqli_fetch_array($uquery)){
?>
<tr>
<td><?php echo $uresult ['id'];?></td>
<td><?php echo $uresult ['userno'];?></td>
<td><?php echo $uresult ['fullname'];?></td>
<td><?php echo $uresult ['udate'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
and also you can write it, in this way:
and echo variable `i` if you want to see the count of it.
<?php
$uquery= "SELECT * from users";
$viewquery = mysqli_query($con,$uquery);
while($uresult = mysqli_fetch_assoc($viewquery))
{
?>

Related

Datatables console error jQuery.Deferred exception: Cannot set property '_DT_CellIndex'

my datatables didn't work and i get console error Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined but when i delete the query inside tbody its working fine.
<table class="table table-bordered table-striped table-fixed text-center" id="myTable">
<thead>
<tr>
<th>No</th>
<th>ID</th>
<th>Nama</th>
<th>Golongan</th>
<th>Nilai Output</th>
<th>Penilaian Atasan</th>
<th>Nilai Learning</th>
<th>Nilai Kedisiplinan</th>
<th>Nilai 5R</th>
<th>Hasil</th>
<th>Tanggal</th>
</tr>
</thead>
<!-- query -->
<?php
$no = 0;
$query = "SELECT * FROM user
where id= $_SESSION[id]";
$query = "SELECT user.id,user.nama,golongan,nilai_output,nilai_atasan,nilai_learning,nilai_kedisiplinan,nilai_5r,overall,tanggal
FROM tkaryawan
JOIN user
ON user.id=tkaryawan.id
where user.id= $_SESSION[id]
ORDER BY tanggal DESC";
$result = mysqli_query($koneksi, $query);
if(!$result){
die ("Query Error: ".mysqli_errno($koneksi).
" - ".mysqli_error($koneksi));
}
while($data = mysqli_fetch_assoc($result))
{
$no++;
?>
<tbody>
<tr>
<td><?php echo $no;?></td>
<td><?php echo $data['id'];?></td>
<td class="text-capitalize"><?php echo $data['nama'];?></td>
<td><?php echo $data['golongan'];?></td>
<td><?php echo $data['nilai_output'];?></td>
<td><?php echo $data['nilai_atasan'];?></td>
<td><?php echo $data['nilai_learning'];?></td>
<td><?php echo $data['nilai_kedisiplinan'];?></td>
<td><?php echo $data['nilai_5r'];?></td>
<td class="font-weight-bold text-danger"><?php echo $data['overall'];?></td>
<td class="text-secondary"><?php echo $data['tanggal'];?></td>
<tr>
</tbody>
<?php
}
// free the memory
mysqli_free_result($result);
// close conection
mysqli_close($koneksi);
?>
</table>
appreciate any help you can provide.
EDITED
<?php
$stmt = $mysqli->prepare("SELECT id,nama FROM user WHERE user.id= $_SESSION[id]");
$stmt->execute();
$res = $stmt->get_result();
$row = $res->fetch_assoc();
if(!$row){
mysqli_query($link, $sql);
}
else
{
echo "<h3 class='text-uppercase'>HASIL KINERJA </br> <p class='font-weight-bold text-danger'> $row[nama] </p> </h3>";
}
?>
You put your while loop above tbody which will loop the tbody as well. You need to move the while and its closing tag on <tr>. Also try to change the closing tr tag on tbody to be </tr>.
<table class="table table-bordered table-striped table-fixed text-center" id="myTable">
<thead>
<tr>
<th>No</th>
<th>ID</th>
<th>Nama</th>
<th>Golongan</th>
<th>Nilai Output</th>
<th>Penilaian Atasan</th>
<th>Nilai Learning</th>
<th>Nilai Kedisiplinan</th>
<th>Nilai 5R</th>
<th>Hasil</th>
<th>Tanggal</th>
</tr>
</thead>
<!-- query -->
<?php
$no = 0;
$query = "SELECT * FROM user
where id= $_SESSION[id]";
$query = "SELECT user.id,user.nama,golongan,nilai_output,nilai_atasan,nilai_learning,nilai_kedisiplinan,nilai_5r,overall,tanggal
FROM tkaryawan
JOIN user
ON user.id=tkaryawan.id
where user.id= $_SESSION[id]
ORDER BY tanggal DESC";
$result = mysqli_query($koneksi, $query);
if(!$result){
die ("Query Error: ".mysqli_errno($koneksi).
" - ".mysqli_error($koneksi));
}
?>
<tbody>
<?php
while($data = mysqli_fetch_assoc($result))
{
$no++;
?>
<tr>
<td><?php echo $no;?></td>
<td><?php echo $data['id'];?></td>
<td class="text-capitalize"><?php echo $data['nama'];?></td>
<td><?php echo $data['golongan'];?></td>
<td><?php echo $data['nilai_output'];?></td>
<td><?php echo $data['nilai_atasan'];?></td>
<td><?php echo $data['nilai_learning'];?></td>
<td><?php echo $data['nilai_kedisiplinan'];?></td>
<td><?php echo $data['nilai_5r'];?></td>
<td class="font-weight-bold text-danger"><?php echo $data['overall'];?></td>
<td class="text-secondary"><?php echo $data['tanggal'];?></td>
</tr>
<?php } ?>
</tbody>
<?php
// free the memory
mysqli_free_result($result);
// close conection
mysqli_close($koneksi);
?>
</table>

sql query not working in my webpage

I wrote a MySQL query in my PHP code to join two tables, but I don't want all the columns in the result
My place details table:
My registration table:
My Code
<?php
$con= mysqli_connect("localhost", "root", "", "project");
if(!$con)
{
die('not connected');
}
$result= mysqli_query($con, "SELECT placedetails.name,placedetails.doj,placedetails.total,placedetails.stay,placedetails.food,placedetails.travel,registration.username
FROM placedetails inner join registration on placedetails.id=registration.id ;" );
?>
<div class="container">
<CENTER><h2>view Booking Details</h2>
<table class="table table-bordered">
<th>place</th>
<th>Travelling Date</th>
<th>Total Cost</th>
<th>Stay cost</th>
<th>Food cost</th>
<th>Travelling cost</th>
<th>User ID</th>
<?php
while($row =mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['doj']; ?></td>
<td><?php echo $row['total'] ;?></td>
<td><?php echo $row['stay'] ;?></td>
<td><?php echo $row['food'] ;?></td>
<td><?php echo $row['travel'] ;?></td>
<td><?php echo $row['username'] ;?></td>
<td><img src='".$row['choose']."'/></td>";
</tr>
<?php
}
?>
</table>
</div>
i wrote my code,its executing but the problem is the data is not executing,can someone please help me out with my problem.
MysqlAdmin
In your table place details create a new entry call ID_regist.
After that change or give a number that correspond to your id in tabel Regist.
code php
For the connection create a connection.php.
<?php
$con= mysqli_connect("localhost", "root", "", "project");
if(!$con)
{
die('not connected');
}
?>
Makes your database more difficult to attack
Main code
<?php
include("connection.php");
?>
<div class="container">
<CENTER><h2>view Booking Details</h2>
<table class="table table-bordered">
<th>place</th>
<th>Travelling Date</th>
<th>Total Cost</th>
<th>Stay cost</th>
<th>Food cost</th>
<th>Travelling cost</th>
<th>User ID</th>
<?php
$sql=
"SELECT ".
"pld.name, ".
"pld.doj, ".
"pld.total, ".
"pld.stay, ".
"pld.food, ".
"pld.travel, ".
"pld.username ".
"FROM placedetails pld ".
"inner join registration reg ".
"on pld.ID_regist=reg.id;";
$result= mysqli_query($con, $sql);
if($result){
while($row =mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['doj']; ?></td>
<td><?php echo $row['total'] ;?></td>
<td><?php echo $row['stay'] ;?></td>
<td><?php echo $row['food'] ;?></td>
<td><?php echo $row['travel'] ;?></td>
<td><?php echo $row['username'] ;?></td>
<td><img src='".$row['choose']."'/></td>"; // first there is no row, call chose
</tr>
<?php
}
}
else{
die("Error"); //Something of the type mysqli_error(connection);
}
?>
</table>
</div>
Attention to the row call chose, that you don't use in your sql query.
If that does not solve your problems, tell me what happens when I try to help you.
You have to alter the place table and add registration_id. Then join with this field.
SELECT placedetails.name,placedetails.doj,placedetails.total,placedetails.stay,placedetails.food,placedetails.travel,registration.username
FROM placedetails inner join registration on registration.id=place.registration_id

PHP not displaying last column in table

I am trying to display all the info in the table but when I query the information then put it into a PHP table it doesn't show any data in the last table.
Here is my PHP code for the table
<table border='1'>
<tr>
<th>Ticket ID</th>
<th>Username</th>
<th>Message</th>
<th>Date</th>
<th>Error #</th>
<th>Priority</th>
</tr>
<?php
if(!$query){
die('Invalid query: ' .mysql_error());
}
while ($row = mysql_fetch_array($query)) { ?>
<tr>
<td><?php echo $row['TicketID']; ?></td>
<td><?php echo $row['Message']; ?></td>
<td><?php echo $row['Date']; ?></td>
<td><?php echo $row['Error']; ?></td>
<td><?php echo $row['Priority']; ?></td>
</tr>
<?php } ?>
</table>
Here is the PHP code for query
<?php
$server = mysql_connect("localhost", "root", "**password**");
$db = mysql_select_db("minecraft", $server);
$query = mysql_query("SELECT * FROM tickets");
?>
All of my row names are correct but it doesn't want to put the data into that column.
Here is my table structure
You Omitted
<td><?php echo $row['Username']; ?></td>
that should be after
<td><?php echo $row['TicketID']; ?></td>

Column name field showing multiple time in php?

I am searching records and records are displaying from database, but column name is repeating.Please check below images.
<table border="1" align="center">
<thead>
<tr>
<th>User id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM newrecords_1 WHERE CONCAT( First_name, ' ',Last_name ) LIKE '%$name%' ORDER BY `First_name` ASC";
$result = $conn->query($query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {?>
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
</tbody>
</table>
<?php
}
} else {
echo "0 results";
}
What i am getting
What i need
after added html code on header getting output
Put your table code outside of the loop like below :-
<table border="1" align="center">
<thead>
<tr>
<th>User id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM newrecords_1 WHERE CONCAT( First_name, ' ',Last_name ) LIKE '%$name%' ORDER BY `First_name` ASC";
$result = $conn->query($query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {?>
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
<?php } } else { echo "0 results";}?>
</tbody>
</table>
You are getting header part after every fetching because you are using header part also in loop. Place header part above loop and keep only
below code in loop.
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>

echo items from mysqli_fetch_array into html table td tags not showing up

Here is my code, I get the items to show but nothing will echo in the tags. I tried just removing the php echo statements and just try writing in some text but still nothing. Thanks in advance
<?php
//Create a connection
$connect = mysqli_connect('localhost', 'root', 'bachi619', 'company');
//check connection
if(mysqli_connect_errno($connect)){
echo 'Failed to connecto to database'.mysqli_connect_error();
}
$result= mysqli_query($connect, "SELECT * FROM employees");
?>
<br>
<table width="500", cellpadding=5 callspacing=5 border=1>
<tr>
<th>ID</th>
<th>Name</th>
<th>Last Name</th>
<th>Department</th>
<th>Email</th>
</tr>
<?php while($rows = mysqli_fetch_array($result)): ?>
<tr>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['first_name']; ?></td>
<td><?php echo $rows['last_name']; ?></td>
<td><?php echo $rows['department']; ?></td>
<td><?php echo $rows['email']; ?></td>
</tr>
<?php endwhile; ?>
</table>
You're missing PHP in several places:
<?php
$connect = mysqli_connect('localhost', 'root', '11111', 'company');
if(mysqli_connect_errno($connect)){
echo 'Failed to connecto to database'.mysqli_connect_error();}
$result= mysqli_query($connect, "SELECT * FROM employees");
?>
<table width="500", cellpadding=5 callspacing=5 border=1>
<tr>
<th>ID</th>
<th>Name</th>
<th>Last Name</th>
<th>Department</th>
<th>Email</th>
</tr>
<?php while($rows = mysqli_fetch_array($result)): ?>
<tr>
<td><?php echo $rows['id']; ?></td>
<td><?php echo $rows['first_name']; ?></td>
<td><?php echo $rows['last_name']; ?></td>
<td><?php echo $rows['department']; ?></td>
<td><?php echo $rows['email']; ?></td>
</tr>
<?php endwhile; ?>
</table>
I used to have the same issue. At first I thought mysqli_fetch_array() couldn't work inside tag. But now it finally did. Anyways, after checking your codes have you tried removing the : in <?php while($rows = mysqli_fetch_array($result)): ?>
Because as far as I know you don't need a ; or a : if you're calling a function inside while-loop or any loop function.
Try this:
while($row=mysqli_fetch_assoc($result))

Categories