everything works perfect bar the div 'hidden-table' not showing, if i remove the 'style:display:none' then it shows the table with correct data so i know its working and i have tried the taking the popup out of the echo and displaying it separately just to see if it shows which it does.
seems the problem occurs only when its in the echo and seems centred around the 'onmousover'
full page code:
<html>
<table border='0' cellpadding='0' cellspacing='0' class="center2">
<tr>
<td width='60'><img src="images/box_tl.png"></td>
<td style="background: url(images/box_tm.png)" align="center"><img src="images/news.png"></td>
<td width='25'><img src="images/box_tr.png"></td>
</tr>
<tr>
<td style="background: url(images/box_ml.png)"><h2>.</h2></td>
<td style="background: url(images/box_mm.png)">
<?php
include 'connect.php';
$query = mysql_query("SELECT * FROM tbl_img") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Mob Name</th> <th>Id</th> <th>Health</th> <th>Body</th> <th>Effects</th> <th>Spawn</th></tr></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query )) {
$mob_id = $row['mob_id'];
$mob = $row['mob'];
$body = $row['body'];
$mob_name = $row['mob_name'];
$health = $row['health'];
$level = $row['level'];
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<img src='/testarea/include/mobs/$mob' />";
echo "</td><td>";
echo $mob_name;
echo "</td><td>";
echo $level;
echo "</td><td>";
echo $health;
echo "</td><td>";
echo
"
<a onmouseover='popup($('#hidden-table').html(), 400);' href=''><img src='/testarea/include/mobs/dead/$body' /></a>
";
echo "
<div id='hidden-table' style='display:none;'>
<table border='0' cellpadding='0' cellspacing='0' class='center3'>
<tr>
<td width='14'><img src='images/info_tl.png'></td>
<td style='background: url(images/info_tm.png)' align='center'></td>
<td width='14'><img src='images/info_tr.png'></td>
</tr>
<tr>
<td style='background: url(images/info_ml.png)'><h2>.</h2></td>
<td style='background: url(images/info_mm.png)'>
";
$query2 = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());
echo "<table border='0' cellpadding='1' cellspacing='1' width='250' id='2' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Item Name</th> <th>Qty</th></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query2 )) {
$id = $row['id'];
$item_img = $row['item_img'];
$qty = $row['qty'];
$item_name = $row['item_name'];
// Print out the contents of each row into a table
echo "<tr><td width='50'>";
echo "<img src='/testarea/item/$item_img' />";
echo "</td><td width='150'>";
echo $item_name;
echo "</td><td width='50'>";
echo $qty;
echo "</td></tr>";
}
echo "</tbody></table>";
echo "
</td>
<td style='background: url(images/info_mr.png)'><h2>.</h2></td>
</tr>
<tr>
<td width='14'><img src='images/info_bl.png'></td>
<td style='background: url(images/info_bm.png)' align='center'><h2>.</h2></td>
<td width='14'><img src='images/info_br.png'></td>
</tr>
</table>
</div>"
;
echo "</td><td>";
echo "test";
echo "</td><td>";
echo "test";
echo "</td></tr>";
}
echo "</tbody></table>";
?>
</td>
<td style="background: url(images/box_mr.png)"><h2>.</h2></td>
</tr>
<tr>
<td width='60'><img src="images/box_bl.png"></td>
<td style="background: url(images/box_bm.png)" align="center"><h2>.</h2></td>
<td width='25'><img src="images/box_br.png"></td>
</tr>
</table>
</html>
You're inadvertently ending your onmouseover event when you try to reference your jQuery selector. The use of single quotes for different reasons is the reason. Try this instead:
function ShowPop()
{
popup($('#hidden-table').html(), 400);
}
<a onmouseover='ShowPop()' href=''><img ..... /></a>
Related
I need help with a simple task, but I am stuck...
I have a database where I pull different data and I am visualizing those data on a web page.
Here is my query for getting the data:
$result = mysqli_query($mysqli, "SELECT *, DATEDIFF(nextcalibration, CURDATE()) AS days FROM tools AS dp ");
Here is my table:
<table id="table_id" class="table table-striped">
<tr>
<th>Nr</th> <th>Status</th> <th>name</th> <th>Serial</th> <th>Used At</th> <th>Owner</th> <th>Calibrated</th> <th>nextcalibration</th> <th>vendor</th> <th>days</th> <th>actions</th>
</tr>
<?php
while($user_data = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$user_data['toolnr']."</td>";
echo "<td>".$user_data['status']."</td>";
echo "<td>".$user_data['toolname']."</td>";
echo "<td>".$user_data['serial']."</td>";
echo "<td>".$user_data['usedat']."</td>";
echo "<td>".$user_data['owner']."</td>";
echo "<td>".$user_data['calibrated']."</td>";
echo "<td>".$user_data['nextcalibration']."</td>";
echo "<td>".$user_data['vendors']."</td>";
echo "<td>".$user_data['days']. "</td>";
echo "<td><a href='edit.php?id=$user_data[id]'><img src='img/edit.png' ></a> | <a href='delete.php?id=$user_data[id]' onclick='return checkDelete()'><img src='img/delete.png'></a></td></tr>";
}
?>
</table>
I would like to make conditional formatting only for the last column - "days".
The idea is if the value of "days" <= 30 to become red color text.
I tried with various JS, but honestly, it did not work.
<table id="table_id" class="table table-striped">
<tr>
<th>Nr</th> <th>Status</th> <th>name</th> <th>Serial</th> <th>Used At</th> <th>Owner</th> <th>Calibrated</th> <th>nextcalibration</th> <th>vendor</th> <th>days</th> <th>actions</th>
</tr>
<?php
while($user_data = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$user_data['toolnr']."</td>";
echo "<td>".$user_data['status']."</td>";
echo "<td>".$user_data['toolname']."</td>";
echo "<td>".$user_data['serial']."</td>";
echo "<td>".$user_data['usedat']."</td>";
echo "<td>".$user_data['owner']."</td>";
echo "<td>".$user_data['calibrated']."</td>";
echo "<td>".$user_data['nextcalibration']."</td>";
echo "<td>".$user_data['vendors']."</td>";
echo "<td>";
$days=$user_data['days'];
if($days <= 30){
echo "<span style='color:red;'>$days</span>";
}else{
echo $days;
}
echo "</td>";
echo "<td><a href='edit.php?id=$user_data[id]'><img src='img/edit.png' ></a> | <a href='delete.php?id=$user_data[id]' onclick='return checkDelete()'><img src='img/delete.png'></a></td></tr>";
}
?>
</table>
Would something simple like this - without JS- work?
<table id="table_id" class="table table-striped">
<tr>
<th>Nr</th> <th>Status</th> <th>name</th> <th>Serial</th> <th>Used At</th> <th>Owner</th> <th>Calibrated</th> <th>nextcalibration</th> <th>vendor</th> <th>days</th> <th>actions</th>
</tr>
<?php
while($user_data = mysqli_fetch_array($result))
{
$style_days=($user_data['days']<=30)?'style="color:red"':'';
echo "<tr>";
echo "<td>".$user_data['toolnr']."</td>";
echo "<td>".$user_data['status']."</td>";
echo "<td>".$user_data['toolname']."</td>";
echo "<td>".$user_data['serial']."</td>";
echo "<td>".$user_data['usedat']."</td>";
echo "<td>".$user_data['owner']."</td>";
echo "<td>".$user_data['calibrated']."</td>";
echo "<td>".$user_data['nextcalibration']."</td>";
echo "<td>".$user_data['vendors']."</td>";
echo "<td ".$style_days.">".$user_data['days']. "</td>";
echo "<td><a href='edit.php?id=$user_data[id]'><img src='img/edit.png' ></a> | <a href='delete.php?id=$user_data[id]' onclick='return checkDelete()'><img src='img/delete.png'></a></td></tr>";
}
?>
</table>
Of course, apply the necessary guarding for $user_data['days'] (existence, numeric..) :)
I am having trouble with a part of my code. I want the checkbox in the last column to be checked if the corresponding DB value is 1, but something keeps going wrong with my code, anyone who sees what's wrong? It's probably very simple but I can't find it.
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
$betaald = $record['betaald'];
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald' id='betaald' value='1' ". echo ($betaald==1 ? 'checked' : ''); . " ></td>";
echo "</tr>";
}
mysql_close($con);
?>
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData = mysql_query($sql, $con);
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php while ($record = mysql_fetch_array($myData)) { ?>
<tr>
<td><?php echo $record['naam'] ?></td>
<td>
<input type='checkbox' name='betaald' id='betaald' value='1'
<?php if($record['betaald'] == 1){ ?>
checked="checked"
<?php } ?>
/>
</td>
</tr>
<?php } ?>
</table>
Try this
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData= mysql_query($sql) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald</b></th>
</tr>
<?php
while($record = mysql_fetch_array($myData))
{
?>
<tr>
<td> <?php echo $record['naam'] ?></td>
<td> <input type='checkbox' name='betaald' id='betaald' value='1' <?php echo ($record['betaald']==1 ? 'checked' : '')?>> </td>
</tr>
<?php
}
mysql_close($con);
?>
mysql_query($sql) no need to define $con
Note: This extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
while($record = mysql_fetch_array($myData)) {
$betaald = $record['betaald'];
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald' id='betaald' value='1' ";
echo $betaald==1 ? 'checked' : '';
echo " ></td>";
echo "</tr>";
}
mysql_close($con);
?>
You have assigned $betaald value outside the while loop so there is no value in $betaald.
I have included $betaald inside while loop.
You need several changes in your php and html code. First of all I've some confusion about your code. Let me clear those.
Point 1 [name='betaald']: If you have a name like this you will not get multiple selected value.
Point 2 [id='betaald']: ID must be unique in a page.
Point 3 [value='1']: How will you differ values if all have same value?
so your code should be something like this:
<?php
$sql = "SELECT * FROM registered ORDER BY datum";
$myData=mysql_query($sql,$con) ;
?>
<table width="1100" border="1">
<tr>
<th style="text-align:center; padding:0 10px">naam</th>
<th style="text-align:center; padding:0 10px">betaald?</b></th>
</tr>
<?php
$betaald = $_POST['betaald'];
$i = 1;
while($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['naam'] . "</td>";
echo "<td> <input type='checkbox' name='betaald[]' id='betaald".$i."' value='".$record['betaald']."' ";
if ($record['betaald'] == $betaald)
{
echo "checked";
}
echo " ></td>";
echo "</tr>";
$i++;
}
mysql_close($con);
?>
I have a PHP based website for jobs. I echo all the jobs from database in a table below. When i click on a job in table row it shows the job details in an iframe beside the table.
This is the code of the table and iframe index.php
<table class="table1">
<tr>
<td colspan="3">
<?php
include "job.header.php";
?>
</td>
</tr>
<tr>
<td width="30%">
<div>
<?php
require "module/job.call.php";
?>
</div>
</td>
<td width="60%">
<iframe name="content" src="../module/job.unclicked.php">
</iframe>
</td>
<td width="20%"> </td>
</tr>
</table>
This is the code that i call jobs from the database job.call.php
<?php
$result = mysqli_query($conn,"SELECT * FROM job where approved='1' ORDER BY `CreatedTime` DESC");
echo "<table id='maintable' class='table-fill' border='0' cellpadding='0' cellspacing='0'>
<tr>
<th position='fixed' overflow='hidden' width='10%'>Job Title</th>
<th position='fixed' width='5%'>Company Name</th>
<th width='5%'>Closing Date</th>
</tr>";
while($row = mysqli_fetch_array($result) ) {
if (strlen($row['positiontitle']) > 20)
$row['positiontitle'] = substr($row['positiontitle'], 0, 60) . "...";
echo "<tr ref='job.details.php?id=".$row['id']."' target='content' class='positiontitle-link'>";
echo "<td><font style='text-shadow: none;'>" . $row['positiontitle'] . "</font></a></td>";
echo "<td>" . $row['companyname'] . "</td>";
echo "<td>" . $row['closingdate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
I want that when i click on the job in the table row then the address bar should take the id of the job. because if someone wants to share the job then they should just send that address for specific job.
Now it show like this
I want that it should look like this
I have a table in my DB which I call to show everything in that table on a page one of the items in the table is an image which when moused over needs to show a popup showing data from a separate table which corresponds to that item. I have a JQuery which calls the data depending on the row from the 1st table but when I try to actually put the two together I get the first table showing fine but now I get no pop up on mouseover.
This page is currently included in the index.php page which has the scripts to call the .js / .css files.
Here's the code for what I am trying to do:
<html>
<table border='0' cellpadding='0' cellspacing='0' class="center2">
<tr>
<td width='60'><img src="images/box_tl.png"></td>
<td style="background: url(images/box_tm.png)" align="center"><img src="images/news.png"></td>
<td width='25'><img src="images/box_tr.png"></td>
</tr>
<tr>
<td style="background: url(images/box_ml.png)"><h2>.</h2></td>
<td style="background: url(images/box_mm.png)">
<?php
include 'connect.php';
$query = mysql_query("SELECT * FROM tbl_img") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Mob Name</th> <th>Id</th> <th>Health</th> <th>Body</th> <th>Effects</th> <th>Spawn</th></tr></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query )) {
$mob_id = $row['mob_id'];
$mob = $row['mob'];
$body = $row['body'];
$mob_name = $row['mob_name'];
$health = $row['health'];
$level = $row['level'];
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<img src='/testarea/include/mobs/$mob' />";
echo "</td><td>";
echo $mob_name;
echo "</td><td>";
echo $level;
echo "</td><td>";
echo $health;
echo "</td><td>";
echo
"
<a onmouseover='popup($('#hidden-table').html(), 400);' href='somewhere.html'><img src='/testarea/include/mobs/dead/$body' /></a>
";
echo "
<div id='hidden-table' style='display:none;'>
<table border='0' cellpadding='0' cellspacing='0' class='center3'>
<tr>
<td width='14'><img src='images/info_tl.png'></td>
<td style='background: url(images/info_tm.png)' align='center'></td>
<td width='14'><img src='images/info_tr.png'></td>
</tr>
<tr>
<td style='background: url(images/info_ml.png)'><h2>.</h2></td>
<td style='background: url(images/info_mm.png)'>
";
$query2 = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());;
echo "<table border='0' cellpadding='1' cellspacing='1' width='250' id='2' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Item Name</th> <th>Qty</th></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query2 )) {
$id = $row['id'];
$item_img = $row['item_img'];
$qty = $row['qty'];
$item_name = $row['item_name'];
// Print out the contents of each row into a table
echo "<tr><td width='50'>";
echo "<img src='/testarea/item/$item_img' />";
echo "</td><td width='150'>";
echo $item_name;
echo "</td><td width='50'>";
echo $qty;
echo "</td></tr>";
}
echo "</tbody></table>";
echo "
</td>
<td style='background: url(images/info_mr.png)'><h2>.</h2></td>
</tr>
<tr>
<td width='14'><img src='images/info_bl.png'></td>
<td style='background: url(images/info_bm.png)' align='center'><h2>.</h2></td>
<td width='14'><img src='images/info_br.png'></td>
</tr>
</table>
</div>"
;
echo "</td><td>";
echo "test";
echo "</td><td>";
echo "test";
echo "</td></tr>";
}
echo "</tbody></table>";
?>
</td>
<td style="background: url(images/box_mr.png)"><h2>.</h2></td>
</tr>
<tr>
<td width='60'><img src="images/box_bl.png"></td>
<td style="background: url(images/box_bm.png)" align="center"><h2>.</h2></td>
<td width='25'><img src="images/box_br.png"></td>
</tr>
</table>
</html>
you have two semi-colons on this line...could be the problem
$query = mysql_query("SELECT * FROM tbl_drop WHERE mob_name='$mob_name'") or die(mysql_error());;
I'm trying to echo data from an SQLdatabase into a table that is somewhat decent-looking. I can already echo the data properly into 5 separate basic tables, but when I can't figure out how to style it without it completely messing up. Here is the code I already have:
// OUTPUTS RESULTS //
$resultfirst = mysql_query("SELECT * FROM Students WHERE FirstPeriod='$_POST[firstperiod]'");
$resultsecond = mysql_query("SELECT * FROM Students WHERE SecondPeriod='$_POST[secondperiod]'");
$resultthird = mysql_query("SELECT * FROM Students WHERE ThirdPeriod='$_POST[thirdperiod]'");
$resultfourth = mysql_query("SELECT * FROM Students WHERE FourthPeriod='$_POST[fourthperiod]'");
$resultfifth = mysql_query("SELECT * FROM Students WHERE FifthPeriod='$_POST[fifthperiod]'");
// 1st PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>First Period</th>
</tr>";
while($row = mysql_fetch_array($resultfirst))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 2nd PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Second Period</th>
</tr>";
while($row = mysql_fetch_array($resultsecond))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 3rd PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Third Period</th>
</tr>";
while($row = mysql_fetch_array($resultthird))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 4th PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Fourth Period</th>
</tr>";
while($row = mysql_fetch_array($resultfourth))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 5th PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Fifth Period</th>
</tr>";
while($row = mysql_fetch_array($resultfifth))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
If the code above is unclear- my goal is to compare the first period teachers in which are stored in the database, and output the students names that share the same period/teacher.
This code works fine. But the tables look very bland. I would like to echo the data into a table such as this.
<table width="368" border="0" cellspacing="0" cellpadding="2" align="center" height="100">
<tr valign="middle">
<td bgcolor="#000066" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Services</font></b></font> </div>
</td>
<td width="4" height="20"></td>
<td bgcolor="#990000" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Products</font></b></font></div>
</td>
<td width="4" height="20"></td>
<td bgcolor="#C89800" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Resources</font></b></font> </div>
</td>
</tr>
<tr valign="top">
<td bgcolor="#000066" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Professional
and cost effective web design, development and promotion services
</font></p>
</td>
</tr>
</table>
</td>
<td width="4"></td>
<td bgcolor="#990000" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Interactive
Web Products - Flash Survey, poll, Guest book, Instant Quote
</font></p>
</td>
</tr>
</table>
</td>
<td width="4"></td>
<td bgcolor="#C89800" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Free
web resources - articles, tutorials, tips and tricks.
</font></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
If anyone can offer any suggestions of any sort- I would greatly appreciate it.
I see a few areas that can be improved:
As others have said, don't use tables to manage layout. However, tables are perfectly acceptable for displaying tabular data
You really want to use CSS to style your page, it's a lot easier to control your style and makes the markup easier to read. See this w3schools' artcile on CSS Tables
You can combine your multiple queries into one for better performance (though, that seems to be outside the scope of your question)
Here is an example markup and CSS for your table: http://jsfiddle.net/vxzJV/