Generate Excel File with specific group of output - php

Can someone or somebody help me with my code or with my SQL execution? I'd like to create an excel file based on a specific group of data based on the event/activity they participated in.
Here is my code:
$program_admin = $_SESSION['username'];
$actvty_ID = $_POST['id'];
//$activitydate = $_POST['activity_date'];
if(isset($_POST['export_in_excel'])) {
$excel_sql = "SELECT *
FROM projectcode pj
INNER JOIN activities ac ON ac.projects_id = pj.projects_id
INNER JOIN participants re ON re.act_id = ac.id
WHERE pj.project_code='$program_admin'
ORDER BY re.id DESC "; //pj.project_code='$program_admin'
$excel_result = mysqli_query($connect, $excel_sql);
if(mysqli_num_rows($excel_result) > 0) {
$excel_output .='
<table class="excel_table" style="font-family:Calibri; border:1px solid #1f004d;">
<tr><td></td></tr>
<tr>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d;">No.</th>
<th colspan="2" style="text-align:center; font-weight:bold; border:1px solid #1f004d;">Name</th>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d; ">Age</th>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d; ">Gender</th>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d; ">City/Municipality</th>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d; ">Province</th>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d; ">Contact No.</th>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d; ">Email Address</th>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d; ">Organization</th>
<th style="text-align:center; font-weight:bold; border:1px solid #1f004d; ">Signature</th>
</tr>
';
$no = 1;
while($excel_row = mysqli_fetch_array($excel_result)) {
$excel_output .='
<tr>
<td style="text-align:center;">'.$no.'</td>
<td>'.$excel_row["firstname"].'</td>
<td>'.$excel_row["lastname"].'</td>
<td>'.$excel_row["agerange"].'</td>
<td>'.$excel_row["gender"].'</td>
<td>'.$excel_row["city_municipality"].'</td>
<td>'.$excel_row["province"].'</td>
<td>'.$excel_row["mobileno"].'</td>
<td>'.$excel_row["email"].'</td>
<td>'.$excel_row["org_office"].'</td>
<td></td>
</tr>
';
$no ++;
}
$excel_output .='</table>';
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=Attendance Sheet.xls");
echo $excel_output;
}
}
And here is the sample output of my code:
enter image description here

Related

How to add a delete and edit function into my HTML table which is filled with info from my MySQL database?

