Hide DIV or button based on query result - php

I am trying to hide a DIV or the pertaining button based on a value stored in the session (which gathers user data on login). For example, if someone logs in with the access code of 20, I want certain buttons to be disabled, hidden, etc. This is an internal portal with beginner users using it, so I'm thinking simple. Any other ideas are more than welcome. How can I do this?
Here is my current code. I've removed the style attributes for the post. Thanks all.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>MK Diamond - Main Menu</title>
<style type="text/css">
</style>
</head>
<?php
include("session.php");
echo "<body style=\"background-attachment: fixed; background-image: url('img/background.jpg');\">";
echo "<div class=\"auto-style1\" style=\"height: 213px; width: 100%; float: left;\">";
echo "<span class=\"auto-style5\">";
echo "<span class=\"auto-style22\"><strong>This portal is for MK Diamond use ";
echo "only. Any and all access is monitored and controlled - unauthorized ";
echo "attempts will be investigated.</strong></span><br>";
echo "<img src=\"img/mk-logo.png\" height=\"185\" width=\"375\"/></span><br>";
echo "</div>";
echo "<div>";
echo "<table style=\"width: 65%\" align=\"center\" class=\"auto-style7\">";
echo "<tr>";
echo "<td class=\"auto-style21\" style=\"height: 24px\"></td>";
echo "<td class=\"auto-style21\" style=\"height: 24px; width: 25px;\"> </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style18\" style=\"height: 24px\">";
echo "<input name=\"jobsbutton\" type=\"button\" value=\"M.S. Jobs Menu\" onclick=\"location.href='jobsmenu.php'\" style=\"width:160px; height: 35px\" /></td>";
echo "<td class=\"auto-style18\" style=\"height: 24px; width: 25px;\"> </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "<input name=\"ordersbutton\" ID=\"ordersbutton\" type=\"button\" value=\"B.V. Orders Menu\" onclick=\"location.href='ordersmenu.php'\" style=\"width: 160px; height: 35px\" />";
echo "</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo " </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo " </td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo " </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "You are logged in as "; echo "$row[name]";
echo "</span> Logout</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style23\" style=\"height: 24px\">";
echo "Security Class: "; echo "$row[acctype]";
echo "</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "<strong>Welcome to the Main Menu</strong></td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo " </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "<input name=\"Button1\" type=\"button\" value=\"Release Notes\" onclick=\"location.href='releasenotes.php'\" style=\"width: 160px; height: 35px\" />";
echo "</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo " </td></tr>";
echo "</table>";
?>
</div>
<div class="auto-style8">
</div>
</body>
</html>

Related

Creating a Responsive Table With Data from phpmysql

