Running jquery funtion over php mysql while loop - php

The main aim is to display the row when the master row is clicked, there will be multiple records for one single incident id. how to apply jquery function for this type of output. Helps appreciated.
I tried using jexpand function but its not working.
The main aim is to get output like, when one particular row is clicked the remaining set of row with same id should be expanded and vice-versa.
The table results are fetched from mysql database.
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body { font-family:Arial, Helvetica, Sans-Serif; font-size:0.8em;}
#report { border-collapse:collapse;}
#report h4 { margin:0px; padding:0px;}
#report img { float:right;}
#report ul { margin:10px 0 10px 40px; padding:0px;}
#report th { background:#7CB8E2 url(header_bkg.png) repeat-x scroll center left; color:#fff; padding:7px 15px; text-align:left;}
#childALL { background:#C7DDEE none repeat-x scroll center left; color:#000; padding:7px 15px; }
#report tr.td { background:#fff url(row_bkg.png) repeat-x scroll center left; cursor:pointer; }
#report div.arrow { background:transparent url(arrows.png) no-repeat scroll 0px -16px; width:16px; height:16px; display:block;}
#report div.up { background-position:0px 0px;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#report tr:siblings").show();
$("#report tr:siblings").hide();
$("#report div.arrow").click(function(){
$(this).next("#childALL").toggle();
$(this).find(".arrow").toggleClass("up");
});
//$("#report").jExpand();
});
</script>
</head>
<body>
<center>
<img src="abc.jpg" width="400px" height="100px" />
</center>
<?php
$con= mysqli_connect("172.28.212.145", "root", "root", "xxx");
if(!$con)
{
die('not connected');
}
$con= mysqli_query($con, "Select Incident_id,name,qualification from masterdata;");
?>
<div>
<center>
<table id="report">
<tr>
<th>Incident Id</th>
<th>name</th>
<th>Qualification</th>
<th></th>
</tr>
<?php
$incident = null;
while($row = mysqli_fetch_array($con))
{
if( $row['Incident_id'] != $incident )
{
$incident = $row['Incident_id'];
?>
<tr>
<td>
<?php echo $row['Incident_id']; ?>
</td>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<?php echo $row['JournalUdpdateChanges']; ?>
</td>
<td><div class="arrow"></div></td>
</tr>
<?php } else { ?>
<tr id="childALL">
<td >
<?php echo $row['Incident_id']; ?>
</td>
<td >
<?php echo $row['name']; ?>
</td>
<td >
<?php echo $row['qualification']; ?>
</td>
<td >
<?php echo $row['Priority_im']; ?>
</td>
</tr>
<?php
}
}
?>
</table>
</center>
</div>
</body>
</html>

Bootstrap makes really easy work out of this.
Bootstrap Accordion

Related

pagination in html page