I've made this simple PHP/HTML table which shows info in my database, now i want to add a delete and edit function using the SQL DELETE and EDIT functions.
How can i implent this so that every row has a delete button and edit button automaticly when its added to the DB?
Table
<table style="border: 1px solid black;">
<tr>
<th style="border-bottom: 1px solid black;">CI nummer</th>
<th style="border-bottom: 1px solid black;">Aankoopdatum</th>
<th style="border-bottom: 1px solid black;">Serienummer</th>
<th style="border-bottom: 1px solid black;">Merk</th>
<th style="border-bottom: 1px solid black;">Model</th>
<th style="border-bottom: 1px solid black;">OS</th>
<th style="border-bottom: 1px solid black;">Eigenaar</th>
<th style="border-bottom: 1px solid black;">Locatie</th>
<th style="border-bottom: 1px solid black;">Bewerken</th>
<th style="border-bottom: 1px solid black;">Verwijderen</th>
</tr>
<?php
$conn = mysqli_connect("localhost", "root", "", "teradruk");
if (mysqli_connect_errno()) {
echo "Kan geen verbinding maken met de database!";
exit();
}
$sqli = "SELECT * FROM `hardware`";
if ($stmti = $conn->prepare($sqli)) {
if (!$stmti->execute()) {
echo "cant exec: <br> " . $stmti->error;
exit();
} else {
$stmti->bind_result($cinummer, $aankoopdatum, $serienummer, $merk, $model, $os, $eigenaar, $locatie, $applicatie);
$stmti->store_result();
while($stmti->fetch()) {
echo "<tr>
<td>$cinummer</td>
<td>$aankoopdatum</td>
<td>$serienummer</td>
<td>$merk</td>
<td>$model</td>
<td>$os</td>
<td>$eigenaar</td>
<td>$locatie</td>
</tr>";
}
}
} else {
echo "can't prepare: <br> " . $stmti->error;
exit();
}
?>
</table>
I just update the code. but I did not create a EDIT form in HTML and send values, I have write PHP codes
<table style="border: 1px solid black;">
<tr>
<th style="border-bottom: 1px solid black;">CI nummer</th>
<th style="border-bottom: 1px solid black;">Aankoopdatum</th>
<th style="border-bottom: 1px solid black;">Serienummer</th>
<th style="border-bottom: 1px solid black;">Merk</th>
<th style="border-bottom: 1px solid black;">Model</th>
<th style="border-bottom: 1px solid black;">OS</th>
<th style="border-bottom: 1px solid black;">Eigenaar</th>
<th style="border-bottom: 1px solid black;">Locatie</th>
<th style="border-bottom: 1px solid black;">Bewerken</th>
<th style="border-bottom: 1px solid black;">Verwijderen</th>
<th style="border-bottom: 1px solid black;">Options</th>
</tr>
<?php
$conn = mysqli_connect("localhost", "root", "", "teradruk");
if (mysqli_connect_errno()) {
echo "Kan geen verbinding maken met de database!";
exit();
}
if($_GET['action']=="delete")
{
$sql_delete = mysql_query("DELETE FROM hardware WHERE PRIMARY_KEY_OF_hardware_TABLE = ".$_GET['id']." ");
}
elseif($_GET['action']=="edit")
{
$sql_update = "UPDATE hardware SET cinummer = 'New Number' WHERE PRIMARY_KEY_OF_hardware_TABLE = ".$_GET['id']." ";
}
$sqli = "SELECT * FROM `hardware`";
if ($stmti = $conn->prepare($sqli)) {
if (!$stmti->execute()) {
echo "cant exec: <br> " . $stmti->error;
exit();
} else {
$stmti->bind_result($cinummer, $aankoopdatum, $serienummer, $merk, $model, $os, $eigenaar, $locatie, $applicatie);
$stmti->store_result();
while($stmti->fetch()) {
echo "<tr>
<td>$cinummer</td>
<td>$aankoopdatum</td>
<td>$serienummer</td>
<td>$merk</td>
<td>$model</td>
<td>$os</td>
<td>$eigenaar</td>
<td>$locatie</td>
<td><a href='filename.php?id=".$PRIMARY_KEY_OF_hardware_TABLE."&action=delete'>Delete</a> | <a href='filename.php?id=".$PRIMARY_KEY_OF_hardware_TABLE."&action=edit'>Edit</a></td>
</tr>";
}
}
} else {
echo "can't prepare: <br> " . $stmti->error;
exit();
}
?>
</table>
Thanks!

pdf generation using mpdf

