I am creating a monitor display that needs to be able to display 16 numbers at a time. 8 in one table and 8 in the next table. Right now I have to tables that just keep going down the rows based on the number of entries I have in my MySql data base. What I need is for 2 columns in each table (4 numbers in each column) and limit them to the most recent 8 numbers for each given category.
Here is what I have so far:
Some help would be greatly appreciated, I'm pretty stuck on this, thank you.
$select_query = "SELECT buyback.buyback_callNumber
FROM buyback WHERE buyback.buyback_status = 'In-Progress' ";
$select_query2 = "SELECT buyback.buyback_callNumber
FROM buyback WHERE buyback.buyback_status = 'Ready for Pickup'";
$result = mysql_query($select_query);
echo "
<align='center'>
<div class='span9' >
<table class='table table-striped table-bordered'>
<tr>
<td><strong><h3>In-Progress</h3></strong></td>
</tr>";
while($record = mysql_fetch_array($result)){
echo "<tr>";
echo "
<td><strong><h3>".$record['buyback_callNumber'] ."</h3></strong></td></tr>";
}
echo "</table></div>";
echo "
<div class='span9'>
<table class='table table-striped table-bordered'>
<tr>
<td><strong><h3>Ready</h3></strong></td>
</tr>";
$result2 = mysql_query($select_query2);
while($record2 = mysql_fetch_array($result2)){
echo "<tr>";
echo"
<td><strong><h3>".$record2['buyback_callNumber'] ."</h3></strong></td></tr>";
}
echo "</table></div></align>";
echo "</form> ";
As for limiting results to 8 per table, just add 'LIMIT 8' to each query (you may want to ORDER these queries as well by date or some other field you may have set up)
$select_query = "SELECT buyback.buyback_callNumber
FROM buyback WHERE buyback.buyback_status = 'In-Progress' LIMIT 8";
$select_query2 = "SELECT buyback.buyback_callNumber
FROM buyback WHERE buyback.buyback_status = 'Ready for Pickup' LIMIT 8";
not sure why you want to use table when this can be achieved with div's only.
To align the columns side by side place float:left in the divs you want to show side by side.
<div style="float:left> 1st 4 values </div>
<div style="float:left> 2nd 4 values </div>
just a generic suggestion, avoid using tables for html layout as they are outdated and html has attributes like display: table-row, display: table-cell; to suit the purpose
Related
Hope you are doing great. So I am working on a automated attendance system using face recognition and I am displaying data through php.
I have a SQL database with the name of student_db and there are two tables in it with the name of mark_attendance and student_detail. Face recognition system recgnize faces and send rollnumber and date on mark_attendance
enter image description here
where as student_detail consist of whole class students name and rollnumber.enter image description here enter image description here
I am displaying name, rollnumber and a checkbox on frontend what I want to do is to mark checkbox aUtomatically if student is present. It should compare data of mark_attendance table with the studet_detail table and mark checkbox.
I AM ATTACHING THE CODE I HAVE TRIED BUT ITS NOT WORKING.
<html>
<head></head>
<body>
<table border="1">
<tr>
<th> Name </th>
<th> Attendance </th>
</tr>
<?PHP
include('db_connection.php');
$qry = "SELECT * FROM student_detail";
$result = mysqli_query($db_con, $qry);
$ftch = mysqli_fetch_assoc($result);
$markattendance = "SELECT * FROM mark_attendance ";
$ma = mysqli_query($db_con, $markattendance);
if(mysqli_num_rows($result) > 0)
{
foreach($result as $r)
{
$sav = "SELECT * FROM mark_attendance t1
JOIN student_detail t2
ON t2.rollno = t1.rollno";
$sa = mysqli_query($db_con, $sav);
$s = mysqli_fetch_assoc($sa);
$count = mysqli_num_rows($sa); echo "</b>";
echo "<table><tr>";
echo "<td>".$r['Name']."</td>";
// echo $r['rollno'];
echo $s['rollno'];
if($count >= 1 && $s['rollno'] == $r['rollno']){
echo "<form><td> <input type='checkbox' checked value=".$r['Name']."></td>";
}
else{
echo "<form><td> <input type='checkbox' value=".$r['Name']."></td>";
}
// echo "<form><td> <input type='checkbox' value=".$r['Name']."></td>";
// echo "<td> <input type='text' value=".$r['rollno']."></td></form>";
echo "</tr>";
}
}
?>
</table>
</body>
</html>
Its MARKING only the first data checkbox on db not other after it.
I also have tried with while loop and other stuff but its still not working can you run it on your computer and provide me the working code.
SORRY FOR THE BAD ENGLISH
So I'm trying to make a K/D ratio with some data from a database using SQL.
The main problem is that the tables are so strange and I'm trying to display it as an HTML table.
There's a table called stats_player_kill (when player kills another)
Here's the content of the table:
So if I want to get the kills, I count the killer column with the same id.
Here's how I get number of kills of each player and display it as an HTML table:
<table class="tablitas" id="kills">
<thead>
<tr>
<th data-column-id="name">Player</th>
<th data-column-id="killer" data-type="numeric">Kills</th>
</tr>
</thead>
<?php
$sql = "select p.name as name, count(*) as amountOfObjects
from stats_player_kill b
join stats_player p on p.id = b.victim
group by b.victim
order by count(*) desc
limit 15";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["name"]."</td><td>".$row["amountOfObjects"]."</td></tr>";
}
echo "</tbody>";
echo "</table>";
echo "</td>";
} else {
echo "0 results";
}
?>
So I need help making the math to divide number of kills by the total deaths.
Sorry for my English and thanks to everyone! :D
So I have a table named pins that has 3 columns that need to be taken into consideration. These columns are plan and order_id.
I need to get a count for all of the pins that have an order_id=0 and plan=9.
This is what I have so far:
$qT="SELECT plan, COUNT(*) as cnt FROM pins WHERE order_id=0 and plan=9";
$res=mysql_query($qT);<br/>
mysql_free_result($res);
while($row = mysql_fetch_array($res)) {<br/>
echo $row['plan'];<br/>
}
Any help in displaying the results would be a great help.
Try to group your pin using GROUP BY, So
$result = mysql_query("SELECT plan, COUNT(pin) as cnt FROM pins WHERE (order_id=0 and plan=9) GROUP BY plan");
echo "<table border='1' style='border-collapse: collapse'>";
echo "<th>Plan</th><th>Count</th>";
while ($row = mysql_fetch_array($result))
{
echo "<tr><td>".$row['plan']."</td><td>".$row['cnt']."</td></tr>";
}
echo "</table>";
mysql_free_result($result);
?>
I have created these 3 columns in my mysql table so I can have a list of each users transactions.
ticket_date, ticket_num, ticket_result
I also created a function to echo the value in those columns and it worked successfully.
function.php:
$sql = "SELECT *
FROM members
WHERE user_id = '{$_SESSION['user_id']}'";
$query = $this->db_connection->query($sql);
while ($row = $query->fetch_object()) {
global $me, $me2, $date;
$me = $row->ticket_num;
$me2 = $row->ticket_result;
$date = $row->ticket_date;
}
transactions.php
<table class="table">
<thead>
<th>Date</th>
<th>Ticket ID</th>
<th>Result</th>
</thead>
<tr>
<td><?php echo $date; ?> </td>
<td><?php echo $me; ?> </td>
<td><?php echo $me2; ?> </td>
</tr>
</table>
My problem now is that if a user has more than one transaction how would I be able to echo each value from a particular column separately. I am trying to echo each transaction into a .
Would I be able to store each value as an array so I could call it like this?
$row->ticket_num['0']
EDIT: I meant to ask how can I store the transactions into their respective columns. Such as storing more than one $ticket_date that apply to each transaction. Could I store information into the columns as an array so I can call each transaction using the array pointer?
I think the best thing to do, would be not to use global variables for this, unless there is any reason that your function can't return this data, i.e. it's returning something else. You could have something like this in your function.php:
$sql = "SELECT *
FROM members
WHERE user_id = '{$_SESSION['user_id']}'";
$query = $this->db_connection->query($sql);
$return = array();
while ($row = $query->fetch_object()) {
array_push($return, array($row->ticket_num, $row->ticket_result, $row->ticket_date ));
}
return $return
Then you can do this in your transactions.php:
<table class="table">
<thead>
<th>Date</th>
<th>Ticket ID</th>
<th>Result</th>
</thead>
<?php
$ticket = Whatever_Function();
foreach($ticket as $t){
echo"<tr> <td> ".$t[0]." </td><td>".$t[1]."</td><td>".$t[2]."</td></tr>";
}
?>
</table>
Edit
In relation to your additional question in the comments, a database structure like this should be set up:
By doing this, you are separating it, so that every table belongs to one thing or action. These can then be related to each other using an SQL Join like this:
SELECT * FROM Transactions tr
JOIN Users u ON u.UID = tr.UID
JOIN Tickets ti ON ti.TID = tr.TID
By looking at the above SQL code snippet, you should be able to see how it matches up the columns on the different tables. This creates one big virtual table that you can then search for stuff with, where their column names prepended with their given pseudonyms.
So if you wanted to get the email address of everyone that bought the ticket whose price was over £20, even though the tables you need aren't directly connected you could do:
SELECT u.email FROM Transactions tr
JOIN Users u ON u.UID = tr.UID
JOIN Tickets ti ON ti.TID = tr.TID
WHERE ti.Price > 20
Do something like this:
global $me, $me2, $date;
while ($row = $query->fetch_object()) {
$me[] = $row->ticket_num;
$me2[] = $row->ticket_result;
$date[] = $row->ticket_date;
}
transactions.php
<table class="table">
<thead>
<th>Date</th>
<th>Ticket ID</th>
<th>Result</th>
</thead>
<?php foreach($me as $k => $m){
echo "<tr>";
echo "<td>".$date[$k]."</td>";
echo "<td>".$m."</td>";
echo "<td>".$me2[$k]."</td>";
echo "</tr>";
?>
</table>
I have 2 tables in DB:
clients (Show all clients data)
clientsmany (admin could add many phone numbers for each client)
I would like to print all the details about the clients in 1 html table and if any client has more than phone number, all the numbers are printed in the same cell of 'td'
<?php
$result = mysql_query("SELECT * FROM clients");
$result1 = mysql_query("SELECT clientsmany.phone, clients.ID FROM clients INNER JOIN clientsmany ON clients.ID=clientsmany.ClientID");
while($row = mysql_fetch_array($result)){ //Not read!
while($row1 = mysql_fetch_array($result1)){ //Working correctly and show the list of 'phone' in $row1 for clientsmany.phone
echo "<center><table border='1'>";
echo "<tr><td>".$row['ID']."</td><td>".$row['phone']."<br>".$row1['phone']."</td></tr>";
echo "</table></center>";
}}
?>
Why the 1st while is not working??
The 2nd while only works and print a correct data then it exit automatic!
<?php
echo "<center><table border='1'>";
$result = mysql_query("SELECT * FROM clients");
while($row = mysql_fetch_array($result)){
$result1 = mysql_query("SELECT * FROM clientsmany WHERE clientsid=".$row['id']);
if(mysql_num_rows($result1)>0 ){
while($row1 = mysql_fetch_array($result1)){
echo "<tr><td>".$row['ID']."</td><td>".$row['phone']."<br>".$row1['phone']."</td> </tr>";
}
}else{
echo "<tr><td>".$row['ID']."</td><td>".$row['phone']."</td></tr>";
}
}
echo "</table></center>";
?>
Use GROUP_CONCAT to create a single query and you will be able to a single loop
GROUP_CONCAT will take a column that is repeated and separate each value with a comma (by default it can be changed) and return it into a single value
$query = <<<END
SELECT
clients.*,
GROUP_CONCAT(clientsmany.phone) as phonenums
FROM
clients
INNER JOIN
clientsmany ON clients.ID=clientsmany.ClientID
GROUP BY
clients.ID
END;
A query like this would give you all the clients table columns and a column named phonenums which will be a comma separated list of the phone numbers
Now since you only have one query you only need one loop
$db = mysqli_connect(...);
...
//only need to echo out the <table> part once
//so taken out of the while loop
echo "<center><table border='1'>";
$result = mysqli_query($db,$query);
while( ($row = mysqli_fetch_assoc($result)) ) {
echo <<<END
<tr>
<td>{$row['ID']}</td>
<td>{$row['SomeOtherColumn']}</td>
<td>{$row['phonenums']}</td>
</tr>
END;
}
//Again the </table> only needs done once
//so taken out of the loop
echo "</table></center>";
Notice the mysli_* functions being used. Mysql api is depreciated, for the most part you can just rename the functions you currently use to mysqli_, but note that some require the $db link as a parameter so make sure to read the php manual on each of the functions so you know how to call them correctly.
Also note that I am using heredoc syntax instead of doing multiple echo calls
First, mysql_* functions are depreciated. Try to use mysqli_* functions.
If you want to display data in 1 html table, so why you have started while above table tag?
Try this query..
SELECT clientsmany.phone, clients.* FROM clients, clientsmany WHERE clients.ID=clientsmany.ClientID"
Then use while statement below table tag (No need of 2 different while loop)...
echo "<center><table border='1'>";
while($row1 = mysqli_fetch_array($result1)) {
// your <tr><td> code
}
echo "</table></center>";