Specific information on how to insert into html table - php

I am trying to use the results of a database and display them in an HTML table. I've searched around but can't find a specific answer for my situation as I am new to PHP and I had to copy this code from another source because I was unable to get it to work on my own. Please help.
<?php $server = "127.0.0.1";
$user = "admin";
$pass = "password";
$dbname = "hysteryalelogs";
// Create connection in mysqli
$connection = new mysqli($server, $user, $pass, $dbname);
//Check connection in mysqli
if($connection->connect_error){
die("Error on connection:" .$connection->connect_error);
}
//Display the informaion
$sql = "SELECT * FROM logs";
$res = $connection->query($sql);
if($res->num_rows > 0){
while($row = $res->fetch_assoc()){
echo "Sales Number: ". $row["Sales_Number"]. "<br/>";
echo "Quantity: ". $row["Quantity"]. "<br/>";
echo "Due Date: ". $row["Due_Date"]. "<br/>";
echo "Burnished Housing: ". $row["Burnished"]. "<br/>";
echo "Greased Bearings: ". $row["Grease"]. "<br/>";
echo "Air Cleaned: ". $row["Air"]. "<br/>";
echo "SS Screw: ". $row["Screw"]. "<br/>";
echo "Test Date: ". $row["Test_Date"]. "<br/>";
echo "Pass: ". $row["Pass"]. "<br/>";
echo "Fail: ". $row["Fail"]. "<br/>";
echo "Tester: ". $row["Tester"]. "<br/>";
echo "Final Check: ". $row["Final_Check"]. "<br/>";
echo "Green Dot: ". $row["Green_Dot"]. "<br/>";
echo "Green Dot Check: ". $row["Green_Dot_Check"]. "<br/>";
echo "Ship Date: ". $row["Ship_Date"]. "<br/>";
echo "Serial Number: ". $row["Serial_Number"]. "<br><br><hr><br/>";
}
} else {
echo "No Record Found!";
}
$connection->close();
?>
(clarification) The code works. I Just don't know how to format the table for it to display inside.