I am trying to generate data from database to pdf using mpdf. and i am trying like this
<?php
include("../mpdf/mpdf.php");
$id= $_GET['order_id'];
include('../connect.php');
$mpdf=new mPDF('win-1252','A4','','',20,15,48,25,10,10);
$mpdf->useOnlyCoreFonts = true; // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("My Title");
$mpdf->SetAuthor("Company");
$mpdf->SetWatermarkText("Paid");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
$ss1 = "select orders.order_id, orders.company_id, lead_address.address, lead_address.address_category, lead_address.country, lead_address.state, lead_address.company_id, lead_address.city,lead_address.pin from orders INNER JOIN lead_address ON orders.company_id=lead_address.company_id where lead_address.address_category='Billing' AND orders.order_id=".$_GET['order_id']."";
$mq1 = mysql_query($ss1) or die(mysql_error());
$rr1 = mysql_fetch_array($mq1);
$billing = $rr1['address'];
$country = $rr1['country'];
$state = $rr1['state'];
$city = $rr1['city'];
$pin = $rr1['pin'];
$ss2 = "select orders.order_id, orders.company_id, lead_address.address, lead_address.address_category, lead_address.country, lead_address.state, lead_address.company_id, lead_address.city,lead_address.pin from orders INNER JOIN lead_address ON orders.company_id=lead_address.company_id where lead_address.address_category='Shipping' AND orders.order_id=".$_GET['order_id']."";
$mq2 = mysql_query($ss2) or die(mysql_error());
$rr2 = mysql_fetch_array($mq2);
$shipping = $rr2['address'];
$country1 = $rr2['country'];
$state1 = $rr2['state'];
$city1 = $rr2['city'];
$pin1 = $rr2['pin'];
$sql = "select * from before_order_line_items where order_id = ".$_GET['order_id']." ";
$query = mysql_query($sql);
$html = '
<html>
<head>
<style>
body {font-family: sans-serif;
font-size: 10pt;
}
p { margin: 0pt;
}
td { vertical-align: top; }
.items td {
border-left: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
table thead td { background-color: #EEEEEE;
text-align: center;
border: 0.1mm solid #000000;
}
.items td.blanktotal {
background-color: #FFFFFF;
border: 0mm none #000000;
border-top: 0.1mm solid #000000;
border-right: 0.1mm solid #000000;
}
.items td.totals {
text-align: right;
border: 0.1mm solid #000000;
}
</style>
</head>
<body>
<!--mpdf
<htmlpageheader name="myheader">
<table width="100%"><tr>
<td width="50%" style="color:#0000BB;"><span style="font-weight: bold; font-size: 14pt;"><img src="netelity.png" /></span><br /></td>
<td width="50%" style="text-align: right;">Invoice No.<br /><span style="font-weight: bold; font-size: 12pt;">0012345</span></td>
</tr></table>
</htmlpageheader>
<htmlpagefooter name="myfooter">
<div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
Page {PAGENO} of {nb}
</div>
</htmlpagefooter>
<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->
<div style="text-align: right">Date: '.date('jS F Y').'</div>
<table width="100%" style="font-family: serif;" cellpadding="10">
<tr>
<td width="45%" style="border: 0.1mm solid #888888;"><span style="font-size: 7pt; color: #555555; font-family: sans;">Billing Address</span><br /><br />'.$billing.'<br />'.$country.' , '.$state.'<br />'.$city.' - '.$pin.'</td>
<td width="10%"> </td>
<td width="45%" style="border: 0.1mm solid #888888;"><span style="font-size: 7pt; color: #555555; font-family: sans;">Shipping Address</span><br /><br />'.$shipping.'<br />'.$country1.', '.$state1.'<br />'.$city1.' - '.$pin1.'</td>
</tr>
</table>
<table class="items" width="100%" style="font-size: 9pt;">
<thead>
<tr>
<td width="10%">No</td>
<td width="20%">Item</td>
<td width="10%">UOM</td>
<td width="10%">Price</td>
<td width="10%">Qty</td>
<td width="10%">Disc%</td>
<td width="10%">Tax%</td>
<td width="10%">Frt</td>
<td width="10%">Total</td>
</tr>
</thead>
<tbody>
<!-- ITEMS HERE -->
';
while($row = mysql_fetch_array($query))
{
'
<tr>
<td>'.$row['id'].'</td>
<td>'.$row['item'].' <br> '.$row['description'].'</td>
<td>'.$row['uom'].'</td>
<td>'.$row['selling_price'].'</td>
<td>'.$row['quantity'].'</td>
<td>'.$row['discount'].'</td>
<td>'.$row['tax'].'</td>
<td>'.$row['freight'].'</td>
<td>'.$row['total'].'</td>
</tr>
';
}
'
</tbody>
</table>
<div style="text-align: center; font-style: italic;">Payment terms: payment due in 30 days</div>
</body>
</html>
';
$mpdf->WriteHTML($html);
$mpdf->Output(); exit;
exit;
?>
Only Shipping and billing address are getting displayed. From the second table its not showing anything. It shows blank.
How to do this?
You're forgetting to add the $html in your while loop.
'
<tr>
<td>'.$row['id'].'</td>
<td>'.$row['item'].' <br> '.$row['description'].'</td>
<td>'.$row['uom'].'</td>
<td>'.$row['selling_price'].'</td>
<td>'.$row['quantity'].'</td>
<td>'.$row['discount'].'</td>
<td>'.$row['tax'].'</td>
<td>'.$row['freight'].'</td>
<td>'.$row['total'].'</td>
</tr>
';
should be
$html .= '
<tr>
<td>'.$row['id'].'</td>
<td>'.$row['item'].' <br> '.$row['description'].'</td>
<td>'.$row['uom'].'</td>
<td>'.$row['selling_price'].'</td>
<td>'.$row['quantity'].'</td>
<td>'.$row['discount'].'</td>
<td>'.$row['tax'].'</td>
<td>'.$row['freight'].'</td>
<td>'.$row['total'].'</td>
</tr>
';

Working With Temporary Tables in MySQL

I have some link which show data on iframe with the help of temporary data from database
I am fetching this data with the help of query strings
The page with Links is
<style type="text/css">
a
{
text-decoration:none;
}
.Menu
{
width:150px;
float:left;
}
.fr
{
width:800px;
height:800px;
float:right
}
</style>
<div class="Menu">
<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
$sql="select * from NSEIndices_latest";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$tpnt=$row['TickerPlantCode']; //nse indice code
$indexname=$row['IndexName']; //nse indice index name
?>
<tr>
<td><?php echo $indexname;?><br></td>
</tr>
<?php }?>
</div>
<div class="fr">
<iframe height="780" width="780" scrolling="no" name="fr"></iframe>
</div>
Now the link from above page fetch data with the help of query string at this page a temporary table is created by collectiong data from various tables
but am getting error while retrieve data from that temporary table
the page with temporary table is
<table class="table" cellspacing="0" width="100%">
<tr>
<td align="left" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9;">Company Name
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">High
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Low
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Last Price
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Prv Close
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Change
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">%Gain
</th>
</tr>
<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
$tpnt=$_GET['tpnt'];
$indexname=$_GET['indexname'];
echo "1".$indexname. "<br>";
$query="SELECT nsepricequotes_latest.Symbol, nsepricequotes_latest.CompanyName, nsepricequotes_latest.HighPrice, nsepricequotes_latest.LowPrice, nsepricequotes_latest.LastTradedPrice, nsepricequotes_latest.ClosePrice, nsepricequotes_latest.NetChange, nsepricequotes_latest.PercentChange, nse_index_constituents.Tickerplant_index_code,nse_index_constituents.NSE_Index_Name
FROM nsepricequotes_latest, nse_index_constituents
WHERE nsepricequotes_latest.TickerPlantCode = nse_index_constituents.TickerPlant_scrip
AND PercentChange >0
ORDER BY PercentChange DESC ";
$result=mysql_query($query);
echo "2".$indexname. "<br>";
while($row1=mysql_fetch_array($result))
{
$Symbol1=$row1['Symbol'];
$CompanyName1=$row1['CompanyName'];
$HighPrice1=$row1['HighPrice'];
$LowPrice1=$row1['LowPrice'];
$LastTradedPrice1=$row1['LastTradedPrice'];
$ClosePrice1=$row1['ClosePrice'];
$NetChange1=$row1['NetChange'];
$PercentChange1=$row1['PercentChange'];
$Tickerplant_index_code1=$row1['Tockerplant_index_code1'];
$NSE_Index_Name1=$row1['NSE_Index_Name'];
}
echo "3".$indexname. "<br>";
$tbl="create TEMPORARY TABLE temppice(Symbol varchar(100),CompanyName varchar(200),HighPrice float(50),LowPrice float(50),LastTradedPrice float(50),ClosePrice float(50),NetChange float(50),PercentChange float(50),Tickerplant_index_code varchar(100),NSe_Index_Name varchar(100))";
$res=mysql_query($tbl);
if (!$res) { die('Temporary table creation failed: ' . mysql_error()); }
if(mysql_error())die(mysql_error());
$intbl="Insert into temppice values('$Symbol1','$CompanyName1','$HighPrice1','$LowPrice1','$LastTradedPrice','$ClosePrice1','$NetChange1','$PercentChange1','$Tockerplant_index_code1','$NSE_Index_Name1')";
mysql_query($intbl);
if(mysql_error())die(mysql_error());
echo "4".$indexname. "<br>";
$query1="Select * from temppice where NSE_Index_Name=$indexname";
$result1=mysql_query($query1);
//if(mysql_error())die(mysql_error());
while($row=mysql_fetch_array($result1, MYSQL_BOTH))
{
$symbol=$row['Symbol'];
$CompanyName=$row['CompanyName'];
$HighPrice=$row['HighPrice'];
$LowPrice=$row['LowPrice'];
$previousclose=$row['LastTradedPrice'];
$ClosePrice=$row['ClosePrice'];
$netChange=$row['NetChange'];
$percentagechange=$row['PercentChange'];
?>
<tr>
<td align="left" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $CompanyName;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $HighPrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $LowPrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $previousclose; ?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $ClosePrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $netChange;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $percentagechange;?></td>
</tr>
<?php } ?>
</table>
the error am getting is
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mastertr/public_html/master/wpfiles/gtnsegainers.php on line 58
TEMPORARY tables have lifetime of one connection, so if you create the table during one request from the browser, and then want to fetch data from it in another request.... it's no longer there. The table does not exist and your query fails with no such table in database error.

