PHP MySQL HTML Table - Freeze Panes (Multiple Frozen Columns) - php

Really stuck on this one. Spent a couple hours fiddling and no results so asking here...
Tried solutions from html/CSS to Javascript and jQuery, but couldn't get anything to work. Basically trying to accomplish freeze panes like in Excel with the below table. For this I am most interested in freezing the first 4 columns. I might be interested in freezing the first 'header' column too, but not as important.
This is an example, but I will likely use this is a situation where I have multiple tables on a single page (so thinking if we had a frozen header it would need to stop at the end of each table).
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "
SELECT fac_id, abc_id, provider_id, fac_name, status, lob, service_level, rate, start_date, end_date, fiscal_month_end, month_start, region, area, bd, pd, phone_pd, ps, total_beds, licensed_beds, address, city, state, zip, phone_office, logo_1, logo_2
FROM table_db
WHERE status = 'ACTIVE' AND lob = '123' AND area = 'Smith'
ORDER BY region ASC, area ASC, fac_name ASC
";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table cellpadding=5><tr><th>Fac ID</th><th>ABC ID</th><th>Provider ID</th><th>Fac Name</th><th>Service Level</th><th>Rate</th><th>Start Date</th><th>Fiscal Month End</th><th>Month Start</th><th>Region</th><th>Area</th><th>BD</th><th>PS</th><th>PD</th><th>PD Phone</th><th>Total Beds</th><th>Licensed Beds</th><th>Address</th><th>City</th><th>State</th><th>Zip</th><th>Office Phone</th><th>Logo 1</th><th>Logo 2</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["fac_id"]. "</td><td>" . $row["abc_id"]. "</td><td>" . $row["provider_id"]. "</td><td>" . $row["fac_name"]. "</td><td>" . $row["service_level"]. "</td><td>" . $row["rate"]. "</td><td>" . $row["start_date"]. "</td><td>" . $row["fiscal_month_end"]. "</td><td>" . $row["month_start"]. "</td><td>" . $row["region"]. "</td><td>" . $row["area"]. "</td><td>" . $row["bd"]. "</td><td>" . $row["ps"]. "</td><td>" . $row["pd"]. "</td><td>" . $row["phone_pd"]. "</td><td>" . $row["total_beds"]. "</td><td>" . $row["licensed_beds"]. "</td><td>" . $row["address"]. "</td><td>" . $row["city"]. "</td><td>" . $row["state"]. "</td><td>" . $row["zip"]. "</td><td>" . $row["phone_office"]. "</td><td><a href='/logo/" . $row["logo_1"]. "'>" . $row["logo_1"]. "</a></td><td><a href='/logo/" . $row["logo_2"]. "'>" . $row["logo_2"]. "</a></td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
</body>
</html>

Related

reading seconds from mysql and convert to hours

So im basically a complete beginner in php/mysql this is the current code:
$sql = "SELECT id, userid, date, rig, hash, miner_hashes, temp, fanrpm, rack_loc,ip, uptime, gpus, driver, cpu_temp, miner, miner_version, mem, powertune, fanpercent, voltage, miner_secs, version FROM hash WHERE rig='bbf3ec' ORDER BY ID DESC LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>"
. $row["version"]. "</td><td>"
. $row["driver"] . "</td><td>"
. $row["gpus"] . "/8</td><td>"
. $row["miner"] . "</td><td>"
. $row["miner_version"] . "</td><td>"
. $row["miner_secs"] . "</td><td>"
. $row["rig"] . "</td><td>"
. $row["rack_loc"] . "</td><td>"
. $row["ip"] . "</td><td>"
. $row["cpu_temp"] . "c</td><td>"
. $row["hash"] . "</td><td>"
. $row["miner_hashes"] . "</td><td>"
. $row["temp"] . "</td><td>"
. $row["voltage"] . "</td><td>"
. $row["fanpercent"] . "</td><td>"
. $row["powertune"] . "</td><td>"
. $row["mem"]. "</td></tr>";
}
echo "";
} else { echo "0 results"; }
Currently I'm just printing miner_secs value as INT from database, but I want it to convert to hours first and then to insert it into a row, any idea on how to do that?
Just once again I'am a complete beginner in this stuff, every explanation is highly appericated!
You can still do calculations on the minor_secs even if it is a string.
. round(($row['miner_secs']/60)/60,2) . "</td><td>"
I'm dividing the output by 60 and then 60 again. Then rounding it to avoid insane precision.

How to display MySQL data based on a column field

