Retrieve Total working days (full,half,off day) [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Evening everyone,
i am park, right now i am doing system for my small business.
this is my code.
$query = "SELECT empid, count(t_status)FROM timesheet WHERE t_status = 'Full Day' group by empid";
$result = mysql_query($query)or die (mysql_error());
print "<table\">
<tr>
<th>ID</th>
<th>Total.Full</th>
<th>Total.Half</a></th>
<th>Totah.Off</a></th>
<th>Options</a></th>
</tr>";
while ($row = mysql_fetch_array($result)){
print "<tr>";
print "<td>" . $row['empid']. "</td>";
print "<td>" . $row['count(t_status)']. "</td>";
print "<td>" . $row['HERE FOR HALF DAY TOTAL']. "</td>";
print "<td>" . $row['HERE FOR OFF DAY TOTAL']. "</td>";
print "</tr>";}
print "</table>";
==============================
so, how do i retrieve offdays and halfday total put display it in the next column of "full day".
Dont advise about "PDO" or "MYSQLI" because i will go through about that in the future.TQ.

$query = "SELECT empid, SUM(IF(t_status='Full Day',1,0)) as full_day,
SUM(IF(t_status='Half Day',1,0)) as half_day,
SUM(IF(t_status='Off Day',1,0)) as off_day
FROM timesheet GROUP BY empid";
$result = mysql_query($query)or die (mysql_error());
print "<table>
<tr>
<th>ID</th>
<th>Total.Full</th>
<th>Total.Half</a></th>
<th>Totah.Off</a></th>
<th>Options</a></th>
</tr>";
while ($row = mysql_fetch_array($result)){
print "<tr>";
print "<td>" . $row['empid']. "</td>";
print "<td>" . $row['full_day']. "</td>";
print "<td>" . $row['half_day']. "</td>";
print "<td>" . $row['off_day']. "</td>";
print "</tr>";
}
print "</table>";

Related

Filtering MySQL Database by field result

I am pulling stock data off of a trading API through a loop based on an aray of stock symbols. This spits out xml data which I then parse and input into a MySQL database for analysis later. This is an example of the fields I'm inserting into the database (I can add more):
$sql = "INSERT into securities (symbol, ask, ask_time, asksz)
VALUES ('$symbol', '$ask', '$ask_time','$asksz')";
My current query pulls all of the data and lists it in rows, entry after entry into a table:
$sql = "SELECT id, symbol, ask, ask_time, asksz FROM securities";
if($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>id</th>";
echo "<th>symbol</th>";
echo "<th>ask</th>";
echo "<th>ask_time</th>";
echo "<th>asksz</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['symbol'] . "</td>";
echo "<td>" . $row['ask'] . "</td>";
echo "<td>" . $row['ask_time'] . "</td>";
echo "<td>" . $row['asksz'] . "</td>";
echo "</tr>";
}
echo "</table>";
Is there a way to compare two separate stocks side by side? For instance, structure my query in order to pull those 4 fields only for 'AAPL', then in the same row pull the same data for 'GOOG'?

Syntax error when trying to print something (PHP/SQL) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am a beginner/terrible when it comes to PHP/SQL, keep that in mind. Ok, so what I am trying to do is print some "values" or whatever you could call them with PHP/SQL, like this:
<?PHP
require_once
?>
Now this works just fine.
Just add them like you added the rest of your select columns.
require_once("dbb.php");
$SQL="select
date_format(timestamp,'%Y %M %d') as datum,
arena.namn as arena,
concat(hemma.lagnamn,'-',borta.lagnamn)as lag,
(select count(*) from mål where matchID=matchID and hemma.lagID=hemma) as h,
(select count(*) from mål where matchID=matchID and borta.lagID=borta)as b,
publiksiffror,
hemmagoal,
bortagoal
from
matcher
inner join
lag as hemma
on hemma.lagID = hemma
inner join
lag as borta
on borta.lagID = borta
inner join
arena
on matcher.arena=arena.arenaID;";
$result = mysql_query($SQL) or die(mysql_error());
while($rad = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td>" . $rad[0] . "</td>";
echo "<td>" . $rad[2] . "</td>";
echo "<td>" . $rad[3] . "</td>";
echo "<td>" . $rad[4] . "</td>";
echo "<td>" . $rad[1] . "</td>";
echo "<td>" . $rad[5] . "</td>";
echo "</tr>";
}
?>

How to put user input into a SQL Query

I have a database and I want the user to be able to have an input into what comes out. i.e
Select from Table where example = user input from box **(input by the user)**
Im guessing what I need is a variable to hold the value that then goes into the statement. I know how to get the value from the input box with script but can I use it like:
select * From handover WHERE hdate = variable. However I am guessing someone is going to talk to me about security if its even possible.
<html><body>
<input>User input</input> //That needs to go into statement
<?php
include 'config.php';
$result = mysqli_query($con,"SELECT * FROM handover WHERE hdate = **user input**;");
echo "<table border='1'>
<tr>
<th>hdate</th>
<th>Delay</th>
<th>Health and Safety</th>
<th>Non Vsa</th>
<th>VSA</th>
<th>Dar</th>
<th>Other</th>
<th>Hour</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['hdate'] . "</td>";
echo "<td>" . $row['hdelay'] . "</td>";
echo "<td>" . $row['hs'] . "</td>";
echo "<td>" . $row['nv'] . "</td>";
echo "<td>" . $row['vsa'] . "</td>";
echo "<td>" . $row['dar'] . "</td>";
echo "<td>" . $row['other'] . "</td>";
echo "<td>" . $row['hour'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Any help is welcome and advice on the best language to use for this.
Kind Regards
Fintan
first of all, this question has nothing to do with javascript & ajax. so you can delete those tags.
you want to show/search data from mysql.
$result = mysqli_query($con,"SELECT * FROM handover WHERE hdate = '".$_POST['abc']."' ");
this is when you want to check if hdate column have exact data as user input ( $_POST['abc'] ).
and also don't forget to use mysqli_real_escape_string
you can learn common mysql pattern queries from here: http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html

How to put a break in the output when specific values change using mysqli php

I am building a website to list statistics for bowling tournaments over the last 24 years. Using the following code generates a long, single table showing all the data. I would like to put a break in the table when the $row['season'] value changes, i.e., from 1990-1991 to 1991-1992, and for each subsequent change of seasons and echo either an html horizontal line between seasons or put the value of the season from the database, i.e., 2013-2014 at the top of each table segment. After a week of searching the web haven't figured out an answer. Here's the code I have now. Needs to be mysqli.
$result = mysqli_query($conn,"SELECT * FROM members INNER JOIN scores ON members.id=scores.memberID WHERE format LIKE '%s%' ORDER BY year, STR_TO_DATE( month, '%b' ), format ASC;");
echo "<table border='0'>
<tr>
<th>Name</th>
<th>Hometown</th>
<th>Month</th>
<th>Year</th>
<th>Season</th>
<th>Center</th>
<th>Center City</th>
<th>Format</th>
</tr>";
foreach($result as $row) {
echo "<tr>";
echo "<td>" . $row['firstName'] . " ". $row['lastName'] . "</td>";
echo "<td>" . $row['hometown'] . "</td>";
echo "<td>" . $row['month'] . "</td>";
echo "<td>" . $row['year'] . "</td>";
echo "<td>" . $row['season'] . "</td>";
echo "<td>" . $row['center'] . "</td>";
echo "<td>" . $row['centerCity'] . "</td>";
echo "<td>" . $row['format'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
The answer is actually already given but it looks like your new with php so here is a smal example i hope its useful to you.
You need to insert some if statements to check if there is any change of year. same goes for any other checks you want to perform.
this is something you could do...
<?php
$lastYear = null;//you can also set the first year manually of course
foreach($result as $row) {
//set the first year
if($lastYear == null){$lastYear = $row['year'];}
//check if the year changed or not
if($lastYear == $row['year']){
//if the year didnt change... do something
}else{
//your year changed... do something different
$lastYear = $row['year']; //update your 'last'year
}
}
?>
I hope this will help you.

php mysql echo | How to inherit colors from a submit form?

I'm having some real trouble finding information on this topic and I would be very appreciative for any help. In short I have a form where users select a category from a drop down list, enter some contents, and hit submit which goes to SQL. Each category in the dropdown is color coded:
<option STYLE="color: #00CC66;" value="Option_1">Option_1</option>
<option STYLE="color: #0066CC;" value="Option_2">Option_2</option>
<option STYLE="color: #996633;" value="Option_3">Option_3</option>
etc
Then I have a php that pulls up the stored submitted data (categories and contents) into a table on that same page sorted by date.
<?php
$con=mysqli_connect("localhost","myuser","mypassword","mydb");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM mytable order by date DESC");
echo "<table border='1'>
<tr>
<th>Category</th>
<th>Contents</th>
<th>Date/Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . $row['contents'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
My question is, when echo places the information in the table, is there a way I can get 'category' showing up in the same colors as the user form? (IE, on the table, Option_1 would show up as #00CC66, Option 2 as 0066CC, etc...)
Basically I want the actual category text on the fetched table to display the same as it is in the drop down form. I don't mind if I need to manually set each one as the categories are limited, I just have no clue where to begin on this one. Appreciate any help in advance!
Yes, but you would need to either change the value of the select box to the colour or manually do it like this:
function getColor($strOption)
{
switch ($strOption)
{
case "Option_1":
return "#00CC66";
case "Option_2":
return "#0066CC";
#etc
}
}
Then in your while loop:
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><font color='".getColor($row['category'])."'> " . $row['category'] . "</font></td>";
echo "<td>" . $row['contents'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}

Categories