Get Data From a Table Created by Equi Join Query

i have a table created by my sql equijoin
and i want to retrieve data from that table by am getting error
the error is
dname.resource doesn't exist
and the code is
<style type="text/css">
a
{
text-decoration:none;
}
.Menu
{
width:150px;
float:left;
}
.fr
{
width:800px;
height:800px;
float:right
}
</style>
<div class="Menu">
<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbanme");
$sql="select * from NSEIndices_latest";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$tpnt=$row['TickerPlantCode']; //nse indice code
$indexname=$row['IndexName']; //nse indice index name
?>
<tr>
<td><?php echo $indexname;?><br></td>
</tr>
<?php }?>
</div>
<div class="fr">
<iframe height="780" width="780" scrolling="no" name="fr"></iframe>
</div>
the gtnsegainer.php page on am getting error is
the gtnsegainer page is in iframe
this page retrieve data from database according to the link on the above page
<table class="table" cellspacing="0" width="100%">
<tr>
<td align="left" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9;">Company Name
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">High
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Low
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Last Price
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Prv Close
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Change
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">%Gain
</th>
</tr>
<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
$tpnt=$_GET['tpnt'];
$indexname=$_GET['indexname'];
$query="SELECT nsepricequotes_latest.Symbol, nsepricequotes_latest.CompanyName, nsepricequotes_latest.HighPrice, nsepricequotes_latest.LowPrice, nsepricequotes_latest.LastTradedPrice, nsepricequotes_latest.ClosePrice, nsepricequotes_latest.NetChange, nsepricequotes_latest.PercentChange, nse_index_constituents.Tickerplant_index_code
FROM nsepricequotes_latest, nse_index_constituents
WHERE nsepricequotes_latest.TickerPlantCode = nse_index_constituents.TickerPlant_scrip
AND PercentChange >0
ORDER BY PercentChange DESC ";
$result=mysql_query($query);
$query1="Select * from $result where NSE_Index_Name=$indexname";
$result1=mysql_query($query1);
while($row=mysql_fetch_array($result1))
{
$symbol=$row['Symbol'];
$CompanyName=$row['CompanyName'];
$HighPrice=$row['HighPrice'];
$LowPrice=$row['LowPrice'];
$previousclose=$row['LastTradedPrice'];
$ClosePrice=$row['ClosePrice'];
$netChange=$row['NetChange'];
$percentagechange=$row['PercentChange'];
?>
<tr>
<td align="left" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $CompanyName;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $HighPrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $LowPrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $previousclose; ?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $ClosePrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $netChange;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $percentagechange;?></td>
</tr>
<?php } ?>
</table>
it is hard to tell what your error is, in your particular setup, but i recommend adding some simple debugging as such, after each mysql_query($query); add if(mysql_error())die(mysql_error()); and that will point you in the right direction.