I am trying to make an appointment maker for potential customers. The hours that are available will depend greatly on personal schedules, so I don't want a generic calendar type appointment maker. What I was trying was an SQL DB with 4 columns [ID, Made, Date, Time] with the following types [INT, BIT, VARCHAR, VARCHAR].
When SELECTing my data and displaying it, I am attempting to have an IF statement (PHP) determine if "Made" is "00" or "01" - 00 being "appointment available", 01 being "taken".
The output does display all the rows; however, it is showing all the rows as "appointment available". One of my rows has "01" in the "Made" column, and it is still showing as available.
PHP/SQL Script after connection:
$sql = "SELECT * FROM $tname";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if ($row["Made"] = '00') {
echo "<tr><td>" . $row["ID"] . "</td><td>" . 'Make An Appointment' . "</td><td>" . $row["Date"] . "</td><td>" . $row["Time"] . "</td></tr>";
}
elseif ($row["Made"] = '01') {
echo "<tr><td>" . $row["ID"] . "</td><td>" . 'Reserved' . "</td><td>" . $row["Date"] . "</td><td>" . $row["Time"] . "</td></tr>";
}
}
}
This is the link to the output on the website:
http://www.jpegchaos.com/appointment.php
I will continue to re-upload the .php with any attempts to see if new information displays.
Line 2 should show "Reserved" while 1 and 3 should be "Make an Appointment"
Thank you in advance
You need to use ==, not = when you're checking the $row["Made"]. As you have it now, the first if statement is always true, so it never gets to the elseif. Try this:
$sql = "SELECT * FROM $tname";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if ($row["Made"] == '00') {
echo "<tr><td>" . $row["ID"] . "</td><td>" . 'Make An Appointment' . "</td><td>" . $row["Date"] . "</td><td>" . $row["Time"] . "</td></tr>";
}
elseif ($row["Made"] == '01') {
echo "<tr><td>" . $row["ID"] . "</td><td>" . 'Reserved' . "</td><td>" . $row["Date"] . "</td><td>" . $row["Time"] . "</td></tr>";
}
}
}

PHP MySQL scoreboard with link to profile page

