I am designing a table that retrieved from database and when user hover on of the value in the table, it should gather the corresponding data from the db and show it on tooltip. when i do select query for all value in the table, the tooltip doesnt work. But when I query only 1 particular item in the database it works like a charm. I dont know whats wrong with this. Please help me,
code,
$fabSql = "SELECT FABRICATION.*,
MASTER_DRAWING.WEIGHT
FROM FABRICATION, MASTER_DRAWING
WHERE FABRICATION.HEAD_MARK = MASTER_DRAWING.HEAD_MARK";
$fabParse = oci_parse($conn, $fabSql);
oci_execute($fabParse);
while (($row = oci_fetch_array($fabParse, OCI_BOTH)) != false)
{
$totalFabPercentage = (($row['MARKING']*$markingPercentage)+($row['CUTTING']*$cuttingPercentage)+($row['ASSEMBLY']*$assemblyPercentage)+
($row['WELDING']*$weldingPercentage)+($row['DRILLING']*$drillingPercentage)+($row['FINISHING']*$finishingPercentage));
echo '<tr>';
echo '<td>'.$row['HEAD_MARK'].'</td>';
echo '<td>'.$row['ID'].'</td>';
if ($row['MARKING'] == 1){
echo '<td align="center" title="SIGNED BY : '.$row['MARKING_FAB_SIGN'].' on '.$row['MARKING_FAB_DATE'].'" class="jquery-tooltipped"><span class="glyphicon glyphicon-ok greenyellow"></span>';
} elseif ($row['MARKING'] == 0) {
echo '<td align="center"><span class="glyphicon glyphicon-refresh grey"></span>';
} else {
echo '<td align="center"><span class="glyphicon glyphicon-flag red"></span>';
}
if ($row['CUTTING'] == 1){
echo '<td align="center"><span class="glyphicon glyphicon-ok greenyellow"></span>';
} elseif ($row['CUTTING'] == 0) {
echo '<td align="center"><span class="glyphicon glyphicon-refresh grey"></span>';
} else {
echo '<td align="center"><span class="glyphicon glyphicon-flag red"></span>';
}
}
}
but when i do query like this, the tooltip works,
$fabSql = "SELECT FABRICATION.*,
MASTER_DRAWING.WEIGHT
FROM FABRICATION, MASTER_DRAWING
WHERE FABRICATION.HEAD_MARK = MASTER_DRAWING.HEAD_MARK
AND FABRICATION.HEAD_MARK = 'SMS-MH-BM1'";
Related
I need to change a value depending a result.
In this case, if my row "status" is "Active" I want to put something like that in a table:
<td>'.$row['register_status'].'</td>
<td>'if($row['status']=='Active'){print "<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>";}'</td>
<td>'.$row['register_status'].'</td>
What is wrong?
Edit: Sorry. I did not put all code. Here starting my array and I put with quotes your code but can't run
if(mysql_num_rows($result) > 0)
{
$number = 1;
while($row = mysql_fetch_assoc($result))
{
$data .= '<tr>
<td>'.$row['register_status'].'</td>
<td>'
if($row['status']=='Active')
{
echo '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
}
'</td>
</tr>';
$number++;
}
}
else
{
// records now found
$data .= '<tr><td colspan="6">Records not found!</td></tr>';
}
$data .= '</table>';
echo $data;
I have some code for ascending and descending sort, when click on link, table will be sorted asc and after another they will be sort desc. Generally code is working but they don't return first and last field from database. When sort desc don't return last and when asc then don't return first field. I will come piece of code here. Somebody to help ? Thanks.
this is the link for request
echo "<th>ID
<a href='sort_user.php?sortItemsId&order=" . (isset($_GET['order'])?!$_GET['order']: 1) . "'>
<i class='fa fa-sort' aria-hidden='true'></i>
</a>
</th>";
if (isset($_REQUEST["sortItemsId"])) {
$isAsc = isset($_GET['order'])? (bool) !$_GET['order']: 1;
$sql = "SELECT id, name, number, email, recovery_email, address FROM users ORDER BY id " .($isAsc?"ASC":"DESC").";";
$query = mysqli_query($db, $sql);
.....
}
You have nested while loops in your code:
while($row = mysqli_fetch_object($query)) {
//some code
//$row is first object
while($row = mysqli_fetch_object($query)) {
//printing data
//$row is replaced by second object and so on
}
}
I will post now full code with printing data. I got result but don't get last field when sorting desc and don't get first field when sorting asc
if (isset($_REQUEST["sortItemsId"])) {
$isAsc = isset($_GET['order'])? (bool) !$_GET['order']: 1;
$sql = "SELECT id, CRMContact, CRMOrganization, username, recovery_email, status FROM tb_users ORDER BY id " .($isAsc?"ASC":"DESC").";";
$query = mysqli_query($db, $sql);
if (mysqli_num_rows($query) > 0) {
while($row = mysqli_fetch_object($query)) {
echo "<div class='container'><table class='table table-striped'><thead>";
echo " <tr><th>ID
<a href='existing_user.php?sortItemsId&order=" . (isset($_GET['order'])?!$_GET['order']: 1) . "'>
<i class='fa fa-sort' aria-hidden='true'></i>
</a>
</th> <th>CRM Contact</th><th>CRM Organization</th>";
echo "<th>Username</th><th>Recovery email</th><th>Status</th><th>Actions</th></tr></thead>";
$i = 0;
while ($row = mysqli_fetch_object($query)) {
$i++;
$id = $row->id;
echo "<tbody>
<tr>
<td style='background-color:" . (($i % 2 == 0) ? '#fff' : '#f9f9f9') . "'>$row->id</td>
<td style='background-color:" . (($i % 2 == 0) ? '#fff' : '#f9f9f9') . "'>$row->CRMContact</td>
<td style='background-color:" . (($i % 2 == 0) ? '#fff' : '#f9f9f9') . "'>$row->CRMOrganization</td>
<td style='background-color:" . (($i % 2 == 0) ? '#fff' : '#f9f9f9') . "'><a href='edit_user.php?idEdit=$row->id'>$row->username</a></td>
<td style='background-color:" . (($i % 2 == 0) ? '#fff' : '#f9f9f9') . "'>$row->recovery_email</td>
<td style='background-color:" . (($i % 2 == 0) ? '#fff' : '#f9f9f9') . "'>$row->status</td>
<td style='background-color:" . (($i % 2 == 0) ? '#fff' : '#f9f9f9') . "'>
<div class='btn-group'>
<button type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false' style='background-color: #4076BC; color: #fff;'>
<i class='fa fa-fire' aria-hidden='true'></i>
Action <span class='caret'></span>
</button>
<ul class='dropdown-menu'>
<li><a href='view_user.php?viewId=$row->id'>View</a></li>
<li><a href=''>Edit</a></li>
<li><a href='existing_user.php?deleteUser=$row->id'>Delete</a></li>";
?>
<?php
if ($row->deactivated == 1) {
echo "<li><a href='existing_user.php?deactivateUserAcc=activate&id=$id'>Activate</a></li>";
} else {
echo "<li><a href='existing_user.php?deactivateUserAcc=deactivate&id=$id'>Deactivate</a></li>";
}
"</ul>
</div>
</td>
</tr>
</tbody>";
}
echo "</table></div>";
}
} else if (mysqli_num_rows($query) == 0) {
echo "<script type='text/javascript'>alert('Database is empty.');</script>";
} else {
echo "<script type='text/javascript'>alert('Something went wrong.');</script>";
}
}
I'm trying to show booking using tables, which have dynamic rows and also rowspan.
Here is my code:
<table border="1" style='width: 100%' >
<tr>
<th style='background-color:green;width: 80px' ><font color="white">Time</font></th>
<?php
$i=1;
while($i<=$no_court)
{
echo "<th style='background-color:green;width: 80px'> <font color='white'>Court".$i."</font></th>";
$i+=1;
}
?>
</tr>
<tr>
<td>8:00 AM</td>
<?php
$i=1;
while($i<=$no_court)
{
$flag=0;
$j=0;
while(sizeof($start) > $j )
{
$start_time=$start[$j];
$finish_time=$finish[$j];
$court=$court1[$j];
$sst = strtotime($start_time);
$eet= strtotime($finish_time);
$diff= $eet-$sst;
$timeElapsed= gmdate("h:i",$diff);
$timeElapsed+=1;
if ($start_time=='08:00:00' && $court==$i)
{
$fio_time=$finish[$j];
if($fio_time=='13:00:00')
{
$f_time='1:00:00';
}
$f=$facility_id[$j];
$sql15 = $dbConnection->prepare('SELECT * FROM tbl_facility WHERE facility_id=?');
$sql15->execute(array($f));
$row15 = $sql15->fetch();
$facility_name=$row15['facility_name'];
if($block_by[$j]=="1")
{
echo "<td style='background-color:blue;' rowspan='$timeElapsed'>
<font size='2' color='white'><b><center>$league[$j]</b></br>
Reserved </br>
$facility_name</br>
$start_time-$f_time</br>
<a href='' onClick='javascript: openPopup($id[$j])' style='color:white;'>Edit</a>
<a href='delete.php?id=$id[$j]' style='color:white;' onclick='return confirmdelete()' >Delete</a>
</center></font></td>";
break;
}
elseif($block_by[$j]=="2")
{
$p=$player_id[$j];
$sql17 = $dbConnection->prepare('SELECT * FROM tbl_player_registration WHERE player_id=?');
$sql17->execute(array($p));
$row17 = $sql17->fetch();
$first_name=$row17['first_name'];
echo "<td style='background-color:gray;' rowspan='$timeElapsed'>
<font size='2' color='white'><b><center>Reserved By</b></br>
$first_name </br>
</center></font></td>";
break;
}
}
elseif($start_time <='08:00:00' && $finish_time >='08:00:00' && $court==$i )
{
break;
}
elseif($court==$i )
{
$l=0;
while(sizeof($court) > $l)
{
$ta=$start[$l];
$fa=$finish[$l];
$ca=$court1[$l];
if($ta >='08:00:00' && $fa <='08:00:00' && $ca==$i )
{
$flag=1;$court=$ca;
}
$l+=1;
}
}
$j+=1;
}
if($flag==1 )
{
echo "<td></td>";
}
if($flag==0 )
{
}
if($court != $i)
{
echo "<td></td>";
}
$i+=1;
}
?>
</tr>
</table>
Its showing output as this image:
Its showing data properly but adding an extra column, which make the table look disturbing.
I want to show the result as this image:
I'm little confused where I'm messing the code. Kindly help to sort this issue.
I have the following: The result I am getting is the image attached. I would like the username to be listed only once and then the win, loose across the page. not a row for each result.
$sql_events = mysql_query("SELECT * FROM weekpicks ORDER BY 'username' asc ")
or die (mysql_error());
while ($row = mysql_fetch_array($sql_events)) {
$username = $row["username"];
$week = $row["win_loose"] ;
$row_color = ($row_count++ % 2 == 0 ? $color1 : $color2);
echo '<tr style="background-color: '.$row_color.';">';
echo '<td style="width: 100" align="center"><font size="2">'.$username.'</td>';
echo '<td style="width: 50" align="center"><font size="2">'.$week.'</td>';
echo '<td style="width: 50" align="center"><font size="2">'.$week.'</td>';
echo '<td style="width: 50" align="center"><font size="2">'.$week.'</td>';
echo '<td style="width: 50" align="center"><font size="2">'.$week.'</td>';
you have to update your code. You are querying correctly but taking the data in a wrong way. You have to try associative array to solve your problem. Please try following codes-
$sql_events = mysql_query("SELECT * FROM weekpicks ORDER BY 'username' asc ") or die (mysql_error());
while ($row = mysql_fetch_array($sql_events)) {
$username[$row["username"]][] = $row["win_loose"];
}
foreach($username as $key=>$val){
echo '<td style="width: 100" align="center"><font size="2">'.$username.'</td>';
foreach($val as $value){
echo '<td style="width: 50" align="center"><font size="2">'.$value.'</td>';
}
}
One more thing to mention, it is not a good practice to use inline css on every table column. You could use a class and get the css to the css file attached to that class.
Hope it helps...:)
You're pre-echoing weeks for which you don't have data yet. The idea is, print a cell for each week as long as it's referring to the same user:
$sql_events = mysql_query("SELECT * FROM weekpicks ORDER BY username asc ")
or die(mysql_error());
$current_username = null;
while ($row = mysql_fetch_array($sql_events)) {
$username = $row["username"];
//User changed
if ($current_username == null || $current_username != $username) {
if ($current_username != null) {
echo '</tr>'; //Had another user before so end the row
}
$row_color = ($row_count++ % 2 == 0 ? $color1 : $color2);
echo '<tr style="background-color: ' . $row_color . ';">';
echo '<td style="width: 100" align="center"><font size="2">' . $username . '</td>';
$current_username = $username;
}
$week = $row["win_loose"];
echo '<td style="width: 50" align="center"><font size="2">' . $week . '</td>';
}
echo '</tr>';
Hello i have these code.
<div class="col-md-6"> <br><br>
<table class="table">
<thead>
<th> Subject </th>
<th> Schedule </th>
<th> Day </th>
<th> Slots </th>
<th> Sections </th>
<th> Action </th>
</thead>
<tbody>
<?php
foreach($Subjects as $row)
{
$course = $this->session->userdata('course');
if($course == 'BSITWMA' || $course == 'BSCSSE' || $course == 'BSITDA' || $course == 'BSITGDD')
{
if($row->ite == '1' ) {
echo '<tr>';
echo '<td id="subj_code" name="subj_code">' .$row->subject_code. '</td>';
echo '<td id="sched_time" name="sched_time">' .$row->schedule_timestart. ' - ' .$row->schedule_timeend.' </td>';
echo '<td id="day" name="day">' .$row->schedule_day. '</td>';
echo '<td id="slot" name="slot">' .$row->slots. '</td>';
echo '<td id="sect_code" name="sect_code">' .$row->section_code. '</td>';
echo '<td > <button id = "btn-add" class="btn" > Reserve </button > </td>';
echo '</tr>';
}
}
else {
if($row->coe == '1' ) {
echo '<tr>';
echo '<td id="subj_code" name="subj_code">' .$row->subject_code. '</td>';
echo '<td id="sched_time" name="sched_time">' .$row->schedule_timestart. ' - ' .$row->schedule_timeend.' </td>';
echo '<td id="day" name="day">' .$row->schedule_day. '</td>';
echo '<td id="slot" name="slot">' .$row->slots. '</td>';
echo '<td id="sect_code" name="sect_code">' .$row->section_code. '</td>';
echo '<td > <button id = "btn-add" class="btn" > Reserve </button > </td>';
echo '</tr>';
}
}
}
?>
</tbody>
</table>
</div>
I have updated my code and this is what it looks like now.
what i want is to when i press the button. i will retrieve all the values and use it to insert into the database.
i dont have any code yet for the retrieving of value part.
i have the jquery part like this, and i still dont have any idea how to get the values in each TD.
$('button').on('click',function() {
var rowCount = $('#mhTable >tbody >tr').length;
});
You could get the ancestor <td> element of the button and get the values by accessing the text element of the sibling <td> elements using the jQuery .each() function.
The code should look something like this:
$(document).ready(function() {
$("#btn-add").on('click', function() {
var values = [];
$(this).parent('td').siblings().each(function() {
values.push($(this).text());
});
console.log(values);
});
});
Here I pass the values to an array for simplicity but you can pass these values using ajax or whatever other method you use to send values to the database.
Here is a fiddle with this example in practise
Why not do something like this for each of your variables within your foreach?
$subject_code = $row->subject_code;
and then you can use that variable for whatever you choose (such as your query)