The below table prints data form a mysql db. Is it possible to make it responsive to adapt to even the smallest devices without losing the image. I am studying bootstrap to see how it can work.
<style>
body { margin: 0; font-family: Arial, Helvetica, sans-serif; }
.content { margin: auto; width: 99.8%; height:79.8%; border: 1px solid green; padding: 10px; background-color: magenta; }
</style>
<div class="content">
<div class="row">
<div class="col">
<?php
print "<table border=1 width=100%>";
print "<td width=10px height=auto bgcolor=#00FF33>" . $row['id'] . "</td>";
print "<td width=200px height=200px>"."<a href='".$row['image']."'><img src=".$row['image']."width=100% height=100%</a>" ."</td>";
print "<td>";
print "<table border=1 width=100%>";
print "<tr>";
print "<td>" . $row['imagename'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>" . $row['name'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>" . $row['username'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>" . $row['useremail'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>" . $row['userphone'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>"."<a href='id=$uniqueid' >More Details</a>"."</td>";
print "</tr>";
print "<tr>";
print "<td>"."<a href='id=$uniqueid' >Contact Seller</a>"."</td>";
print "</tr>";
print "</table>";
print "</td>";
print "</table>";
print "<br />";
?>
</div>
Incase you're using bootstrap just add "table table-responsive" to your table class
<table class="table table-responsive">

Display database row inside html using php

Im trying to display the database rows in html using php.
here is my php code thats working:
while($traveller=mysqli_fetch_assoc($records)){
echo "<tbody>";
echo "<tr>";
echo "<td border = 3px solid #555555 padding = 5px 10px >". $traveller['ticket_no'] ." </td>";
echo "<td>". $traveller['fname'] ." </td>";
echo "<td>". $traveller['lname'] ." </td>";
echo "<td>". $traveller['flight_name'] ." </td>";
echo "<td>". $traveller['d_name'] ." </td>";
echo "<td>". $traveller['plane_name'] ." </td>";
echo "<td>". $traveller['boarding_time'] ." </td>";
echo "<td>". $traveller['depart_time'] ." </td>";
echo "</tbody>";
echo "</tr>";
}
But its black and white.
im trying to add some style to it so im trying to link it between my html table but its not working and im not sure what the problem is. here is the code:
<td> <?php echo "$traveller['ticket_no']"; ?></td>
is there a way to solve this or add styles to the table.
any help is acceptable and appreaciated.
you can use style tag inside
example:
<td class='myclass'>
<style>
td.myclass
{
text-align:center;
}
try something like this because you missed style attribute.
<?php
while($traveller=mysqli_fetch_assoc($records)){ ?>
<tr>
<td style="background-color: red;"><?php echo $traveller['ticket_no']; ?></td>
<td><?php echo$traveller['fname'];?></td>
<td><?php echo $traveller['lname'];?> </td>
<td><?php echo $traveller['flight_name']; ?></td>
<td><?php echo $traveller['d_name']; ?></td>
<td><?php echo $traveller['plane_name'];?> </td>
<td><?php echo $traveller['boarding_time']; ?></td>
<td><?php echo $traveller['depart_time'];?></td>
</tr>
<?php } ?>
Try to give style to table,tr,td tags, then only you can add styles to table
like this:-
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
then when you print table it will display with specified styles,
here i'm giving styles to diect table, tr, td tags
if you want you can assign "class" to table,tr or td and give style to classes
as you want to give link in table, code like this:-
<td> <?php echo "$traveller['ticket_no']"; ?></td>
and there are fault's in the way you written the loop, just loop tr only
don't include tbody or anything inside loop,it should be outside the loop like this:-
echo "<tbody>";
while($traveller=mysqli_fetch_assoc($records)){
echo "<tr>";
echo "<td>". $traveller['ticket_no'] ." </td>";
echo "<td>". $traveller['fname'] ." </td>";
echo "<td>". $traveller['lname'] ." </td>";
echo "<td>". $traveller['flight_name'] ." </td>";
echo "<td>". $traveller['d_name'] ." </td>";
echo "<td>". $traveller['plane_name'] ." </td>";
echo "<td>". $traveller['boarding_time'] ." </td>";
echo "<td>". $traveller['depart_time'] ." </td>";
echo "</tr>";
}
echo "</tbody>";
You can try style in php code like this:
echo "<tbody>";
while($traveller=mysqli_fetch_assoc($records)){
echo "<tr style='color:white;background-color:green'>";
echo "<td style='border: 3px solid #555555;padding:5px 10px' >". $traveller['ticket_no'] ." </td>";
echo "<td>". $traveller['fname'] ." </td>";
echo "<td>". $traveller['lname'] ." </td>";
echo "<td>". $traveller['flight_name'] ." </td>";
echo "<td>". $traveller['d_name'] ." </td>";
echo "<td>". $traveller['plane_name'] ." </td>";
echo "<td>". $traveller['boarding_time'] ." </td>";
echo "<td>". $traveller['depart_time'] ." </td>";
echo "</tr>";
}
echo "</tbody>";
Or you can try style in html code :
<?php
while($traveller=mysqli_fetch_assoc($records)){ ?>
<tr>
<td style="border: 3px solid #555555;padding:5px 10px"><?php echo $traveller['ticket_no']; ?></td>
<td><?php echo$traveller['fname'];?></td>
<td><?php echo $traveller['lname'];?> </td>
<td><?php echo $traveller['flight_name']; ?></td>
<td><?php echo $traveller['d_name']; ?></td>
<td><?php echo $traveller['plane_name'];?> </td>
<td><?php echo $traveller['boarding_time']; ?></td>
<td><?php echo $traveller['depart_time'];?></td>
</tr>

Echo different table columns in every other row in table

Hi I'm creating a questionnaire. The questions and their answers are stored in a table like so:
Now, I want to display the questions and their answers in a table where I get the questions and their possible answers on different rows. Like so:
In my php file, I echo the table and the rows but I cannot figure out how to put the questions and answer in different rows. here is how it looks like:
and here is my php code:
<?php
session_start();
$status=$_GET["status"];
include 'dbh.inc.php';
?>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
text-align: left;
padding: 8px;
}
#td_box{
text-align: center;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #006689;
color: white;
}
</style>
</head>
<body>
<?php
if ($status=="disp") {
$sql="SELECT * FROM questions";
$result = mysqli_query($conn,$sql);
echo "<table>";
while ($row=mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>"; echo $row["question"]; echo "</td>";
echo "<td>"; echo $row["optionA"];echo $row["optionB"];echo $row["optionC"];
echo $row["optionD"];echo $row["optionE"];echo "</td>";
}
}
echo "</table>";
?>
</body>
</html>
Try:
<?php
if ($status=="disp") {
$sql="SELECT * FROM questions";
$result = mysqli_query($conn,$sql);
echo "<table>";
while ($row=mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>"; echo $row["question"]; echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"; echo $row["optionA"];echo $row["optionB"];echo $row["optionC"];
echo $row["optionD"];echo $row["optionE"];echo "</td>";
echo "</tr>";
}
}
echo "</table>";
?>
What I did:
I added a </tr> after your question echo and opend a new one directly after. Then I closed that <tr> after your last <td> as you forgot to do that.
1st : Put all option radio buttons in another tr .
2nd : Maintain proper name attribute for radio button .name="question[$row['question_id']]"
3rd : And use colspan="4" for question td
while ($row=mysqli_fetch_array($result)) {
echo "<tr >";
echo "<td colspan='4'>"; echo $row["question"]; echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionA']\" >".$row['optionA'];
echo "</td>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionB']\" >".$row['optionB'];
echo "</td>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionC']\" >".$row['optionC'];
echo "</td>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionD']\" >".$row['optionD'];
echo "</td>";
echo "<td>";
echo "<input type=\"radio\" name=\"question[$row['question_id']]\" value=\"$row['optionE']\" >".$row['optionE'];
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan='4'>"; echo $row["question"]; echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"; echo $row["optionA"];echo "</td>";
echo "<td>"; echo $row["optionB"];echo "</td>";
echo "<td>"; echo $row["optionC"];echo "</td>";
echo "<td>"; echo $row["optionD"];echo "</td>";
echo "</tr>";
this way you will have proper answers in tabular format in aligned manner

Limit Character in a table

Thanks to stackoverflow and its great solution, I have found a way to limit the characters in a table but it doesn't work for me. I tried a lot but with no success.
This is my table
<?php
$result = mysqli_query($conn,"SELECT * FROM library ORDER BY `CreatedTime` DESC");
echo "<table class='table-fill' border='0' cellpadding='0' cellspacing='0'>
<tr>
<th position='fixed' overflow='hidden' width='10%'>Book Name</th>
<th width='5%'></th>
</tr>";
while($row = mysqli_fetch_array($result) ) {
echo "<tr>";
echo "<td colspan='2' style='padding-bottom: 0;'><a href='library.details.php?id=". $row['id']."' target='content' class='positiontitle-link'><font style='text-shadow: none; font-weight: 800;'>" . $row['bookname']. "</td>";
echo "</tr>";
echo "<tr style='border-top-width: 0; padding-top: 0;'>";
echo '<td style="max-height: 10px;">' . $str . '</td>';
echo "<td style=' padding-top: 0; padding-left: 15px; width: 40%;'> <font color='gray'>Author :</font> " .($row['authorname'] ). "</td>";
echo "<td width='5%' style=' padding-top: 0;'> <font color='gray'>Year Published </font>" . $row['yearpublished'] . "</td>";
echo "</tr>";
if (strlen($row['bookname']) > 1) $str = substr($row['bookname'], 0, 1) . "...";
}
echo"</table>";
?>
This is how it looks like
Any help will be appreciated.
I'm doing this out of my head so forgive me any format issues and such...
Move the string length check to just under the while.
Overwrite $row['bookname'] instead of creating $str.
Remove the line with:
echo '<td style="max-height: 10px;">' . $str . '</td>';
Result:
while($row = mysqli_fetch_array($result) ) {
if (strlen($row['bookname']) > 9) $row['bookname'] = substr($row['bookname'], 0, 9) . "...";
echo "<tr>";
echo "<td colspan='2' style='padding-bottom: 0;'><a href='library.details.php?id=". $row['id']."' target='content' class='positiontitle-link'><font style='text-shadow: none; font-weight: 800;'>" . $row['bookname']. "</td>";
echo "</tr>";
echo "<tr style='border-top-width: 0; padding-top: 0;'>";
echo "<td style=' padding-top: 0; padding-left: 15px; width: 40%;'> <font color='gray'>Author :</font> " .($row['authorname'] ). "</td>";
echo "<td width='5%' style=' padding-top: 0;'> <font color='gray'>Year Published </font>" . $row['yearpublished'] . "</td>";
echo "</tr>";
}

how to put a tooltip in a looping calendar

how can i put a tooltip in a specific date? Can someone please help me. I really need this
and how can i put a ajax so that my calendar doesn't refresh
This is my code.
<?php
error_reporting(0);
Class CALEVENTS
{
var $host;
var $user;
var $password;
var $database;
var $db=NULL;
function CALEVENTS($host="",$user="",$password="",$database="")
{
$this->setInfo($host,$user,$password,$database);
}
function setInfo($host,$user,$password,$database)
{
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->database=$database;
//$this->db=new DB();
//$this->db->open($this->host,$this->user,$this->password,$this->database);
$this->db=mysql_connect($this->host,$this->user,$this->password);
mysql_select_db($this->database);
}
function drawCalendar()
{
$db_event=$this->db;
if(isset($_GET['time']))
$time=$_GET['time'];
else
$time=time();
$today = getdate($time);
$mday = $today ['mday'];
$mon = $today ['mon'];
$year = $today ['year'];
$time = mktime(0, 0, 0, $mon,1,$year);
$today = getdate($time);
$wday = $today ['wday'];
$year = $today ['year'];
$weekday = $today ['weekday'];
$month = $today ['month'];
$i= -$wday;
$thisPage=$_SERVER['PHP_SELF'];
$time = mktime(0, 0, 0, $mon+1,0,$year);
$lastDay=date('j',$time);
$sql="SELECT DATE_FORMAT(eventDate,'%d') AS day,eventContent,eventTitle,eventID FROM events WHERE eventDate BETWEEN '$year/$mon/01' AND '$year/$mon/31'";
//$db_event->query($sql);
$result=mysql_query($sql,$db_event);
$events=array();
//while($row_event=$db_event->fetchObject())
// $events[intval($row_event->day)].=$row_event->eventContent."<br><br>";
while($row_event=mysql_fetch_object($result))
$events[intval($row_event->day)].=$row_event->eventTitle."<br>" .$row_event->eventContent;
echo "<style>\n";
echo ".event_cls {background-color: #b7c8ef; color:white; font-weight: bold; text-decoration: none; cursor: hand;}\n";
echo " <div id='event' style=' left: 395px; top: 192px; color:black'></div></td> </tr> </table>\n";
echo ".event_cls:hover {background-color:ced9f0;}";
echo ".event_col:hover {background-color:ced9f0;}";
echo ".event_head{background-color: #333b73; color:white; font-weight:bold;FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 12px;}\n";
echo ".event_col{background-color:#e2e6ef; color:#000095; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 11px; height='75' width='75'}\n";
echo ".event_link {TEXT-DECORATION: none; color:#0DB0FF;}\n";
echo "</style>";
echo "<table width='870' border='0' align='center' style='border-style:solid;border-width:1px;position:relative;top:15px;left:15px;' cellspacing='1'>\n";
echo "<tr class='event_col' align='center'> \n";
echo "<td height='75'><b><a href='$thisPage?time=".mktime(0, 0, 0, $mon-1,$mday,$year)."' title='Previous Month' class='event_link'><</a></b></td>\n";
echo "<td colspan='5' class='event_col'> <b>$month $year</b></td>\n";
echo "<td height='75'><b><a href='$thisPage?time=".mktime(0, 0, 0, $mon+1,$mday,$year)."' title='Next Month' class='event_link'>></a></b></td>\n";
echo "</tr>\n";
echo "<tr class='event_col' height='25''>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Sunday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Monday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Tuesday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Wednesday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Thursday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Friday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Saturday</td>\n";
echo "</tr>\n";
echo "<script>\n";
foreach($events as $key => $value)
echo "evnt$key=\"$value\"\n";
echo "function showevent(day)\n";
echo "{";
echo " evnt=eval('evnt'+day);\n";
echo " mydiv=document.getElementById('event');\n";
echo " mydiv.innerHTML=evnt\n";
echo "}";
echo "</script>\n";
for($j=0;$j<6;$j++){
echo "<tr> \n";
for($k=0;$k<7;$k++){
$i++;
$cls="class='event_col'";
if(array_key_exists($i,$events))
$cls="class=event_cls onmouseover='showevent($i)'";
echo "<td height='75' $cls>\n";
echo ($i>0&&$i<=$lastDay)?$i:'';
echo "</td>";
}
echo "</tr>" ; }
echo " <tr > <td colspan=8 >\n";
echo " </td> </tr> </table>\n";
echo"<br/><div id='event' style=' z-index:1000; left: 395px; top: 192px; color:#000;'></div>";
}?>
I really need help.. please help me
You can set "id" to each "td" and then in javascript you can setAttribute "title" to some value.

Categories