Page 1 of 1
Data repeating problem
Posted: Mon Feb 18, 2008 4:28 am
by samani
hi,
i'm retrieving data from mysql DB.
while($row = mysql_fetch_array($result))
{
$details1['name'] = $row['st_title'];
$details2['service level'] = $row['service_level_value'];
$details['symbol'] = $row['currency_html'];
$details3['charge'] = $row['service_charge'];
echo $details1['name'] ;
echo $details2['service level'];
echo $details['symbol'];
echo $details3['charge'];
}
My problem is $details1['name'] this field is containing repeating data...........
how to remove repeating data and display other data.
Re: Data repeating problem
Posted: Mon Feb 18, 2008 4:36 am
by Benjamin
Without knowing more details my guess is to use the DISTINCT keyword in your MySQL query.
Re: Data repeating problem
Posted: Mon Feb 18, 2008 4:40 am
by samani
that's not working ................ i want to dispaly the same name one time and want to echo othe details.
(for one name there are many levels so i want to echo name one time and under that all other data)
Re: Data repeating problem
Posted: Mon Feb 18, 2008 4:42 am
by Benjamin
Ok. Go ahead and post what you have got done so far. We may need to rearrange your code a bit. Be sure to use the
Re: Data repeating problem
Posted: Mon Feb 18, 2008 4:48 am
by samani
ok. this is my code;
//open the database connection
$link = open_connection
(ADMIN_DB_HOST, ADMIN_DB_USER_NAME, ADMIN_DB_PASSWORD , ADMIN_DB_NAME );
$sql = "SELECT service_type.st_title, service.service_level_value, currency.currency_html, service.service_charge
FROM service , service_type , currency WHERE service.currency_code = '@currency_code' AND
service.default_service = 'YES' AND
service.st_id = service_type.st_id AND currency.currency_code = '@currency_code'";
$param_array =array('@currency_code' => $currency_code);
$sql = generate_safe_sql($sql,$param_array);
$result = execute_query($sql,$link);
$rowc = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
$details1['name'] = $row['st_title'];
$details2['service level'] = $row['service_level_value'];
$details['symbol'] = $row['currency_html'];
$details3['charge'] = $row['service_charge'];
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td width='83%'>";
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td width='150'>";
echo "<strong>";
echo "<font color='#FF3399' size='2' face='Arial, Helvetica, sans-serif'>";
echo $details1['name'] ;
echo "</font></strong>";
echo "</td>";
echo "<td>";
echo "<strong>";
echo "<font color='#FF3399' size='2' face='Arial, Helvetica, sans-serif'>";
echo $details2['service level'] ;
echo "hrs"; echo "</font></strong>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "<td width='17%'>";
echo "<strong>";
echo "<font color='#FF3399' size='2' face='Arial, Helvetica, sans-serif'>";
echo $details['symbol'], "*" ;
echo $details3['charge'] ;
echo "</font>";
echo "<font color='#ec008c'></font><font color='#FF3399' size='2' face='Arial, Helvetica, sans-serif'>*";
echo "</font>";
echo "</strong>";
echo "</td> ";
echo "</tr>";
echo "</table>";
}
i want to echo name, service_level, 'symbol', 'currency_html', charge value.
under one name there are many other records, i want to echo one name in one tme (not to repeat same name)
thanks
Re: Data repeating problem
Posted: Mon Feb 18, 2008 4:58 am
by Benjamin
If this mangles your html I'm sorry but I didn't really pay attention to the html portion. This should get you over the hump.
Code: Select all
//open the database connection
$link = open_connection
(ADMIN_DB_HOST, ADMIN_DB_USER_NAME, ADMIN_DB_PASSWORD , ADMIN_DB_NAME );
$sql = "SELECT service_type.st_title, service.service_level_value, currency.currency_html, service.service_charge
FROM service , service_type , currency WHERE service.currency_code = '@currency_code' AND
service.default_service = 'YES' AND
service.st_id = service_type.st_id AND currency.currency_code = '@currency_code'";
$param_array =array('@currency_code' => $currency_code);
$sql = generate_safe_sql($sql,$param_array);
$result = execute_query($sql,$link);
$rowc = mysql_num_rows($result);
$records = array();
while($row = mysql_fetch_array($result))
{
$records[$row['st_title']][] = $row;
}
foreach ($records as $details1 => $items)
{
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td width='83%'>";
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td width='150'>";
echo "<strong>";
echo "<font color='#FF3399' size='2' face='Arial, Helvetica, sans-serif'>";
echo $details1;
echo "</font></strong>";
echo "</td>";
foreach ($items as $item)
{
$details2['service level'] = $item['service_level_value'];
$details['symbol'] = $item['currency_html'];
$details3['charge'] = $item['service_charge'];
echo "<td>";
echo "<strong>";
echo "<font color='#FF3399' size='2' face='Arial, Helvetica, sans-serif'>";
echo $details2['service level'] ;
echo "hrs"; echo "</font></strong>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "<td width='17%'>";
echo "<strong>";
echo "<font color='#FF3399' size='2' face='Arial, Helvetica, sans-serif'>";
echo $details['symbol'], "*" ;
echo $details3['charge'] ;
echo "</font>";
echo "<font color='#ec008c'></font><font color='#FF3399' size='2' face='Arial, Helvetica, sans-serif'>*";
echo "</font>";
echo "</strong>";
echo "</td> ";
}
echo "</tr>";
echo "</table>";
}
Re: Data repeating problem
Posted: Mon Feb 18, 2008 5:01 am
by samani
Thanks a lot ! it's working........ !