Hi :) Hope this helps :)
<?php
$server = "127.0.0.1";
$user = "admin";
$pass = "password";
$dbname = "hysteryalelogs";
// Create connection in mysqli
$connection = new mysqli($server, $user, $pass, $dbname);
//Check connection in mysqli
if($connection->connect_error){
die("Error on connection:" .$connection->connect_error);
}
//Display the informaion
$sql = "SELECT * FROM logs";
$res = $connection->query($sql);
if($res->num_rows > 0){
echo "<table border='3px' cellpadding='5px' cellspacing='5px' align='center' bgcolor='skyblue' ";
echo "<tr>";
echo "<td><center><strong>Sales Number</strong></center></td>";
echo "<td><center><strong>Quantity</strong></center></td>";
echo "<td><center><strong>Due Date</strong></center></td>";
echo "<td><center><strong>Burnished Housing</strong></center></td>";
echo "<td><center><strong>Greased Bearings</strong></center></td>";
echo "<td><center><strong>Air Cleaned</strong></center></td>";
echo "<td><center><strong>SS Screw</strong></center></td>";
echo "<td><center><strong>Test Date</strong></center></td>";
echo "<td><center><strong>Pass</strong></center></td>";
echo "<td><center><strong>Fail</strong></center></td>";
echo "<td><center><strong>Tester</strong></center></td>";
echo "<td><center><strong>Final Check</strong></center></td>";
echo "<td><center><strong>Green Dot</strong></center></td>";
echo "<td><center><strong>Green Dot Check</strong></center></td>";
echo "<td><center><strong>Ship Date</strong></center></td>";
echo "<td><center><strong>Serial Number</strong></center></td>";
echo "</tr>";
while($row = $res->fetch_assoc()){
echo "<tr>";
echo "<td>"."<center>"."<i>".$row["Sales_Number"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Quantity"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Due_Date"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Burnished"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Grease"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Air"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Screw"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Test_Date"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Pass"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Fail"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Tester"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Final_Check"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Green_Dot"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Green_Dot_Check"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Ship_Date"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Serial_Number"]."</i>"."</center>"."</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "No Record Found!";
}
$connection->close();
?>

Related

How can I return a value to html tag

<td> <?php echo $b; ?> </td>
I am trying to put the "ad_soyad" value to the table by returning the "ad_soyad" value to the HTML table code above. I have tried return value but it doesn't work. Any suggestions?
function func2()
{
$servername = "127.0.0.1";
$username = "root";
$password="";
$database = "customer_list";
$port = 3306;
$con = mysqli_connect($servername,$username,$password, $database, $port);
$sql = "SELECT ad_soyad,telefon,e_posta,cari_kart_kodu,olusturma_tarihi,guncelleme_tarihi FROM customer_list";
$result =$con->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "ad soyad:".$row["ad_soyad"]." ";
echo "<br>";
$aa = $row["ad_soyad"];
echo "telefon:".$row["telefon"]." ";
echo "<br>";
echo "eposta:".$row["e_posta"]." ";
echo "<br>";
echo "Cari Kart Kodu:".$row["cari_kart_kodu"]." ";
echo "<br>";
echo "Oluşturma Tarihi:".$row["olusturma_tarihi"]." ";
echo "<br>";
echo "Guncelleme Tarihi:".$row["guncelleme_tarihi"]." ";
echo "<br>";
echo "<br>";
echo "<br>";
}
;
}

How To get AM PM Time format from a phpMyAdmin table using mysqli_fetch_array

I have tried everything I can find to try and get time formatted results from my table using mysql_fetch_array while also getting other results.
This is my code:
<?php
$con = new mysqli("mysql.hostinger.co.uk", "user", "password", "database");
$con->set_charset('utf8mb4');
//Retrieve all the data from the Update Log Table
$result = $con->query("SELECT requestID, songTitle, artistName, requester, dedicatedTo, TIME_FORMAT(requestTime, '%r'), dance FROM `table` ORDER BY requestID DESC") or die(mysql_error());
echo "<form class='formleft'>";
//keeps getting the next row until there are no more to get
while($row = mysqli_fetch_array($result)){
//Print out the contents of each row into a table
echo "<div class='reqgap'></div>";
echo "<input type='checkbox' id='play";
echo $row['requestID'];
echo "' class='play checkbox' autocomplete='off' ";
if ($row['requestID'] == '0') {
echo "style='display:none;' />";
} else {
echo "/>";
};
echo "<label class='played' for='play";
echo $row['requestID'];
echo "' ";
if ($row['requestID'] == '0') {
echo "hidden >";
} else {
echo ">";
};
echo "Played";
echo "</label>";
echo "<article class='request songs req";
echo $row['requestID'];
if ($row['requestID'] % 2 == 0) {
echo " even";
} else {
echo " odd";
};
echo "' >";
echo "<article class='requestleft'>";
echo "<article class='requestnum'>";
echo "<p class='requestnumt'>";
if ($row['requestID'] == '') {
echo "RequestID Error";
} else {
echo $row['requestID'];
}
echo "</p>";
echo"</article>";
echo "<article class='requesttime'>";
echo "<p class='requesttimet'>";
if ($row['requestTime'] == '') {
echo "Request Time Error";
} else {
echo $row['requestTime'];
}
echo " UTC</p>";
echo"</article>";
It just shows my error message "Request Time Error" when it comes to displaying that data.
Any assistance will be greatly appreciated

Calculate and print passed (%) for each application for each table

Right now I could list each application/(Internal Team Names) name in table. Now I want to find out passed (%) from each table for each application and print on html page. Each "aw..." table has all application/(Internal Team Names) names and respective result also.
<html>
<?php
$Show= htmlspecialchars($_GET["Show"]);
$team= htmlspecialchars($_GET["team"]);
$tablename = htmlspecialchars($_GET["tablename"]);
$servername="localhost";
$username="root";
$password="";
?>
<?php
// Create connection with mySQL
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed:" . mysqli_connect_error());
}
//echo "Connected to mysql successfully";
//select a database to work with
mysqli_query( $conn , "USE plm_dashboard" );
Echo "<Body bgcolor="."white".">" ;
//echo $Show;
Echo "<br>";
Echo "<br>";
Echo "Applied Filters Are <br> ";
//echo "Team = $team "; echo "TableName= $tablename ";
$Local_team= "Reports";
if ($Show == "failed"){
$Result_status = "passed";
} else {
// in this case the value of the $Result_status is 'all'
$Result_status = "";
}
echo "Result = $Show <br>";
//$result =mysqli_query($conn ,"SELECT * FROM aw34_0605_tc1122 where Application="."'".$team."'");
$result = mysqli_query($conn ,"SELECT * FROM teamnames");
$result1 =mysqli_query($conn ,"SELECT * FROM aw34_0530_tc1015 (Select count(id) from aw34_0530_tc1015 where result ='passed' and application='ace')/(Select count(id) from aw34_0530_tc1015 where application='ace')*100");
//$result =mysqli_query($conn ,"SELECT * FROM ". $tablename );
//********** determine number of rows result set **********/
// $row_cnt = $result->num_rows;
//mysqli_query()
//echo "Showing $row_cnt Results ";
//echo "<table border="."1".">
echo "<table border="."1"."align="."right".">
<tr>
<th>ID</th>
<th>Internal Team Names</th>
<th width="."10px"." >Passed % for aw34_0530_tc1015</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['TeamInternalNames'] . "</td>";
echo "<td>" . $row['TeamName'] . "</td>";
// if ($row['Result'] == "passed") {
// echo "<td style="."background-color:#33FF38".">P</td>";
// } else {
// echo "<td style="."background-color:#FF334C".">F</td>";
// }
echo "</tr>";
}
echo "</table>";
ECHO "BYE";
mysqli_close($conn);
Echo "<Body>";
?>
</html>