I have a wordpress site with a scoreboard that gets results from a view in the wp database and I ve set up the board on a custom page template.My trouble is to link the players in the scoreboard to a new page with players stats etc. I want to be able to click the player name in the scoreboard and then get to a page with stats for that player.
Here is the relevant code that displays the scoreboard:
<?php //Table with SQL Query
$connection = mysql_connect('localhost', 'root', '');
mysql_set_charset('utf8',$connection);
mysql_select_db('worldsbestblog');
$query = "SELECT * FROM Sammenlagt LIMIT 0,20";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){ //Loop through results
echo "<tr><td>" . $row['Dato'] . "</td>
<td>
" . $row['Navn'] . "
</td>
<td>" . $row['hull1'] . "</td><td>" . $row['hull2'] .
"</td><td>" . $row['hull3'] . "</td><td>" . $row['hull4'] .
"</td><td>" . $row['hull5'] . "</td><td>" . $row['hull6'] .
"</td><td>" . $row['hull7'] . "</td><td>" . $row['hull8'] .
"</td><td>" . $row['hull9'] . "</td><td>" . $row['hull10'] .
"</td><td>" . $row['hull11'] . "</td><td>" . $row['hull12'] .
"</td><td>" . $row['hull13'] . "</td><td>" . $row['hull14'] .
"</td><td>" . $row['hull15'] . "</td><td>" . $row['hull16'] .
"</td><td>" . $row['hull17'] . "</td><td>" . $row['hull18'] .
"</td><td>" . $row['Sammenlagt'] . "</td><td>" . $row['Par'] .
"</td><td>" . $row['Poeng'] . "</td></tr>"; //$row['index'] the index here is a column name
}
?>
I've seen countless similar questions where SESSIONS, $_POST and $_GET has been used though I havent been able to either understand or see how/if thats what's missing in order to make it work.
As it is now i get a URL showing the userid of player, but when clicked, wordpress cant find that page.
[edit]
OK I have done some editing and found an answer to my question. Unsure how to go about here on stackoverflow (direct me if I should do this elsewhere), but I want to show you what did the job so that the next guy will find this post with an explanation.
So here is the current code and thanks to #Cal Evans and #Hamed Momeni for helpful guidance:
Scoreboard goes:
$query = "SELECT * FROM Sammenlagt";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['Dato'] . "</td>
<td>
" . $row['Navn'] . "
</td>
<td>" . $row['hull1'] . "</td><td>" . $row['hull2'] .
"</td><td>" . $row['hull3'] . "</td><td>" . $row['hull4'] .
"</td><td>" . $row['hull5'] . "</td><td>" . $row['hull6'] .
"</td><td>" . $row['hull7'] . "</td><td>" . $row['hull8'] .
"</td><td>" . $row['hull9'] . "</td><td>" . $row['hull10'] .
"</td><td>" . $row['hull11'] . "</td><td>" . $row['hull12'] .
"</td><td>" . $row['hull13'] . "</td><td>" . $row['hull14'] .
"</td><td>" . $row['hull15'] . "</td><td>" . $row['hull16'] .
"</td><td>" . $row['hull17'] . "</td><td>" . $row['hull18'] .
"</td><td>" . $row['Sammenlagt'] . "</td><td>" . $row['Par'] .
"</td><td>" . $row['Poeng'] . "</td></tr>"; //$row['index'] the index here is a column name
}
?>
.../wordpress/teststats is a new page with a custom page template with the following code:
<?php
$spid = (int) filter_input(INPUT_GET,'id', FILTER_SANITIZE_NUMBER_INT);
$spillerquery = mysql_query("SELECT * FROM Sammenlagt WHERE spillerid='$spid'") or die ("Somthing went wrong!!");
if (mysql_num_rows($spillerquery) < 1){
die ("Couldnt find that player");
}
$navnequery = mysql_query("SELECT Navn FROM Sammenlagt WHERE spillerid='$spid'") or die ("Player does not exist");
$spillernavn = mysql_result($navnequery,MYSQL_BOTH);
?>
<h2>Her er <?php echo "$spillernavn"; ?> sine resultater</h2>
<?php
while($row = mysql_fetch_array($spillerquery, MYSQL_ASSOC)){
echo "<tr><td>" . $row['Dato'] .
"</td><td>" . $row['hull1'] . "</td><td>" . $row['hull2'] .
"</td><td>" . $row['hull3'] . "</td><td>" . $row['hull4'] .
"</td><td>" . $row['hull5'] . "</td><td>" . $row['hull6'] .
"</td><td>" . $row['hull7'] . "</td><td>" . $row['hull8'] .
"</td><td>" . $row['hull9'] . "</td><td>" . $row['hull10'] .
"</td><td>" . $row['hull11'] . "</td><td>" . $row['hull12'] .
"</td><td>" . $row['hull13'] . "</td><td>" . $row['hull14'] .
"</td><td>" . $row['hull15'] . "</td><td>" . $row['hull16'] .
"</td><td>" . $row['hull17'] . "</td><td>" . $row['hull18'] .
"</td><td>" . $row['Sammenlagt'] . "</td><td>" . $row['Par'] .
"</td><td>" . $row['Poeng'] . "</td></tr>";
}
?>
Try this.
<?php
//Table with SQL Query
$player_id = (int) filter_input(INPUT_GET,'id', FILTER_SANITIZE_NUMBER_INT);
$connection = mysql_connect('localhost', 'root', '');
mysql_set_charset('utf8',$connection);
mysql_select_db('worldsbestblog');
$query = "SELECT * FROM Sammenlagt where player_id = {$player_id} LIMIT 0,20";
$result = mysql_query($query);
Although, I do agree with #Hamed that you should be using $wpdb instead of creating your own connection. This is assuming that your table is in the same database as your WordPress tables.
If you're actually using Wordpress I suggest you use the provided $wpdb object for your Database needs.
The other suggestion is when using Wordpress you need to use template files for creating different pages. You can create different page templates for various pages inside Wordpress. That way you can use the Wordpress rerouting engine for its powerful and easy features.
For example imagine you want to create a page for player stats. First create a file with the name tpl-player_stats.php inside your theme dir with the following header:
<?php
/*
Template Name: Player Stats Page
*/
And then inside Wordpress dashboar create a page and assign the above template to it. After that you can go to your page by going to http://example.com/your_page_slug/?id=player_id.
Generally this is how it's done with Wordpress. So I suggest you dig into that.

How to make a link this is connected to database in php

I am trying to make a php script which will get clients data from database in a table. the script works fine and is getting database fields correctly. Now i want to add a link beside every client info. The link should be like www.domain.com/check?clientid=$id&number=$phonenumber
How should i do this?
its a table and clients details are arranged in order. Please help me?
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname, phonenumber, city, country, email FROM clients ORDER BY ID ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th><th>Phone Number</th><th>Country</th><th>Email</th><th>Send SMS</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]. "</td><td>" . $row["phonenumber"]. "</td><td>" . $row["city"]. " "
. $row["country"]. "</td><td>" . $row["email"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
I agree with Marcosh (in the comments), so that would give you this code (between the if(...) { and } else):
echo "<table><tr><th>ID</th><th>Name</th><th>Phone Number</th><th>Country</th><th>Email</th><th>Send SMS</th><th>Link to page</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]."</td><td>" . $row["phonenumber"]. "</td><td>" . $row["city"]. " ". $row["country"]. "</td><td>" . $row["email"]. "</td><td>Click me!</td></tr>";
}
echo "</table>";
Note 1: This will add a link with the text "Click me!". I think you may want to change that. You may also want to change the header (currently "Link to page")
Note 2: If you use php 5.5 or later, you can also use
echo "blablabla<td>{$row['id']}</td>etc..."
instead of
echo "blablabla<td>" . $row['id'] . "</td>etc..."
Thanks for help #ivo and i have learned how to get this thing done:
<td><form action='https://control.domain.com/api/sendhttp.php' method='GET'><input type='hidden' name='authkey' value='74685AiSz3dkBX5467773f'><input type='hidden' name='mobiles' value='" . $row['phonenumber'] . "'><input type='hidden' name='sender' value='hostbi'><input type='hidden' name='route' value='4'><textarea name='message' cols='55'>Leave a message</textarea><input type='submit' value='Click me!'></form></td>