I am showing all my products in rows, but the code which I am using shows the result in columns. I am using the datatable pagination, I don't know how I am using pagination in my web site please help me. enter image description here
<table id="datatables" class="table no-margin">
<thead >
<tr>
<th></th>
</tr>
</thead>
<tbody class="df">
<?php
$pr = mysqli_query($link,"select * from product where company_id = '".$company_id."'");
while($prd = mysqli_fetch_array($pr))
{
$price = mysqli_fetch_array(mysqli_query($link,"select * from
admin_price where p_code = '".$prd['p_code']."'"));
?>
<tr>
<td>
<?php echo("<a href='single.php?
p_code=".$prd['p_code']."'>"); ?>
<div class="part-secz">
<img src="<?php echo("images/".$prd['image']); ?>" alt=""/>
<div class="part-infoz">
<?php
echo("<a class='asd' href='single.php?p_code=".$prd['p_code']."'>");
?>
<h5>
<?php echo($prd['p_code']); ?><span>$ <?php echo($price['price']); ?>
</span>
</h5>
<?php
echo("</a>");?>
<?php echo("<a class='add-cart' href='single.php p_code=".$prd['p_code']."'>"); ?> Quick View<?php
echo("</a>");?>
<?php echo("<a class='qck' href='single.php p_code=".$prd['p_code']."'>"); ?>BUY NOW</a><?php
echo("</a>");?>
</div>
</div>
</td>
<div class="clearfix">
</div>
</tr>
<?php
}
?>
Just get your tag outside of while loop
<tr>
while($prd = mysqli_fetch_array($pr))
{
<td> Your Values </td>
}
</tr>
Basically, your code is a cycle of :
<table id="datatables" class="table no-margin">
<thead><tr><th></th></tr></thead>
<tbody class="df">
<?php
$pr = mysqli_query($link,"select * from product where company_id = '".$company_id."'");
while($prd = mysqli_fetch_array($pr))
{
<tr>
<td>
{{some display logic}}
</td>
<div class="clearfix">
</div>
</tr>
<?php } ?>
If you want your products to be in one line fix it, so new row is not created
<table id="datatables" class="table no-margin">
<thead><tr><th></th></tr></thead>
<tbody class="df">
<tr>
<?php
$pr = mysqli_query($link,"select * from product where company_id = '".$company_id."'");
while($prd = mysqli_fetch_array($pr))
{
<td>
{{some display logic}}
</td>
<div class="clearfix">
</div>
<?php } ?>
</tr>
<html>
<head>
</head>
<style>
#myInput {width: 90px; height: 10px; border-radius: 12px;
};
.button1 {width: 90px;
height: 10px; border-radius: 20px;
}
.button1:hover, .button1:active {
background-color: #008B8B;
color: white;
}
</style>
<style>
.paginationbutton {
font: bold 11px Arial;
text-decoration: none;
background-color: #EEEEEE;
color: #333333;
padding: 4px 6px 4px 6px;
border-top: 1px solid #CCCCCC;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-left: 1px solid #CCCCCC;
border-radius: 12px;
}
a.paginationbutton:hover, a.paginationbutton:active {
background-color: #008B8B;
color: white;
}
</style>
<script>
//document.getElementById('currentPage').value=1;
gotoFirstPage();
function gotoFirstPage(){
paginate(100,1);
}
function gotoPrevPage(){
var currentPg=document.getElementById('currentPage').value;
var prevPage=currentPg-1;
if (prevPage < 1) {
prevPage = 1;
}
paginate(100,prevPage);
}
function gotoNextPage(){
var currentPg=document.getElementById('currentPage').value;
var totalItems=document.getElementById('totalItems').value;
var pageSize=10;
var nextPage=parseInt(currentPg)+1;
var totalPages = Math.ceil(totalItems / pageSize);
alert(nextPage);
alert(totalPages);
if (nextPage > totalPages) {
nextPage = totalPages;
}
var start=1;
var end=10;
paginate(totalItems,nextPage);
}
function gotoLastPage(){
var totalItems=document.getElementById('totalItems').value;
var pageSize=10;
var totalPages = Math.ceil(totalItems / pageSize);
paginate(100,totalPages);
}
function paginate(
totalItems ,
currentPage
) {
// var totalItems=document.getElementById('totalItems').value;
var pageSize=10;
// calculate total pages
var totalPages = Math.ceil(totalItems / pageSize);
// ensure current page isn't out of range
if (currentPage < 1) {
currentPage = 1;
} else if (currentPage > totalPages) {
currentPage = totalPages;
}
var startPage, endPage ;
// calculate start and end item indexes
var startIndex = (currentPage - 1) * pageSize;
var endIndex = Math.min(startIndex + pageSize - 1, totalItems - 1);
alert(""+startIndex+""+endIndex);
document.getElementById('currentPage').value=currentPage;
}
</script>
<div id="buttons" style="text-align:right">
Total Items<input type="text" id='totalItems' value="" size=3 class="paginate_control_prev">
currentPage<input type="text" id='currentPage' value="1" size=3 class="paginate_control_prev">
<span id="pageLabel" >
«« First
«Previous
Next »
Last »»
<input type="text" id='nthPage' size=3 maxlength=3 class="paginate_control_prev">
<input type="button" id="paginate-go-button" class="button1" value="Go" onclick="goToNthPage()"> </div>
<script>
document.getElementById('currentPage').value="2";
</script>
</body></html>

Probably a simple error for you guy, I am new to php

This is my first post here, I feel very welcomed as people told me you guys are nice to help people with problems.
I am making a website for a festival at school, and I somehow got this error today:
mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\projectsite\News.php on line 135
<?php
session_start();
if (isset($_SESSION['test'])){
}else{
$_SESSION["test"]=0;
}?>
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="" href="http://example.com/myicon.png">
<link rel="stylesheet" type="text/css" href="css.css">
</head>
<title>News</title>
</style>
<body bgcolor="#E6E6FA">
<a href="http://localhost/projectsite/index.php" ><img src="images/nl.png"/></a>
<a href="http://localhost/projectsite/homeenglish.php" ><img src="images/uk.png"/></a>
<body background="images/achtergrondje2.jpg" style=>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #ffffff;
background-color: #494b4a;
}
li {
float: left;
}
li a {
display: block;
color: #dadada;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a {
display: block;
<img src="images/bannertje2.jpg"
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #dadada;
}
li a.active {
color: white;
background-color: #e83d3d;
}
</style>
</head>
</head>
<body><font color="white"
</body>
<ul>
<li>Home</li>
<li>Line-up</li>
<li>Inschrijven</li>
<li><a class="active" href="http://localhost/projectsite/news.php">Nieuws</a></li>
<li style="float:right"><a class="active" href="http://localhost/projectsite/contact.php">Over ons</a></li>
<li style="float:right"><a class="active" href="http://localhost/projectsite/logout.php">Logout</a></li>
<li style="float:right"><a class="active" href="http://localhost/projectsite/Loginmain.php">Login</a></li>
<br>
</ul>
<?php if ($_SESSION["test"] == 1)
{
?><li style="float:right" ><a class="active" href="html.php">uitloggen</a></li><?php
?><li style="float:right" ><a href=''><?php echo "Welkom Back ". $_SESSION["username"] . "( ͡° ͜ʖ ͡°)"?></a></li><?php
}else{
}
?>
</ul>
<div class="flex-container">
<form method="POST">
<table>
<tr><td><h2>Nieuwsitem Toevoegen</h2></td></tr>
<tr>
<th>Title:</th>
<td><input type="text" name="txtTitle" /></td>
</tr>
<tr>
<th>Plaats:</th>
<td><input type="text" name="txtPlaats" /></td>
</tr>
<tr>
<th>Description:</th>
<td><input type="text" name="txtDescription" /></td>
</tr>
<tr>
<th></th>
<td><input type="submit" name="btnnews" value="Invoeren" /></td>
</tr>
<tr>
<th></th>
<td><input type="submit" name="btnnwesplaatsen1" value="plaatsen" /></td>
</tr>
</table>
</form>
<?php
require('connect.php');
// If the values are posted, insert them into the database.
if (isset($_POST['btnnews']))
{
$title = $_POST['txtTitle'];
$Description = $_POST['txtDescription'];
$plaatsID = $_POST['txtPlaats'];
$query = "INSERT INTO `nieuwsitems` (txtPlaats, txtTitle, txtDescription) VALUES ($plaatsID, '$title', '$Description')";
$result = mysqli_query($connection);
if($result)
{
$smsg = "Succes";
}else{
$fmsg ="";
}
}
include("connect.php");
if(isset($_POST['btnnwesplaatsen1']))
{
$query = "SELECT * FROM nieuwsitems WHERE PlaatsID= 1";
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
$titel = $row['Title'];
$item = $row['Description'];
echo "$titel".'<br>';
echo "$item".'<br><hr>';
}
?>
</body>
</html>
Here is connect.php
<?php
$connection = mysqli_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysqli_error($connection));
}
$select_db = mysqli_select_db($connection, 'projectfestival');
if (!$select_db){
die("Database Selection Failed" . mysqli_error($connection));
}
replace in your code that line..
$result = mysqli_query($connection,$query);