Ajax call works in stand alone, but fails in wordpress

This code is working in stand alone, but when it gets put into wordpress it gives a series of errors related to the ajax call. The first problem it had was that it couldn't read the jquery from the remote source so I downloaded the file and have it read internal to the server, but these errors are still left and I'm not sure how to correct this. Note that in wordpress, I use a plugin that allows me to use [php] and [/php] to use php within wordpress.
<?php
$page_to_load = $_POST[view];
switch($page_to_load) {
case '':
echo "<script src=\"../scripts/jquery-3.2.0.min.js\"></script>";
echo "<script type=\"application/javascript\" src=\"../scripts/raid.js\"></script>";
echo "<font size=\"+3\" color=\"#FFFFFF\">Who should I host?<br>Please wait while channel is selected<br></font>";
echo "<font size=\"+2\">";
echo "<br><br>";
echo "<img src=\"../_images/ajax_loader_blue_350.gif\">";
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$chanarray[] = null;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT `TwitchNames` FROM TK_Members WHERE Validated='1' AND RaidMe='1'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
array_push($chanarray, $row['TwitchNames']);
}
} else {
echo "0 results";
}
array_splice($chanarray, 0, 1);
$conn->close();
echo "<script type=\"application/javascript\">";
echo "var channels = ". json_encode($chanarray);
echo "</script>";
echo "</font>";
echo "<form id=\"form\" method=\"post\">";
echo "<input type=\"hidden\" name=\"view\" value=\"page2\">";
echo "</form>";
break;
case 'page2':
echo "<font size=\"+3\" color=\"#FFFFFF\">Who should I host?<br>";
echo "Your channel to host is:<br></font>";
echo "<font size=\"+2\">";
echo "<br><br>";
$chans[] = null;
$test = $_POST['outArray'];
foreach ($test as $chan) {
$temparray = array(rand(),$chan);
array_push($chans, $temparray);
}
array_splice($chans,0,1);
sort($chans);
echo "".$chans[0][1]."";
echo "<br><br><br>";
echo "See All Live Channels";
echo "</font>";
break;
}
?>
Here are the errors:
Change $(document).ready(function() { to jQuery(function($){ because WordPress runs jQuery in no-conflict mode.
Source: https://wordpress.org/support/topic/simple-jquery-not-working/

Mysqli query returns no rows

For whatever reason, I keep getting the echo "No News."; even though I clearly have information put into the table which is named news.
<?php
session_start();
define('DB_SERVER', "localhost");
define('DB_USER', "USERNAME");
define('DB_PASSWORD', "PASSWORD");
define('DB_DATABASE', "DATABASE");
$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
// Check connection
if(mysqli_connect_errno()) {
echo "Email Owner#OtherTXT.com";
exit();
}
/* create a prepared statement */
$query = "SELECT `title`, `message`, `date` FROM `news`";
$result = $mysqli->query($query);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<h2>";
echo ($row["title"]);
echo "</h2>";
echo "<h3>";
echo ($row["date"]);
echo "</h3>";
echo "<br />";
echo "<p>";
echo ($row["message"]);
echo "</p>";
}
} else {
echo "No News.";
}
$mysqli->close();
?>
This is a picture of my table
Hope this will help ;)
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<h2>";
echo ($row["title"]);
echo "</h2>";
echo "<h3>";
echo ($row["date"]);
echo "</h3>";
echo "<br />";
echo "<p>";
echo ($row["message"]);
echo "</p>";
}
} else {
echo "No News.";
}
Maybe adding a store_result before calling the num rows do the trick:
$result = $mysqli->query($query);
$result->store_result();
if ($result->num_rows > 0) {
...
Or you can put it into the query:
$result = $mysqli->query($query,MYSQLI_STORE_RESULT);

Categories