How to insert button for every row so that the data for that particular row can be duplicated into the database

I have read through several questions on stackoverflow before asking this. I have very little knowledge on php and mysql so much help is needed.
So, what I needed is to create a button for every table row so that when user hits the "copy" button, the data for that row will be copied into the database. How can I do this?
demotable.php (//EDIT//)
<?php
require('connect.php');
$query = "SELECT * FROM trade_history1 ";
$result = mysql_query($query);
echo "<table border = '1px'>"; // start a table tag in the HTML
echo "<tr><td>" . "ID" . "</td><td>" . "Date" . "</td><td>" . "Type" . "</td><td>" . "Size" . "</td><td>" . "Currency Pair" . "</td><td>" . "Entry" . "</td><td>" . "Stoploss" . "</td><td>". "Take Profit" . "</td><td>" . "Date Close" . "</td><td>" ."Close" . "</td><td>" ."Profit/Loss"."</td><td>" ."Copy"."</td></tr>" ; //$row['index'] the index here is a field name
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['date'] . "</td><td>" . $row['type'] . "</td><td>" . $row['size'] ."</td><td>" . $row['currency_pair'] ."</td><td>" . $row['entry'] ."</td><td>" . $row['stoploss'] ."</td><td>" . $row['takeprofit'] ."</td><td>" . $row['dateclose'] ."</td><td>" . $row['close'] ."</td><td>" . $row['profitloss'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysql_close(); //Make sure to close out the database connection
?>
<html>
View
</html>
copytrade.php
<?php
require ('connect.php');
$mysqli = new mysqli($database_hostname, $database_username, $database_password, $database_name) or exit("Error connecting to database");
$stmt = $mysqli->prepare("INSERT INTO trade_history1 (size, date, type, currency_pair, entry, stoploss, takeprofit, dateclose,close,profitloss)
SELECT size, date, type, currency_pair, entry, stoploss, takeprofit, dateclose,close,profitloss
FROM trade_history1
WHERE id = ?");
$stmt->bind_param("i", $id); //
$successfullyCopied = $stmt->execute();
$stmt->close();
$mysqli->close();
?>
By the way, whenever I click the "copy button" on demotable.php, the link will be this: http://localhost/1103242B/demo/copytrade.php?copy=copy. May I know which part of the code did I missed out or did I do wrongly? Thanks.
You have to put all your table design in the form tag. And then for each row you have to add a copy link with url something like http://localhost/1103242B/demo/copytrade.php?id=id. Here id is the record id from database. You are generating the table above and then in below form you don't have any id reference to copytrade.php page.
That way also you can do that but in each row you can put some checkbox and then when user clicks on checkbox set the id in a hidden field inside the form and then you can able to post that id to copytrade.php.
Both way it will work.
Try to edit your page like below.
<html>
<form method = "GET" action = "copytrade.php">
<?php
require('connect.php');
$query = "SELECT * FROM trade_history1 "; //You don't need a ; like you do in SQL
$result = mysql_query($query);
echo "<table border = '1px'>"; // start a table tag in the HTML
echo "<tr><td>" . "ID" . "</td><td>" . "Date" . "</td><td>" . "Type" . "</td><td>" . "Size" . "</td><td>" . "Currency Pair" . "</td><td>" . "Entry" . "</td><td>" . "Stoploss" . "</td><td>". "Take Profit" . "</td><td>" . "Date Close" . "</td><td>" ."Close" . "</td><td>" ."Profit/Loss"."</td><td>" ."Copy"."</td><td>Copy</td></tr>" ; //$row['index'] the index here is a field name
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['date'] . "</td><td>" . $row['type'] . "</td><td>" . $row['size'] ."</td><td>" . $row['currency_pair'] ."</td><td>" . $row['entry'] ."</td><td>" . $row['stoploss'] ."</td><td>" . $row['takeprofit'] ."</td><td>" . $row['dateclose'] ."</td><td>" . $row['close'] ."</td><td>" . $row['profitloss'] . "</td><td>a href='copytrade.php?id=" .$row['id'].'">copy</a></td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysql_close(); //Make sure to close out the database connection
?>
<input type = "submit" name = "copy" value = "copy"/></form>
</html>

Categories