Hello this is the code in my php, i dont get error but the items in the database doesn't show and only the else tag is execute.
<?php
$sql = $bdd->prepare('SELECT * FROM bgk9z_items');
if ($sql->fetchColumn() > 0) { //
while ($result = $sql->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<th id="checkbox"><input type="checkbox" name="toggle" /></th>
<td id="titre"><? echo $result['title']; ?>
<div class="opt"><span class="up">Modifier</span> <span class="del">Supprimer</span> <span class="sho">Afficher</span></div>
</td>
<td id="extrait"><? $string = $result['introtext']; $long = (strlen($string) > 13) ? substr($string,0,280).'...' : $string; echo $long;?></td>
<td id="cat"><? include_once(dirname(__DIR__) . '/controlers/show-cat-name.php'); ?></td>
<td id="etat"><? $rep = $result['published']; if ($rep == 1) { echo "Oui";} else{echo "Non";} ?></td>
<td id="image"><? echo "Image"; ?></td>
<td id="ident"><? echo $result['id']; ?></td>
</tr>
<?
}
}
else { ?>
<tr><td colspan="7" style="text-align: center; color: rgb(192, 0, 0); font-size: 23px; font-weight: bold;">NO ITEM TO SHOW</td></tr>
<?php }
?
Related
In my PHP code is below.
<table width="100%" >
<tr width="100%" class="bgcolor_02">
<th ROWSPAN="2" >SUBJECTS </th>
<th COLSPAN="2" >EXAMS </th>
<th COLSPAN="2" >PROJECTS </th>
</tr>
<tr class="bgcolor_02">
<th id="1E"> 1.EXAM</th>
<th id="2E"> 2.EXAM</th>
<th id="1P"> 1.PROJECT</th>
<th id="2P"> 2.PROJECT</th>
</tr>
<?php
$myexamresults = $db-> getrows (" SELECT * FROM `es_exam_result` WHERE `es_studentid` = '".$_SESSION['eschools']['user_id']."' ORDER BY `es_examorder` ASC ");
$pre_subjects=subjectnameByClass($es_subjectshortname);
foreach ($pre_subjects as $ndsdersliste ) {
$subjeid=$ndsdersliste['es_subjectid']; ?>
<tr > <td ><?php echo $ndsdersliste['es_subjectname']; ?></td>
<?php
foreach ($myexamresults as $ndsmyexam) {
$puan="";
if( $ndsdersliste['es_subjectname'] == $ndsmyexam['es_subjectname'] ) {
$examname = $ndsmyexam['es_examname'];
$puan = $ndsmyexam['es_puan'];
if ($examname =="1.Exam"){ ?> <td headers="1E" ><?php {echo $puan ;} ?> </td> <?php }
if ($examname =="2.Exam"){ ?> <td headers="2E" ><?php {echo $puan ;} ?> </td> <?php }
if ($examname =="1.Project"){ ?> <td headers="1P" ><?php {echo $puan ;} ?> </td> <?php }
if ($examname =="2.Project"){ ?> <td headers="2P" ><?php {echo $puan ;} ?> </td> <?php }
} } ?>
</tr>
<?php } ?>
</table>
I can get exam results from database. But I can not insert correct data under headers. If a student have just "1.Project" result, It is showing under "1.Exam". How to insert under correct title. Thanks..
You have to create empty <td> if there is no result to have the same number of <td> for each <tr>:
<tr > <td ><?php echo $ndsdersliste['es_subjectname']; ?></td>
<?php
$td = [];
foreach ($myexamresults as $ndsmyexam) {
$puan="";
if( $ndsdersliste['es_subjectname'] == $ndsmyexam['es_subjectname'] )
{
$examname = $ndsmyexam['es_examname'];
$puan = $ndsmyexam['es_puan'];
if ($examname =="1.Exam") { $td['1E'] = $puan ; }
if ($examname =="2.Exam") { $td['2E'] = $puan ; }
if ($examname =="1.Project") { $td['1P'] = $puan ; }
if ($examname =="2.Project") { $td['2P'] = $puan ; }
}
}
if (isset($td['1E'])) echo '<td headers="1E">'.$td['1E'] .'</td>' ; else echo '<td headers="1E"></td>' ;
if (isset($td['2E'])) echo '<td headers="2E">'.$td['2E'] .'</td>' ; else echo '<td headers="2E"></td>' ;
if (isset($td['1P'])) echo '<td headers="1P">'.$td['1P'] .'</td>' ; else echo '<td headers="1P"></td>' ;
if (isset($td['2P'])) echo '<td headers="2P">'.$td['2P'] .'</td>' ; else echo '<td headers="2P"></td>' ;
?>
</tr>
I have added PHP code to generate a PDF file in Arabic and English, but when content is in Arabic it shows like this php arabic output :
I have checked the font i'm using is compatible with the Arabic language. I am not sure what I am missing. I also have the unicode to be UTF-8 in my configuration file.
here is the code
<?php
$paid_amount = $this->invoice_model->calculate_to('paid_amount', $invoice_info->invoices_id);
$client_info = $this->invoice_model->check_by(array('client_id' => $invoice_info->client_id), 'tbl_client');
if (!empty($client_info)) {
$currency = $this->invoice_model->client_currency_sambol($invoice_info->client_id);
$client_lang = $client_info->language;
} else {
$client_lang = 'arabic';
$currency = $this->invoice_model->check_by(array('code' => config_item('default_currency')), 'tbl_currencies');
}
unset($this->lang->is_loaded[5]);
$language_info = $this->lang->load('sales_lang', $client_lang, TRUE, FALSE, '', TRUE);
$payment_status = $this->invoice_model->get_payment_status($invoice_info->invoices_id);
$uri = $this->uri->segment(3);
if ($uri == 'invoice_email') {
$img = base_url() . config_item('invoice_logo');
} else {
$img = $_SERVER['DOCUMENT_ROOT'] . '/' . config_item('invoice_logo');
$a = file_exists($img);
if (empty($a)) {
$img = base_url() . config_item('invoice_logo');
}
}
?>
<table class="clearfix">
<tr>
<td>
<div id="logo" style="margin-top: 8px;">
<img style=" height: 70px;" src="<?= $img ?>">
</div>
</td>
<td>
<div id="company">
<h2 class="name"><?= (config_item('company_legal_name_' . $client_lang) ? config_item('company_legal_name_' . $client_lang) : config_item('company_legal_name')) ?></h2>
<div><?= (config_item('company_address_' . $client_lang) ? config_item('company_address_' . $client_lang) : config_item('company_address')) ?></div>
<div><?= (config_item('company_city_' . $client_lang) ? config_item('company_city_' . $client_lang) : config_item('company_city')) ?>
, <?= config_item('company_zip_code') ?></div>
<div><?= (config_item('company_country_' . $client_lang) ? config_item('company_country_' . $client_lang) : config_item('company_country')) ?></div>
<div> <?= config_item('company_phone') ?></div>
<div><?= config_item('company_email') ?></div>
</div>
</td>
</tr>
</table>
<table id="details" class="clearfix">
<tr>
<td>
<div id="client">
<?php
if (!empty($client_info)) {
$client_name = $client_info->name;
$address = $client_info->address;
$city = $client_info->city;
$zipcode = $client_info->zipcode;
$country = $client_info->country;
$phone = $client_info->phone;
$email = $client_info->email;
} else {
$client_name = '-';
$address = '-';
$city = '-';
$zipcode = '-';
$country = '-';
$phone = '-';
$email = '-';
}
?>
<h2 class="name"><?= $client_name ?></h2>
<div class="address"><?= $address ?></div>
<div class="address"><?= $city ?>, <?= $zipcode ?>
,<?= $country ?></div>
<div class="address"><?= $phone ?></div>
<div class="email"><?= $email ?></div>
</div>
</td>
<td>
<div id="invoice">
<h1><?= $invoice_info->reference_no ?></h1>
<div class="date"><?= $language_info['invoice_date'] ?>
:<?= strftime(config_item('date_format'), strtotime($invoice_info->invoice_date)); ?></div>
<div class="date"><?= $language_info['due_date'] ?>
:<?= strftime(config_item('date_format'), strtotime($invoice_info->due_date)); ?></div>
<?php if (!empty($invoice_info->user_id)) { ?>
<div class="date">
<?= lang('sales') . ' ' . lang('agent') ?><?php
$profile_info = $this->db->where('user_id', $invoice_info->user_id)->get('tbl_account_details')->row();
if (!empty($profile_info)) {
echo $profile_info->fullname;
}
?>
</div>
<?php } ?>
<div class="date"><?= $language_info['payment_status'] ?>: <?= $payment_status ?></div>
</div>
</td>
</tr>
</table>
<table class="items" border="0" cellspacing="0" cellpadding="0" page-break-inside: auto;>
<thead>
<tr>
<th class="desc"><?= $language_info['items'] ?></th>
<?php
$invoice_view = config_item('invoice_view');
if (!empty($invoice_view) && $invoice_view == '2') {
?>
<th><?= $language_info['hsn_code'] ?></th>
<?php } ?>
<th class="unit"><?= $language_info['qty'] ?></th>
<th class="desc"><?= $language_info['price'] ?></th>
<th class="unit"><?= $language_info['tax'] ?></th>
<th class="total"><?= $language_info['total'] ?></th>
</tr>
</thead>
<tbody>
<?php
$invoice_items = $this->invoice_model->ordered_items_by_id($invoice_info->invoices_id);
if (!empty($invoice_items)) :
foreach ($invoice_items as $key => $v_item) :
$item_name = $v_item->item_name ? $v_item->item_name : $v_item->item_desc;
$item_tax_name = json_decode($v_item->item_tax_name);
?>
<tr>
<td class="desc"><h3><?= $item_name ?></h3><?= nl2br($v_item->item_desc) ?></td>
<?php
$invoice_view = config_item('invoice_view');
if (!empty($invoice_view) && $invoice_view == '2') {
?>
<td><?= $v_item->hsn_code ?></td>
<?php } ?>
<td class="unit"><?= $v_item->quantity . ' ' . $v_item->unit ?></td>
<td class="desc"><?= display_money($v_item->unit_cost) ?></td>
<td class="unit"><?php
if (!empty($item_tax_name)) {
foreach ($item_tax_name as $v_tax_name) {
$i_tax_name = explode('|', $v_tax_name);
echo '<small class="pr-sm">' . $i_tax_name[0] . ' (' . $i_tax_name[1] . ' %)' . '</small>' . display_money($v_item->total_cost / 100 * $i_tax_name[1]) . ' <br>';
}
}
?></td>
<td class="total"><?= display_money($v_item->total_cost) ?></td>
</tr>
<?php endforeach; ?>
<?php endif ?>
</tbody>
<tfoot>
<tr class="total">
<td colspan="3"></td>
<td colspan="1"><?= $language_info['sub_total'] ?></td>
<td><?= display_money($this->invoice_model->calculate_to('invoice_cost', $invoice_info->invoices_id)) ?></td>
</tr>
<?php if ($invoice_info->discount_total > 0): ?>
<tr class="total">
<td colspan="3"></td>
<td colspan="1"><?= $language_info['discount'] ?>(<?php echo $invoice_info->discount_percent; ?>%)</td>
<td> <?= display_money($this->invoice_model->calculate_to('discount', $invoice_info->invoices_id)) ?></td>
</tr>
<?php endif;
$tax_info = json_decode($invoice_info->total_tax);
$tax_total = 0;
if (!empty($tax_info)) {
$tax_name = $tax_info->tax_name;
$total_tax = $tax_info->total_tax;
if (!empty($tax_name)) {
foreach ($tax_name as $t_key => $v_tax_info) {
$tax = explode('|', $v_tax_info);
$tax_total += $total_tax[$t_key];
?>
<tr class="total">
<td colspan="3"></td>
<td colspan="1"><?= $tax[0] . ' (' . $tax[1] . ' %)' ?></td>
<td> <?= display_money($total_tax[$t_key]); ?></td>
</tr>
<?php }
}
} ?>
<?php if ($tax_total > 0): ?>
<tr class="total">
<td colspan="3"></td>
<td colspan="1"><?= $language_info['total'] . ' ' . $language_info['tax'] ?></td>
<td><?= display_money($tax_total); ?></td>
</tr>
<?php endif;
if ($invoice_info->adjustment > 0): ?>
<tr class="total">
<td colspan="3"></td>
<td colspan="1"><?= $language_info['adjustment'] ?></td>
<td><?= display_money($invoice_info->adjustment); ?></td>
</tr>
<?php endif ?>
<tr class="total">
<td colspan="3"></td>
<td colspan="1"><?= $language_info['total'] ?></td>
<td><?= display_money($this->invoice_model->calculate_to('total', $invoice_info->invoices_id), $currency->symbol); ?></td>
</tr>
<?php
$paid_amount = $this->invoice_model->calculate_to('paid_amount', $invoice_info->invoices_id);
if ($paid_amount > 0) {
$total = $language_info['total_due'];
if ($paid_amount > 0) {
$text = 'style="color:red"';
?>
<tr class="total">
<td colspan="3"></td>
<td colspan="1"><?= $language_info['paid_amount'] ?></td>
<td><?= $paid_amount ?></td>
</tr>
<?php } else {
$text = '';
} ?>
<tr class="total">
<td colspan="3"></td>
<td colspan="1"><span <?= $text ?>><?= $total ?></span></td>
<td><?= display_money($this->invoice_model->calculate_to('invoice_due', $invoice_info->invoices_id), $currency->symbol); ?></td>
</tr>
<?php } ?>
</tfoot>
</table>
<div id="thanks"><?= lang('thanks') ?>!</div>
<div id="notices">
<div class="notice"><?= $invoice_info->notes ?></div>
</div>
<?php
$invoice_view = config_item('invoice_view');
if (!empty($invoice_view) && $invoice_view > 0) {
?>
<style type="text/css">
.panel {
margin-bottom: 21px;
background-color: #ffffff;
border: 1px solid transparent;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}
.panel-custom .panel-heading {
border-bottom: 2px solid #2b957a;
}
.panel .panel-heading {
border-bottom: 0;
font-size: 14px;
}
.panel-heading {
padding: 10px 15px;
border-bottom: 1px solid transparent;
border-top-right-radius: 3px;
border-top-left-radius: 3px;
}
.panel-title {
margin-top: 0;
margin-bottom: 0;
font-size: 16px;
}
</style>
<div class="panel panel-custom" style="margin-top: 20px">
<div class="panel-heading" style="border:1px solid #dde6e9;border-bottom: 2px solid #57B223;">
<div class="panel-title"><?= lang('tax_summary') ?></div>
</div>
<table class="items" border="0" cellspacing="0" cellpadding="0" page-break-inside: auto;>
<thead>
<tr>
<th class="desc"><?= $language_info['items'] ?></th>
<?php
$invoice_view = config_item('invoice_view');
if (!empty($invoice_view) && $invoice_view == '2') {
?>
<th><?= lang('hsn_code') ?></th>
<?php } ?>
<th class="unit"><?= $language_info['qty'] ?></th>
<th class="desc"><?= $language_info['tax'] ?></th>
<th class="unit" style="text-align: right"><?= $language_info['total_tax'] ?></th>
<th class="total" style="text-align: right"><?= $language_info['tax_excl_amt'] ?></th>
</tr>
</thead>
<tbody>
<?php
$total_tax = 0;
$total_cost = 0;
if (!empty($invoice_items)) :
foreach ($invoice_items as $key => $v_item) :
$item_tax_name = json_decode($v_item->item_tax_name);
$tax_amount = 0;
?>
<tr>
<td class="desc"><?= $v_item->item_name ?></td>
<?php
$invoice_view = config_item('invoice_view');
if (!empty($invoice_view) && $invoice_view == '2') {
?>
<td><?= $v_item->hsn_code ?></td>
<?php } ?>
<td class="unit"><?= $v_item->quantity . ' ' . $v_item->unit ?></td>
<td class="desc"><?php
if (!empty($item_tax_name)) {
foreach ($item_tax_name as $v_tax_name) {
$i_tax_name = explode('|', $v_tax_name);
$tax_amount += $v_item->total_cost / 100 * $i_tax_name[1];
echo '<small class="pr-sm">' . $i_tax_name[0] . ' (' . $i_tax_name[1] . ' %)' . '</small>' . display_money($v_item->total_cost / 100 * $i_tax_name[1]) . ' <br>';
}
}
$total_cost += $v_item->total_cost;
$total_tax += $tax_amount;
?></td>
<td class="unit" style="text-align: right"><?= display_money($tax_amount) ?></td>
<td class="total" style="text-align: right"><?= display_money($v_item->total_cost) ?></td>
</tr>
<?php endforeach; ?>
<?php endif ?>
</tbody>
<tfoot>
<tr class="total">
<td colspan="3"></td>
<td><?= $language_info['total'] ?></td>
<td><?= display_money($total_tax) ?></td>
<td><?= display_money($total_cost) ?></td>
</tr>
</tfoot>
</table>
</div>
<?php } ?>
<footer>
<?= config_item('invoice_footer') ?>
</footer>
I'm having problems showing all the results in my modal. There are three rows I want to display in the modal: Billing months for June 2016, May 2016, and April 2016, but only the latest(June 2016) will show. Here's the part of my code:
if(isset($_GET['id']))
{
$page_id = $_GET['id'];
$select_query = "SELECT * FROM billing_info INNER JOIN customer_login ON billing_info.account_no=customer_login.account_no WHERE billing_info.account_no='$page_id' ";
$run_query = mysqli_query($conn,$select_query);
while($row = mysqli_fetch_array($run_query))
{
$id = $row['user_id'];
$cust_fname = $row['cust_fname'];
$cust_mname = $row['cust_mname'];
$cust_lname = $row['cust_lname'];
$branch = $row['branch'];
$account_no = $row['account_no'];
$billing_month = $row['billing_month'];
$pres_reading = $row['pres_reading'];
$prev_reading = $row['prev_reading'];
$payment_status = $row['payment_status'];
$due_date = $row['due_date'];
$int_pres = intval($row["pres_reading"]);
$int_prev = intval($row["prev_reading"]);
$difference = $int_pres-$int_prev;
$payment = $difference*26.678;
$cust_fname = ucfirst($cust_fname);
$cust_mname = ucfirst($cust_mname);
$cust_lname = ucfirst($cust_lname);
$branch = ucfirst($branch);
?>
<div id="openModal" class="modalDialog" style="width:100%;">
<div id="form-sms" style="height: 500px; overflow: scroll;">
<div class="close"> X</div>
<form method="get" action="customer_view.php?id=<?php echo $id; ?>" name="id" enctype="multipart/form-data">
<table width="100%" bgcolor="white" align="center">
<style type="text/css">
td.hundred{
width: 80%;
text-align: center;
}
input {
width: 100%;
}
input[type="text"]{
width: 90%;
text-align: left;
}
input[type="submit"]{
width: 100%;
text-align: center;
}
textarea{
width: 90%;
text-align: left;
margin-left: 10%;
}
td {
padding: 10px;
}
.tdhover:hover {
color: #AFEEEE;
}
</style>
<tr >
<td align="center" colspan="10"><h1><?php echo $cust_fname." ".$cust_mname." ".$cust_lname." - ".$account_no." - ".$branch." Details" ?></h1></td>
</tr>
<tr bgcolor="#20B2AA">
<th>Billing Month</th>
<th>Present Reading</th>
<th>Previous Reading</th>
<th>Payment</th>
<th>Status</th>
<th>Due Date</th>
<th>Water Usage (in m<sup>3</sup>)</th>
<th>Edit</th>
</tr>
<tr bgcolor="#AFEEEE">
<td><?php echo $billing_month; ?></td>
<td><?php echo $pres_reading; ?></td>
<td><?php echo $prev_reading; ?></td>
<td><?php echo "Php " . $payment; ?></td>
<td><?php echo $payment_status; ?></td>
<td><?php echo $due_date; ?></td>
<td><?php echo $difference; ?></td>
<td>Edit</td>
</tr>
<tr style="margin-top: 10px;">
<td bgcolor="#20B2AA" align="center" class="tdhover" colspan="10">Add Billing Information</td>
</tr>
</table>
</form>
</style>
</table>
</form>
</div>
</div>
<?php } }?>
You should loop/parse the data only for <tr> and <td> Not for all tag like <table> and <div> outer the table. Html will loop all of inside { ... } sign.
Then, your style code should be placed the upper (not fix with html/php). This your code should be:
<style type="text/css">
td.hundred{
width: 80%;
text-align: center;
}
input {
width: 100%;
}
input[type="text"]{
width: 90%;
text-align: left;
}
input[type="submit"]{
width: 100%;
text-align: center;
}
textarea{
width: 90%;
text-align: left;
margin-left: 10%;
}
td {
padding: 10px;
}
.tdhover:hover {
color: #AFEEEE;
}
</style>
<?php
if (isset($_GET['id'])) {//open the isset
$page_id = $_GET['id'];
$select_query = "SELECT * FROM billing_info INNER JOIN customer_login ON billing_info.account_no=customer_login.account_no WHERE billing_info.account_no='$page_id' ";
$run_query = mysqli_query($conn, $select_query);
?>
<div id="openModal" class="modalDialog" style="width:100%;">
<div id="form-sms" style="height: 500px; overflow: scroll;">
<div class="close"> X</div>
<form method="get" action="customer_view.php?id=<?php echo $id; ?>" name="id" enctype="multipart/form-data">
<table width="100%" bgcolor="white" align="center">
<?php
while ($row = mysqli_fetch_array($run_query)) { //open the while
$id = $row['user_id'];
$cust_fname = $row['cust_fname'];
$cust_mname = $row['cust_mname'];
$cust_lname = $row['cust_lname'];
$branch = $row['branch'];
$account_no = $row['account_no'];
$billing_month = $row['billing_month'];
$pres_reading = $row['pres_reading'];
$prev_reading = $row['prev_reading'];
$payment_status = $row['payment_status'];
$due_date = $row['due_date'];
$int_pres = intval($row["pres_reading"]);
$int_prev = intval($row["prev_reading"]);
$difference = $int_pres - $int_prev;
$payment = $difference * 26.678;
$cust_fname = ucfirst($cust_fname);
$cust_mname = ucfirst($cust_mname);
$cust_lname = ucfirst($cust_lname);
$branch = ucfirst($branch);
?>
<tr >
<td align="center" colspan="10"><h1><?php echo $cust_fname . " " . $cust_mname . " " . $cust_lname . " - " . $account_no . " - " . $branch . " Details" ?></h1></td>
</tr>
<tr bgcolor="#20B2AA">
<th>Billing Month</th>
<th>Present Reading</th>
<th>Previous Reading</th>
<th>Payment</th>
<th>Status</th>
<th>Due Date</th>
<th>Water Usage (in m<sup>3</sup>)</th>
<th>Edit</th>
</tr>
<tr bgcolor="#AFEEEE">
<td><?php echo $billing_month; ?></td>
<td><?php echo $pres_reading; ?></td>
<td><?php echo $prev_reading; ?></td>
<td><?php echo "Php " . $payment; ?></td>
<td><?php echo $payment_status; ?></td>
<td><?php echo $due_date; ?></td>
<td><?php echo $difference; ?></td>
<td>Edit</td>
</tr>
<tr style="margin-top: 10px;">
<td bgcolor="#20B2AA" align="center" class="tdhover" colspan="10">Add Billing Information</td>
</tr>
<?php } //while closing
?>
</table>
</form>
</style>
</table>
</form>
</div>
</div>
Hopefully it will be success for you ;)
here it showing all records from database but it shows all empty div first then below it shows all records .i want to show each record to be shown in single div in rows.
<div id="winnercontainer">
<h2 style="background-color:#9966FF; width:850px; height:30px; font:bold; font- size:22px; color:#FFFFFF; padding-left:20px;">Winners</h2>
<?php
include('pagination/ps_pagination.php');
$conn = mysql_connect('localhost','root','');
if(!$conn) die("Failed to connect to database!");
$status = mysql_select_db('gunjanbid', $conn);
if(!$status) die("Failed to select database!");
$sql = 'SELECT * FROM winners';
$pager = new PS_Pagination($conn, $sql,10, 10);
//The paginate() function returns a mysql result set for the current page
$rs = $pager->paginate();
?>
<table>
<?php
while($row=mysql_fetch_array($rs)){
?>
<div id="winner">
<tr>
<td ><img src="memberpic/myphoto.jpg" width="150" height="150" alt="001" /></td>
<td > </td>
<td ><table >
<tr>
<td >Auction Item : <?php echo $row['Items']; ?></td>
</tr>
<tr>
<td>Rs. <?php echo $row['Rs']; ?></td>
</tr>
<tr>
<td>Winning Bid Value : Rs. <?php echo $row['WinningBidValue']; ?></td>
</tr>
<tr>
<td>MRP : Rs. <?php echo $row['MRP']; ?></td>
</tr>
<tr>
<td>Auction closed on : <?php echo $row['enddate']; ?></td>
</tr>
<tr>
<td>Winner : <?php echo $row['Winner']; ?></td>
</tr>
<tr>
<td>City: <?php echo $row['City']; ?></td>
</tr>
<tr>
<td >Delivery Status: <?php echo $row['DeliveryStatus']; ?></td>
</tr>
</table></td>
<td > </td>
<td id=save><font color=black>SAVED:</font> Rs.<?php echo $row['MRP']- $row['WinningBidValue']; ?></td>
<td > </td>
<td ><img src=productimage/1/1.1.jpg width="200" height="193" alt="001" /></td>
</tr>
</div>
<?php
}
?>
</table>
<?php
//Display the navigation
//echo $pager->renderFullNav();
echo '<div style="text-align:center">'.$pager->renderFullNav().'</div>';
?>
</div>
abd my stylesheet s are
#winnercontainer
{
width:870px;
height:auto;
background-color:#CCCCCC;
border:solid #9966FF;
border-radius:10px;
margin:auto;
clear:both;
margin:10px;
position:relative;
}
#winner
{
width:840px;
height:250px;
background-color: #999999;
border: solid #9966FF;
border-radius:10px;
margin:auto;
clear:both;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
margin-left: 15px;
position:relative;
}
i want all my records to be place in div means each div have one record to be display.plz help me ,i am new here.
I'll give you a start with some old code I have that reads a table from a MySQL database and prints it out on a screen. You can modify it as you see fit. It's a php file that resides on the server.
<?php
echo "<head><title>Read list</title></head>";
$host = "xxxxxxxxxxx";
$user = "xxxxxxxxxxx";
$password = "xxxxxxxxxxx";
$dbname = "xxxxxxxxxxx";
$cxn = mysqli_connect($host,$user,$password,$dbname);
if (mysqli_connect_errno()) {echo "No connection" . mysqli_connect_error();}
$query = " select * from list where uniqueid >= 0 ";
$result = mysqli_query($cxn, $query) or die ("could not query database");
echo "<table cellpadding=1px border=1>";
while ($row = mysqli_fetch_array($result))
{
$uniqueid = $row['uniqueid'];
$localid = $row['localid'];
$mdid = $row['mid'];
$type = $row['type'];
echo "<tr><td>".$uniqueid."</td><td>".$localid."</td><td>".$mdd."</td><td>".$type."</td></tr>";
}
echo "</table>";
?>
In my MySQL database I have table named game with columns: sport_cat, timelive, match_title, selection,
I am exactly this MySQL query SELECT statement for displaying them in grid view on site:
<?
$qry = "
SELECT sport_cat,match_title,selection,
CASE
WHEN game.result LIKE '' THEN 'PENDING'
WHEN game.result LIKE game.selection THEN 'WON'
WHEN game.result NOT LIKE game.selection THEN 'LOST'
END AS result
FROM game
";
$searchText = "";
if($_REQUEST['search_text']!=""){
$searchText = mysql_real_escape_string($_REQUEST['search_text']);
$qry .=" WHERE sport_cat.timelive LIKE '%$searchText%' " .
" OR game.timelive LIKE '%$searchText%' " .
" OR game.match_title LIKE '%$searchText%' ";
}
$qry .= " ORDER BY timelive DESC";
$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;
?>
In first column sport_cat there are few possible text inputs: football, tennis, basketball.
HTML of my file where this part is looks like this:
<table>
<?if(mysql_num_rows($result)!=0){
$counter = $starting + 1;
while($data = mysql_fetch_array($result)) {?>
<tr>
<td align="center"><? echo $data['sport_cat']; ?></td>
<td align="center"><? echo $data['timelive']; ?></td>
<td align="center"><? echo $data['match_title']; ?></td>
<td align="center"><? echo $data['selection']; ?></td>
</tr>
<?
$counter ++;
} ?>
</table>
What I am trying to do is to display specific picture in those cell according to that input in cell. So if there is football want to display football.png picture or if there is tennis want to display tennis.png or if there is basketball want to display basketball.png.
Also, if there is maybe some unknown input like cricket and don't have picture specified for that word would like to display unknown.png picture.
Pictures are stored under images/icons on my server.
Now i'm not sure how to implement this code regarding picturing issue into this already existent i have.
Thanks.
ADDED full example code: 03.11.2011.:
<?php
error_reporting(E_ALL^E_NOTICE);
include('pagination_class.php');
mysql_connect('xxx.xxx.xxx.xx', 'xxxxxx', 'xxxxxxxx') or die(mysql_error());
mysql_select_db('xxxxxxx');
?>
<script language="JavaScript" src="pagination.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
<?
$qry = "
SELECT sport_cat,bidprice,timelive,match_title,selection,winnings_with_startamount,odds,odds*10 AS gainedodds,username,
CASE
WHEN game.result LIKE '' THEN 'pending'
WHEN game.result LIKE game.selection THEN 'WON'
WHEN game.result NOT LIKE game.selection THEN 'LOST'
END AS result
FROM game
";
$searchText = "";
if($_REQUEST['search_text']!=""){
$searchText = mysql_real_escape_string($_REQUEST['search_text']);
$qry .=" WHERE game.sport_cat LIKE '%$searchText%' " .
" OR game.timelive LIKE '%$searchText%' " .
" OR game.match_title LIKE '%$searchText%' " .
" OR game.selection LIKE '%$searchText%' " .
" OR game.username LIKE '%$searchText%'";
}
$qry .= " ORDER BY timelive DESC";
//for pagination
$starting=0;
$recpage = 10;//number of records per page
$obj = new pagination_class($qry,$starting,$recpage);
$result = $obj->result;
function getStyleColorForStatus($status) {
if ($status == 'WON') {
return '#99ff99';
}
else if ($status == 'LOST') {
return '#ff9999';
}
else if ($status == 'pending') {
return '#e5e5e5';
}
return '';
}
?>
<form name="form1" action="testpage.php" method="POST" style="background-color:#f9f9f9; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1);">
<table border="0" align="center" width="1000px" padding-left="0px" style="background:#F9F9F9;">
<TD colspan="0" style="padding-left:0px; padding-bottom:5px; padding-top:10px; text-align:center;">
Search: <input type="text" name="search_text" value="<?php echo $searchText; ?>">
<input type="submit" value="Search">
</TD>
<tr><TD colspan="0">
<div id="page_contents">
<table width="968px" cellspacing="0" cellpadding="5" align="center" frame="box" rules="none" style="padding-bottom:20px; margin-bottom:8px;margin-top:3px; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1); border: 1px solid #cccccc;">
<tr style="height: 50px;">
<td width="10%" align="center" td class="winheader"><div class="glowtext">Event Category</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Bid Cost</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Event Start Time</div></td></td>
<td width="35%" align="center" td class="winheader"><div class="glowtext">Market/Event</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Selection</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winnings</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Odds</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Gained Odds</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winning Bidder</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Final Result</div></td></td>
</tr>
<?
if(mysql_num_rows($result)!=0){
$counter = $starting + 1;
$pathImg = "/images/icons/";
while($data = mysql_fetch_array($result)) {
//calculate url image
$pathFile = $pathImg . $data['sport_cat'] . ".png";
if (!file_exists($pathFile)) {
$pathFile = $pathImg . "unknown.png";
}
?>
<tr class="initial" onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">
<td align="center"><img src="<?=$pathFile?>" alt="<?=$data['sport_cat']?>"></TD>
<td align="center"><? echo $data['bidprice']; ?></TD>
<td align="center"><? echo $data['timelive']; ?></TD>
<td align="left"><? echo $data['match_title']; ?></TD>
<td align="left"><? echo $data['selection']; ?></TD>
<td align="center"><font color="green">€ <? echo $data['winnings_with_startamount']; ?></TD>
<td align="center"><? echo $data['odds']; ?></TD>
<td align="center"><? echo $data['gainedodds']; ?></TD>
<td align="center"><? echo $data['username']; ?></TD>
<td align="center" style="background-color:<?php echo getStyleColorForStatus($data['result']); ?>"><? echo $data['result']; ?></td>
</tr>
<?
$counter ++;
}
}
?>
<tr><TD align="center" colspan="10" style="padding-bottom:1px; padding-top:10px; color:#333;"><? echo $obj->anchors; ?></TD></tr>
<tr><TD align="center" colspan="10" style="padding-bottom:10px; padding-top:5px; color:#333;"><? echo $obj->total; ?></TD></tr>
<?}else{?>
<tr><TD align="center" colspan="10" style="padding-bottom:10px padding-top:10px; color:red;">No Data Found</TD></tr>
<?}?>
</TD></tr>
</table>
</div>
</tr>
</TD>
</form>
</table>
try this:
$sql = "SELECT * FROM game";
$result = mysql_query($sql) or die(mysql_error());
$pathImg = "/images/icons/";
while ($row = mysql_fetch_array($result)) {
$pathFile = $pathImg . $row['sport_cat'] . ".png";
if (!file_exists($pathFile)) {
$pathFile = $pathImg . "unknown.png";
}
echo '<img src="' . $pathFile . '">';
}
You edit Ask and I edit Anwer :P
<table>
<?
if (mysql_num_rows($result) != 0) {
$counter = $starting + 1;
$pathImg = "/images/icons/";
while ($data = mysql_fetch_array($result)) {
//calculate url image
$pathFile = $pathImg . $data['sport_cat'] . ".png";
if (!file_exists($pathFile)) {
$pathFile = $pathImg . "unknown.png";
}
?>
<tr>
<td align="center"><img src="<?=$pathFile?>" alt="<?=$data['sport_cat']?>"></td>
<td align="center"><? echo $data['sport_cat']; ?></td>
<td align="center"><? echo $data['timelive']; ?></td>
<td align="center"><? echo $data['match_title']; ?></td>
<td align="center"><? echo $data['selection']; ?></td>
</tr>
<?
$counter++;
}
}
?>
</table>
Something like the following should work.
<?php
$sql = "SELECT * FROM game";
$result = mysql_query($sql)or die(mysql_error());
while ($row = mysql_fetch_array($result)){
// Show images
if($row['sport_cat']=='football'){
print "<img src='football.png'/>";
}
elseif($row['sport_cat']=='basketball'){
print "<img src='basketball.png'/>";
}
elseif($row['sport_cat']=='tennis'){
print "<img src='tennis.png'/>";
}else{
print "<img src='unknown.png' />";
}
} // End while loop
?>