Global Temporary Table Creation Failed

i have some link which show data on iframe with the help of temporary data from database
i am fetching this data with the help of query strings
the page with Links is
<style type="text/css">
a
{
text-decoration:none;
}
.Menu
{
width:150px;
float:left;
}
.fr
{
width:800px;
height:800px;
float:right
}
</style>
<div class="Menu">
<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
$sql="select * from NSEIndices_latest";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$tpnt=$row['TickerPlantCode']; //nse indice code
$indexname=$row['IndexName']; //nse indice index name
?>
<tr>
<td><?php echo $indexname;?><br></td>
</tr>
<?php }?>
</div>
<div class="fr">
<iframe height="780" width="780" scrolling="no" name="fr"></iframe>
</div>
Now the link from above page fetch data with the help of query string at this page a temporary table is created by collectiong data from various tables
but am getting error while retrieve data from that temporary table
the page with temporary table is
<table class="table" cellspacing="0" width="100%">
<tr>
<td align="left" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9;">Company Name
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">High
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Low
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Last Price
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Prv Close
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Change
</th>
<td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">%Gain
</th>
</tr>
<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
$tpnt=$_GET['tpnt'];
$indexname=$_GET['indexname'];
echo "1".$indexname. "<br>";
$query="SELECT nsepricequotes_latest.Symbol, nsepricequotes_latest.CompanyName, nsepricequotes_latest.HighPrice, nsepricequotes_latest.LowPrice, nsepricequotes_latest.LastTradedPrice, nsepricequotes_latest.ClosePrice, nsepricequotes_latest.NetChange, nsepricequotes_latest.PercentChange, nse_index_constituents.Tickerplant_index_code,nse_index_constituents.NSE_Index_Name
FROM nsepricequotes_latest, nse_index_constituents
WHERE nsepricequotes_latest.TickerPlantCode = nse_index_constituents.TickerPlant_scrip
AND PercentChange >0
ORDER BY PercentChange DESC ";
$result=mysql_query($query);
echo "2".$indexname. "<br>";
while($row1=mysql_fetch_array($result))
{
$Symbol1=$row1['Symbol'];
$CompanyName1=$row1['CompanyName'];
$HighPrice1=$row1['HighPrice'];
$LowPrice1=$row1['LowPrice'];
$LastTradedPrice1=$row1['LastTradedPrice'];
$ClosePrice1=$row1['ClosePrice'];
$NetChange1=$row1['NetChange'];
$PercentChange1=$row1['PercentChange'];
$Tickerplant_index_code1=$row1['Tockerplant_index_code1'];
$NSE_Index_Name1=$row1['NSE_Index_Name'];
}
echo "3".$indexname. "<br>";
$tbl="create GLOBAL TEMPORARY TABLE temppice(Symbol varchar(100),CompanyName varchar(200),HighPrice float(50),LowPrice float(50),LastTradedPrice float(50),ClosePrice float(50),NetChange float(50),PercentChange float(50),Tickerplant_index_code varchar(100),NSe_Index_Name varchar(100)) ON COMMIT DELETE ROWS;";
$res=mysql_query($tbl);
if (!$res) { die('Temporary table creation failed: ' . mysql_error()); }
if(mysql_error())die(mysql_error());
$intbl="Insert into temppice values('$Symbol1','$CompanyName1','$HighPrice1','$LowPrice1','$LastTradedPrice','$ClosePrice1','$NetChange1','$PercentChange1','$Tockerplant_index_code1','$NSE_Index_Name1')";
mysql_query($intbl);
if(mysql_error())die(mysql_error());
echo "4".$indexname. "<br>";
$query1="Select * from temppice where NSE_Index_Name=$indexname";
$result1=mysql_query($query1);
//if(mysql_error())die(mysql_error());
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
while($row=mysql_fetch_array($result1, MYSQL_BOTH))
{
$symbol=$row['Symbol'];
$CompanyName=$row['CompanyName'];
$HighPrice=$row['HighPrice'];
$LowPrice=$row['LowPrice'];
$previousclose=$row['LastTradedPrice'];
$ClosePrice=$row['ClosePrice'];
$netChange=$row['NetChange'];
$percentagechange=$row['PercentChange'];
?>
<tr>
<td align="left" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $CompanyName;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $HighPrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $LowPrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $previousclose; ?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $ClosePrice;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $netChange;?></td>
<td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $percentagechange;?></td>
</tr>
<?php } ?>
</table>
the error am getting is
Temporary table creation failed: You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'GLOBAL TEMPORARY TABLE
temppice(Symbol varchar(100),CompanyName varchar(200),Hig' at line 1
According to the manual the MySQL CREATE TABLE syntax does not support the global keyword. That appears to be an Oracle thing. Likewise I believe that the ON COMMIT DELETE ROWS clause is part of the Oracle syntax which will not work in MySQL either.
If you remove those two parts it will probably work:
$tbl=<<<SQL
create TEMPORARY TABLE temppice (
Symbol varchar(100),
CompanyName varchar(200),
HighPrice float(50),
LowPrice float(50),
LastTradedPrice float(50),
ClosePrice float(50),
NetChange float(50),
PercentChange float(50),
Tickerplant_index_code varchar(100),
NSe_Index_Name varchar(100)
);
SQL;

Categories