How to create style of html elements while php codes are embedded in it?

I have this php file where I want to retrieve data from database and show in a tabular format.
<html>
<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="adminPanel.css"/>
</head>
<body>
<div class="header">
<h1>Admin</h1>
</div>
<div class="center">
<?php
include "db_connection.php";
$sql = "SELECT * FROM appointments;";
$result = mysqli_query($db,$sql);
If(mysqli_query($db,$sql) == TRUE){
?>
<table>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
<th>License</th>
<th>Engine</th>
<th>Appointment Date</th>
<th>Preferred Mechanic</th>
<?php
while($row = mysqli_fetch_assoc($result)){
?>
<td><?php echo $row['Name'];?></td></br>
<td><?php echo $row['Address'];?></td>
<td><?php echo $row['Phone'];?></td>
<td><?php echo $row['Car_license_No'];?></td>
<td><?php echo $row['Car_Engine_No'];?></td>
<td><?php echo $row['Date'];?></td>
<td><?php echo $row['Mechanic'];?></td>
<?php
}
?>
</table>
<?php
}
?>
</div>
<div class="footer">
<p id="lastMod">
<script language="Javascript">
document.write("Last modified on " + document.lastModified + " ");
</script>
</p>
</div>
</body>
</html>
But the problem is I can`t change the style of data showing in the table. The .footer, .center, .header these are showing up with the perfect style. But styles of html elements that are written within the php blocks are not working, such as , , .
Here is my style sheet
.header{
background-color: black;
color: DC143C;
height: 150px;
margin-bottom: 0px;
font-family: "Impact"
}
.center{
background-image: url(background.jpg);
height: 400px;
margin-top: 0px;
margin-bottom: 0px;
}
.footer{
background-color: black;
font-family: "Impact";
color: DC143C;
margin-top: 82px;
height: 95px;
}
th, td{
color: white;
}
#lastMod{
margin-top: 0px;
padding: 5px;
}
Searched a lot but havn`t found any relevant answer. Thanks in advance.
You should apply the classes to cells then you could style it.
<td class="name"><?php echo $row['Name'];?></td></br>
...
<td class="mechanic"><?php echo $row['Mechanic'];?></td>
<style>
td.name {
background-color: #0f0;
}
....
td.mechanic {
background-color: #f00;
}
</style>
you didn't added any class in your php you should add class in your table like
<table class="mytable">
and style it by pointing with parent such as
<style>
.mytable th { color:#fff; }
</style>

dompdf page breakes not working

here is sample image
<!DOCTYPE html>
<html class="bg-black">
<head>
<meta charset="UTF-8">
<title><?php if(isset($title)) echo $title.' | '; ?> Sales agent management software (SAMS) </title>
<style>
body{
font-size: 9px;
margin: 20px;
}
th,td,p,div,table,h3{margin:0;padding:0}
#page { margin: 20px; }
.header{
border-bottom: 1px solid #dddddd;
text-align: center;
position: fixed; top: 0;
}
.footer { position: fixed; bottom: 0px; text-align: center }
.pagenum:before { content: counter(page); }
</style>
</head>
<body>
<div class="header">
<h2><?php echo get_option('company_name'); ?> Catalog</h2>
</div>
<br /><br />
<div class="footer">Page: <span class="pagenum"></span>, creation time : <?php echo date('l jS \of F Y h:i:s A') ?>, create by: <?php echo user_full_name(singleDbTableRow(loggedInUserData()['user_id'])); ?></div>
<br />
<div class="box-body">
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: 10px; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 80px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:80px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
<tr>
<th><FONT SIZE=12>LKR</FONT></th>
<td><FONT SIZE=14><?php $lkr = get_selling_price($product);
echo number_format(round($lkr, get_option('round_precision')) ); ?></FONT>
</td>
</tr>
<tr>
<th> <FONT SIZE=12>US $</FONT></th>
<td><FONT SIZE=14><?php echo number_format(round(lkr_to_usd($lkr), get_option('round_precision')) ); ?></FONT></td>
</tr>
</table>
</div>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div><!-- /.box-body -->
</body>
</body>
</html>
when i try to generate pdf it's always coming like this. i added my generate pdf code above .
2 nd page is not coming like 1st page.. i searched and found other dompdf solution for other peoples problem. but my problem is on 2nd page it's not coming as 1stpage.
There's some buggy behavior here on the part of dompdf. For some reason styling the DIV containing your product info with width: 100% is breaking the layout when the table row is paged. If you remove that styling from the DIV then the document should render as expected. The default DIV layout is full-width so you can leave the width styling on the DIV out

Error message while trying to make a shopping cart

The following code is not my own. I'm trying to learn how to make a shopping cart but i'm stuck on this part of the tutorial. Please verify the code and tell me what i'm doing wrong.
This is products.php:
if(isset($_GET['action']) && $_GET['action']=="add"){
$id=intval($_GET['id']);
if(isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id]['quantity']++;
}else{
$query_s=mysql_query($sql_s);
$row_s=mysql_fetch_array($query_s);
$_SESSION['cart'][$row_s'id_product']]=array(
"quantity" => 1,
"price" => $row_s['price']
);
}
}
?>
<h1>Product List</h1>
<?php
echo print_r($_SESSION['cart']);
?>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php
$sql = "SELECT * FROM products ORDER BY name ASC";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<tr>
<td><?php echo $row['name'] ?> </td>
<td><?php echo $row['description'] ?> </td>
<td><?php echo $row['price'] ?>$</td>
<td>Add to cart</td>
</tr>
<?php
}
?>
</table>
This is index.php:
<?php
session_start();
include("connection.php");
if(isset($_GET['page']))
{
$pages=array("products","cart");
if(in_array($_GET['page'], $pages)) {
$_page=$_GET['page'];
}else{
$_page="products";
}
}
else {
$_page="products";
}
?>
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Shopping cart</title>
</head>
<body>
<div id="container">
<div id="main">
<?php require($_page.".php"); ?>
</div> <!--end of main-->
<div id="sidebar">
</div> <!--end of sidebar-->
</div> <!--end of container-->
</body>
</html>
This is the css file style.css:
a {
color: #48577D;
text-decoration:none;
}
a:hover{
text-decoration:underline;
}
body {
font-family: Verdana;
font-size: 12px;
color: #444;
}
h1, h2 { margin-bottom: 15px;}
h1 { font-size:18px;}
h2 {font-size: 16px;}
#container {
width:700px;
margin: 150px auto;
background-color:#eee;
padding:15px;
overflow:hidden;
}
#main {
width: 490px;
float: left;
}
#main table {
width: 480px;
}
#main table th {
padding: 10px;
background-color: #48577D;
color: #fff;
text-align: left;
}
#main table td {
padding: 5px;
}
#sidebar {
width: 200px;
float: left;
}
This is the connection.php:
<?php
$con=mysql_connect("localhost","root","");
$database=mysql_select_db('tutorials');
?>
This is cart.php:
This is your cart
It's not incrementing the values properly. Thanks.
There is a syntax error here:
$_SESSION['cart'][$row_s'id_product']]
I think it's supposed to be:
$_SESSION['cart'][$row_s['id_product']]
You will easily catch these errors if you turn on error reporting. There is no reason to not have it turned on in development.

Categories