I have following do while loop be it keep on repeating the table for each record how to fix it? full table repeat for each record.
Also for every row fetch can I add
<table width="1510" border="1" align="center" cellpadding="2" cellspacing="2" class="table table-bordered" >
<tbody>
<form name="f1">
<? $counter = 1;
$total_marks = 0;
$total_obtain = 0;
while($row_rsDept = mysql_fetch_array($rsDept))
{
if($counter === 1)
{
?>
<tr>
<th width="71" rowspan="3" align="center" valign="middle" scope="col"><h4>Sr. No</h4></th>
<th width="229" align="right" valign="top" scope="col"> </th>
<th colspan="8" align="center" valign="middle" scope="col"><h3>Detail of Marks</h3></th>
</tr>
<tr>
<th rowspan="2" align="left" scope="row"><h4>Subject</h4></th>
<td colspan="2" align="center"><h4>Thoery</h4></td>
<td colspan="2" align="center"><h4>Practical</h4></td>
<td width="134" rowspan="2" align="center" valign="middle"><h4>Marks Obtain</h4></td>
<td width="144" rowspan="2" align="center" valign="middle"><h4>Max Marks</h4></td>
<td width="137" rowspan="2" align="center" valign="middle"><h4>Remarks</h4></td>
<td width="137" rowspan="2" align="center" valign="middle"><h4>Grace Marks</h4></td>
</tr>
<tr>
<td width="134">Obtained Marks</td>
<td width="144">Total Marks</td>
<td width="143">Obtained Marks</td>
<td width="153">Total Marks</td>
</tr>
<? } ?>
<tr>
<th align="left" scope="row"> </th>
<th align="left" scope="row"><?php echo $row_rsDept['SUBJECTS']; ?></th>
<td><?php echo $row_rsDept['THEORYOBTAINEDMARKS']; ?></td>
<td><?php echo $row_rsDept['THEORYTOTALMARKS']; ?></td>
<td><?php echo $row_rsDept['PRACTICALOBATINEDMARKS']; ?></td>
<td><?php echo $row_rsDept['PRACTICALTOTALMARKS']; ?></td>
<td align="center" valign="middle"><?php echo $row_rsDept['MARKSOBTAINED']; ?></td>
<td align="center" valign="middle"><?php echo $row_rsDept['MAXMARKS']; ?></td>
<td align="center" valign="middle"><span class="style8"><?php echo $row_rsDept['REMARKS']; ?></span></td>
<td align="center" valign="middle"><?php echo $row_rsDept['GRACEMARKS']; ?></td>
</tr>
<tr>
<th colspan="6" align="right" valign="middle" scope="row"><h4>Total</h4></th>
<td align="center" valign="middle"><span class="style8"><?php echo $row_rsDept['TOTALMARKS']; ?></span></td>
<td align="center" valign="middle">=total of above ( )</td>
<td align="center" valign="middle"> </td>
<td align="center" valign="middle"> </td>
</tr>
<?php
} ?>
<tr>
<th colspan="10" align="left" valign="middle" scope="row"> </th>
</tr>
<tr>
<th colspan="8" align="left" valign="middle" scope="row"> </th>
<th align="left" valign="middle" scope="row"> </th>
<th align="left" valign="middle" scope="row"> </th>
</tr>
<tr>
<th colspan="8" align="left" valign="middle" scope="row"><br></th>
<th align="left" valign="middle" scope="row"> </th>
<th align="left" valign="middle" scope="row"> </th>
</tr>
</form>
</table>
I tried to fix but not working for me
Inside loop you need to increment counter variable
Inside loop add this line
$counter++;
Related
How to get data and set in to php var when use file_get_contents PHP ?
this is code for http://www.example.com/test.php
<table align="center">
<thead style="background-color: #F0F0F0; color: #333333; text-align: center;">
<tr>
<th class="countryHeader">Country</th>
<th class="intHeader"> </th>
<th colspan="2" class="intHeader">Desktop CPM</th>
<th colspan="2" class="bannerHeader">Mobile CPM</th>
</tr>
</thead>
<tbody>
<tr class="breaker">
<td> </td>
<td>Highest</td>
<td>Unique</td>
<td>Raw</td>
<td>Unique</td>
<td>Raw</td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United States</td>
<td class="cpmRaw">$2.00</td>
<td class="cpm">$3.44</td>
<td class="cpmRaw">$2.00</td>
<td class="cpmMobile">$1.63</td>
<td class="cpmMobileRaw">$0.97</td>
</tr>
<tr class="even rateVals">
<td class="countryName">Canada</td>
<td class="cpmRaw">$1.20</td>
<td class="cpm">$2.52</td>
<td class="cpmRaw">$1.20</td>
<td class="cpmMobile">$1.88</td>
<td class="cpmMobileRaw">$1.06</td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United Kingdom</td>
<td class="cpmRaw">$1.60</td>
<td class="cpm">$2.10</td>
<td class="cpmRaw">$1.08</td>
<td class="cpmMobile">$1.71</td>
<td class="cpmMobileRaw">$0.94</td>
</tr>
<tr class="even rateVals">
<td class="countryName">Australia</td>
<td class="cpmRaw">$1.50</td>
<td class="cpm">$2.62</td>
<td class="cpmRaw">$1.20</td>
<td class="cpmMobile">$2.73</td>
<td class="cpmMobileRaw">$1.49</td>
</tr>
<tr class="breaker">
<td colspan="6"> </td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United Arab Emirates</td>
<td class="cpmRaw">$1.48</td>
<td class="cpm">$2.49</td>
<td class="cpmRaw">$1.45</td>
<td class="cpmMobile">$2.11</td>
<td class="cpmMobileRaw">$1.42</td>
</tr>
<tr class="odd rateVals">
<td>All other countries</td>
<td>-</td>
<td colspan="2">$0.25 - $2.00</td>
<td colspan="2">$0.06 - $0.22</td>
</tr>
</tbody>
</table>
And this is code for my_code.php
<?php
$test = file_get_contents('http://www.example.com/test.php');
//echo $test;
?>
And i want to get php var from column Mobile CPM raw value like this
$United_States = "0.97";
$Canada = "1.07";
$United_Kingdom = "0.94";
$Australia = "1.49";
$United_Arab_Emirates = "1.42";
How can i do ?
If you want to parse a HTML document you should use PHP's DOMDocument. Instead of file_get_contents() you should use loadHTMLFile(). Because you are using CSS-classes you should view this post on how to find elements via class.
i have a problem to create table like this image in website, can anyone help me to solve that?. blue line in picture. i just don't know how to create table like this image. especially reference no, it has custom border line.
Here is table design
you can check my code here too MY CODE
this is my code
<html xmlns="http://www.w3.org/1999/ifxhtml">
<head profile="http://www.w3.org/2005/10/profile">
<title>Glisten - A free web template</title>
</head>
<body>
<table width="800" border="1" align="center">
<tbody>
<tr>
<td colspan="2" align="center" bgcolor=""><table width="800" border="1" align="center">
<tbody>
<tr>
<td width="125">Reference No</td>
<td colspan="4"> </td>
<td colspan="2" bgcolor="#8B8A8A" align="center"></td>
</tr>
<tr>
<td align="center" bgcolor="#FF0004"><strong>NG TINEM</strong></td>
</tr>
<tr>
<td>Site ID</td>
<td colspan="3" align="center"></td>
<td width="185">BSC Name</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Site Name</td>
<td colspan="3" align="center"></td>
<td>New Site ID</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Sales Cluster</td>
<td colspan="3" align="center"></td>
<td>LAC</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Ne Type</td>
<td colspan="3" align="center"></td>
<td>Config</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Band</td>
<td colspan="3" align="center"></td>
<td>PO Number</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Cell ID</td>
<td width="80" align="center"></td>
<td width="82" align="center"></td>
<td width="80" align="center"></td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="7" > </td>
</tr>
<tr>
<td align="center">Integration Date</td>
<td align="center"></td>
<td align="center">On Air Date</td>
<td align="center"></td>
<td align="center">Acceptance Date</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
</tbody>
</table>
</body></html>
First identify the total columns to be created.
Then use attribute of table like "colspan" to span the columns.
Add following style to your table (I have added class table in your second table tag):
<style type="text/css">
.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th
{
padding: 8px;
line-height: 1.42857143;
vertical-align: top;
}
table {
border-collapse: collapse;
border-spacing: 0;
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
}
</style>
<table width="800" align="center">
<tbody>
<tr>
<td colspan="2" align="center" bgcolor=""><table class="table" width="800" border="1" align="center">
<tbody>
<?php
while($data = mysql_fetch_array($query)){
if($data['dt_report']=='Yes'){
$check_dt_report='checked="checked"';
}
else{
$check_dt_report='';
}if($data['kpi_stats']=='Yes'){
$check_kpi_stats='checked="checked"';
}
else{
$check_kpi_stats='';
}
if($data['clear_alarm']=='Yes'){
$check_clear_alarm='checked="checked"';
}
else{
$check_clear_alarm='';
}
if($data['configuration']=='Yes'){
$check_configuration='checked="checked"';
}
else{
$check_configuration='';
}
if($data['neighbor']=='Yes'){
$check_neighbor='checked="checked"';
}
else{
$check_neighbor='';
}
?>
<tr>
<td width="125">Reference No</td>
<td colspan="4"> </td>
<td colspan="2" bgcolor="#8B8A8A" align="center"><?php echo $data['no_ref']; ?></td>
</tr>
<tr>
<td align="center" bgcolor="#FF0004"><strong>NG TINEM</strong></td>
</tr>
<tr>
<td>Site ID</td>
<td colspan="3" align="center"><?php echo $data['site_id']; ?></td>
<td width="185">BSC Name</td>
<td colspan="2" align="center"><?php echo $data['bsc_name']; ?></td>
</tr>
<tr>
<td>Site Name</td>
<td colspan="3" align="center"><?php echo $data['site_name']; ?></td>
<td>New Site ID</td>
<td colspan="2" align="center"><?php echo $data['new_site_id']; ?></td>
</tr>
<tr>
<td>Sales Cluster</td>
<td colspan="3" align="center"><?php echo $data['sales_cluster']; ?></td>
<td>LAC</td>
<td colspan="2" align="center"><?php echo $data['lac']; ?></td>
</tr>
<tr>
<td>Ne Type</td>
<td colspan="3" align="center"><?php echo $data['ne_type']; ?></td>
<td>Config</td>
<td colspan="2" align="center"><?php echo $data['config']; ?></td>
</tr>
<tr>
<td>Band</td>
<td colspan="3" align="center"><?php echo $data['band']; ?></td>
<td>PO Number</td>
<td colspan="2" align="center"><?php echo $data['po_number']; ?></td>
</tr>
<tr>
<td>Cell ID</td>
<td width="80" align="center"><?php echo $data['cell_id1']; ?></td>
<td width="82" align="center"><?php echo $data['cell_id2']; ?></td>
<td width="80" align="center"><?php echo $data['cell_id3']; ?></td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="7" > </td>
</tr>
</tbody>
</table>
PHP newbie here! I ve been struggling with this for a few days now and i have decided i cant figure this out on my own.
Basically i have 2 database tables "projects_2016" and "attachment".
I want to show the data of "projects_2016" to show in the top table and then check for a matching id number (and if it exsits) in "attachment" it will list all the results under the "project_2016 data".
At the moment it works great but it duplicates the "projects_2016" data for every "attachment" entry.
Here is my code, any input is appreciated!
PS not too concereded about Sql injections. Still learning that!
<?php include '../../../connection_config.php';
$sql = "SELECT DISTINCT * FROM attachment JOIN projects_2016 ON attachment.attachment_ABE_project_number = projects_2016.id ORDER BY `attachment_ABE_project_number` DESC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<table width="20" border="1" cellspacing="0" cellpadding="2">
<tr>
<th height="0" scope="col"><table width="990" border="0" align= "center" cellpadding="3" cellspacing="0">
<tr class="text_report">
<td width="107" height="30" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>PNo</strong></td>
<td width="871" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>Project Name</strong></td>
</tr>
<tr>
<td height="20" align="left" valign="middle" bgcolor="#FFFFFF" class="text_report"><strong><?php echo "<br>". $row["ID"]. "<br>";?></strong></td>
<td height="20" align="left" valign="middle" bgcolor= "#FFFFFF" class="text_report"><strong><?php echo "<br>". $row["project_name"]. "<br>";?></strong></td>
</tr>
</table>
<?php
$photo_id = $row["ID"];
$contacts = "SELECT DISTINCT * FROM attachment WHERE attachment_ABE_project_number = '$photo_id'" ;
$result_contacts = $conn->query($contacts);
if ($result_contacts->num_rows > 0) {
// output data of each row
while($row_contacts = $result_contacts->fetch_assoc()) {
?>
<table width="990" border="0" align="center" cellpadding= "3" cellspacing="0" class="text_report">
<tr>
<td height="0" colspan="4" align="left" valign="middle" nowrap="nowrap" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td width="319" height="30" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>File Name</strong></td>
<td width="279" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>File Type</strong></td>
<td width="315" align="left" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>File Size (KB)</strong></td>
<td width="53" align="right" valign="middle" nowrap="nowrap" bgcolor="#F5F5F5"><strong>View File</strong></td>
</tr>
<tr>
<td height="20" align="left" valign="middle" bgcolor="#FFFFFF"><?php echo $row_contacts ['file'] ?></td>
<td height="20" align="left" valign="middle" bgcolor="#FFFFFF"><?php echo $row_contacts ['type'] ?></td>
<td height="20" align="left" valign="middle" bgcolor="#FFFFFF"><?php echo $row_contacts ['size'] ?></td>
<td align="right" valign="middle" bgcolor="#FFFFFF">view file</td>
</tr>
<tr>
<td height="0" colspan="4" align="left" valign="middle" bgcolor="#FFFFFF"> </td>
</tr>
<?php
}
?>
</table>
<?php
}
?></th>
</tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="26"> </th>
</tr>
</table>
<p>
<?php
}
}
?>
</p>
</table>
<?php $conn->close();
?>
$sql = "SELECT * FROM projects_2016
WHERE EXISTS (SELECT * FROM attachment WHERE projects_2016.id = attachment_ABE_project_number) ORDER BY id DESC ";
I am trying to display a row of data from my main table (parents details) and then under each of those rows display the children's names from another table. I have had a go using the following code:
$sql="select distinct members_main.first_name as main_firstname,
members_main.first_name as main_firstname,
members_main.last_name as main_lastname,
members_main.address_1 as main_address_1,
members_main.address_2 as main_address_2,
members_main.address_3 as main_address_3,
members_main.address_4 as main_address_4,
members_main.post_code as main_post_code,
members_main.home_tel as main_home_tel,
members_main.mobile as main_mobile,
members_main.home_email as main_home_email
from members_main, members_family where members_main.contact_id=members_family.contact_id";
$sql2="select members_family.first_name as fam_firstname,
members_family.last_name as fam_lastname
from members_family, members_main
where members_main.contact_id=members_family.contact_id";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
echo '<table width="100%" cellpadding="3" cellspacing="0">
<tr>
<th align="left" valign="top">First Name</th>
<th align="left" valign="top">Last Name</th>
<th align="left" valign="top">Address 1</th>
<th align="left" valign="top">Address 2</th>
<th align="left" valign="top">Address 3</th>
<th align="left" valign="top">Address 4</th>
<th align="left" valign="top">Post Code</th>
<th align="left" valign="top">Home Tel</th>
<th align="left" valign="top">Mobile</th>
<th align="left" valign="top">Email</th>
</tr>';
echo '<tr>
<td valign="top">'.$rows['main_firstname'].'</td>
<td valign="top">'.$rows['main_lastname'].'</td>
<td valign="top">'.$rows['main_address_1'].'</td>
<td valign="top">'.$rows['main_address_2'].'</td>
<td valign="top">'.$rows['main_address_3'].'</td>
<td valign="top">'.$rows['main_address_4'].'</td>
<td valign="top">'.$rows['main_post_code'].'</td>
<td valign="top">'.$rows['main_home_tel'].'</td>
<td valign="top">'.$rows['main_mobile'].'</td>
<td valign="top">'.$rows['main_home_email'].'</td>
</tr>';
$result2=mysql_query($sql2);
echo '<table width="100%" cellpadding="3" cellspacing="0">
<tr>
<th align="left" valign="top">First Name</th>
<th align="left" valign="top">Last Name</th>
</tr>';
while($rows=mysql_fetch_array($result2)){
echo '<tr>
<td valign="top">'.$rows['fam_firstname'].'</td>
<td valign="top">'.$rows['fam_lastname'].'</td>
</tr>';
}
}
echo "</table>";
I am getting all rows from the members_family table per each record from the members_main. There can be more than one record in the members_family which will be associated to one record in the members_main. Bascially, members_main (parent) can have multiple children in the members_main.
I think you just need to retrieve your members_main.contact_id from first table to use later in second while loop. Then you will have to move your second query inside first query while loop so the code will look like that:
$sql="select distinct
members_main.contact_id as ID,
members_main.first_name as main_firstname,
members_main.first_name as main_firstname,
members_main.last_name as main_lastname,
members_main.address_1 as main_address_1,
members_main.address_2 as main_address_2,
members_main.address_3 as main_address_3,
members_main.address_4 as main_address_4,
members_main.post_code as main_post_code,
members_main.home_tel as main_home_tel,
members_main.mobile as main_mobile,
members_main.home_email as main_home_email
from members_main, members_family where members_main.contact_id=members_family.contact_id";
$result = mysql_query($sql);
while($rows=mysql_fetch_array($result)) {
//script goes on with table printing untill
<td valign="top">'.$rows['main_home_email'].'</td>
</tr>';
Now it's time for the query
$sql2="select members_family.first_name as fam_firstname,
members_family.last_name as fam_lastname
from members_family, members_main
where members_main.contact_id=members_family.contact_id and members_main.contact_id = '".$rows['ID']."'";
As you see i added in WHERE condition to limit result for specified ID wich i retrieved from first query. Now you can print the rest of the table. Oh and by the way you closing table should look like that
echo "</table></td></tr></table>";
This is because you opened two tables.
Then I would like you to remember that mysql_* functions are deprecated so i would advise you to switch to mysqli or PDO
I feel some confusion with your second query. I am thinking that you have to construct your second query with the contact_id which is coming from first query(members_main). I assumes in that way and i have coded below. May be it will help you
<?php
$sql = "select distinct members_main.first_name as main_firstname,
members_main.first_name as main_firstname,
members_main.last_name as main_lastname,
members_main.address_1 as main_address_1,
members_main.address_2 as main_address_2,
members_main.address_3 as main_address_3,
members_main.address_4 as main_address_4,
members_main.post_code as main_post_code,
members_main.home_tel as main_home_tel,
members_main.mobile as main_mobile,
members_main.home_email as main_home_email
from members_main, members_family where members_main.contact_id=members_family.contact_id";
$result = mysql_query($sql);
?>
<table width="100%" cellpadding="3" cellspacing="0">
<tr>
<th align="left" valign="top">First Name</th>
<th align="left" valign="top">Last Name</th>
<th align="left" valign="top">Address 1</th>
<th align="left" valign="top">Address 2</th>
<th align="left" valign="top">Address 3</th>
<th align="left" valign="top">Address 4</th>
<th align="left" valign="top">Post Code</th>
<th align="left" valign="top">Home Tel</th>
<th align="left" valign="top">Mobile</th>
<th align="left" valign="top">Email</th>
</tr>
<?php
while ($rows = mysql_fetch_array($result))
{
$conId = $rows['contact_id']; //Which is comming from first Query
$sql2 = "select members_family.first_name as fam_firstname,
members_family.last_name as fam_lastname
from members_family, members_main
where members_family.contact_id=$conId";
$result2 = mysql_query($sql2);
?>
<tr>
<td valign="top"><?= $rows['main_firstname']; ?></td>
<td valign="top"><?= $rows['main_lastname']; ?></td>
<td valign="top"><?= $rows['main_address_1']; ?></td>
<td valign="top"><?= $rows['main_address_2']; ?></td>
<td valign="top"><?= $rows['main_address_3']; ?></td>
<td valign="top"><?= $rows['main_address_4']; ?></td>
<td valign="top"><?= $rows['main_post_code']; ?></td>
<td valign="top"><?= $rows['main_home_tel']; ?></td>
<td valign="top"><?= $rows['main_mobile']; ?></td>
<td valign="top"><?= $rows['main_home_email']; ?></td>
</tr>
<tr>
<td colspan="10">
<table width="100%" cellpadding="3" cellspacing="0">
<tr>
<th align="left" valign="top">First Name</th>
<th align="left" valign="top">Last Name</th>
</tr>
<?php
while ($rowsFamily = mysql_fetch_array($result2))
{
?>
<tr>
<td valign="top"><?= $rowsFamily['fam_firstname']; ?></td>
<td valign="top"><?= $rowsFamily['fam_lastname']; ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
?>
</table>
I'm trying to find a way of displaying an else or if statement in this code so that if the record/value doesn't exist in the mysql table then it will echo a piece of text like 'ask me'.
heres the code:
<?php
$rates_set = get_rates();
while ($rates = mysql_fetch_array($rates_set)) {
?>
<table width="110%" border="0" cellspacing="5" cellpadding="5">
<tr>
<th align="left" valign="middle" bgcolor="#EBEBEB" scope="col">Rates</th>
<th align="center" valign="middle" bgcolor="#EBEBEB" scope="col">money in</th>
<th align="center" valign="middle" bgcolor="#EBEBEB" scope="col">money Out</th>
</tr>
<tr>
<th align="left" valign="middle" bgcolor="#EBEBEB" scope="row">cost</th>
<td align="center" valign="middle">£<?php echo "{$rates['labour']} "; ?></td>
<td align="center" valign="middle">£<?php echo "{$rates['material']}"; ?></td>
</tr>
<tr>
<th align="left" valign="middle" bgcolor="#EBEBEB" scope="row">cost/th>
<td align="center" valign="middle">£<?php echo "{$rates['money']}"; ?></td>
<td align="center" valign="middle">£<?php echo "{$rates['expense']}"; ?></td>
</tr>
<tr>
<th align="left" valign="middle" bgcolor="#EBEBEB" scope="row">Overnight</th>
<td align="center" valign="middle">£<?php echo "{$rates['charges']}"; ?></td>
<td align="center" valign="middle">£<?php echo "{$rates['fees']}"; ?></td>
</tr>
</table>
<?php } ?>
hope someone can help. thank you.
Try this,
<?php echo isset($rates['fees'])?"{$rates['fees']}":"ask me"; ?>
You can loop through the values in the $rates array and if empty, assign a default:
$rates_set = get_rates();
while ($rates = mysql_fetch_array($rates_set)) {
// Set defaults
foreach($rates as $key => $value)
{
if(strlen(trim($value)) == 0)
{
// Assign default
$rates[$key] = 'Ask Me';
}
}
?>
There is some tweaking to be done with this method, such as how you determine a value is "empty"...but essentially, this will get the job done.
The other option is to handle it locally within the markup using the ternary operator:
<td align="center" valign="middle">£
<?php isset($rates['money']) ? $rates['money'] : 'Ask Me'; ?>
</td>
<?php
/* Use This */
$rates_set = get_rates();
if (mysql_num_rows($rates_set)>0) {
while ($rates = mysql_fetch_array($rates_set)) {
?>
<table width="110%" border="0" cellspacing="5" cellpadding="5">
<tr>
<th align="left" valign="middle" bgcolor="#EBEBEB" scope="col">Rates</th>
<th align="center" valign="middle" bgcolor="#EBEBEB" scope="col">money in</th>
<th align="center" valign="middle" bgcolor="#EBEBEB" scope="col">money Out</th>
</tr>
<tr>
<th align="left" valign="middle" bgcolor="#EBEBEB" scope="row">cost</th>
<td align="center" valign="middle">£<?php echo "{$rates['labour']} "; ?></td>
<td align="center" valign="middle">£<?php echo "{$rates['material']}"; ?></td>
</tr>
<tr>
<th align="left" valign="middle" bgcolor="#EBEBEB" scope="row">cost/th>
<td align="center" valign="middle">£<?php echo "{$rates['money']}"; ?></td>
<td align="center" valign="middle">£<?php echo "{$rates['expense']}"; ?></td>
</tr>
<tr>
<th align="left" valign="middle" bgcolor="#EBEBEB" scope="row">Overnight</th>
<td align="center" valign="middle">£<?php echo "{$rates['charges']}"; ?></td>
<td align="center" valign="middle">£<?php echo "{$rates['fees']}"; ?></td>
</tr>
</table>
<?php }
} else {
echo 'Ask me';
}
?>
You can use this
<?php
$rates_set = get_rates();
if(mysql_num_rows($rates_set)<1) {
echo "Ask me";
}else{
while ($rates = mysql_fetch_array($rates_set)) {
//your code
}
}
<?php echo ( (!empty($rates['labour'])) ? $rates['labour'] : 'Default Text'); ?>
Is that what you are looking for?
Edit:
Alter the top of the loop like this:
while ($rates = mysql_fetch_array($rates_set)) {
if (empty($rates_set)) continue;