Data repeating problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
samani
Forum Newbie
Posts: 5
Joined: Mon Feb 18, 2008 4:20 am

Data repeating problem

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Data repeating problem

Post by Benjamin »

Without knowing more details my guess is to use the DISTINCT keyword in your MySQL query.
samani
Forum Newbie
Posts: 5
Joined: Mon Feb 18, 2008 4:20 am

Re: Data repeating problem

Post 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)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Data repeating problem

Post 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

Code: Select all

tags.
samani
Forum Newbie
Posts: 5
Joined: Mon Feb 18, 2008 4:20 am

Re: Data repeating problem

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Data repeating problem

Post 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>";
}
 
samani
Forum Newbie
Posts: 5
Joined: Mon Feb 18, 2008 4:20 am

Re: Data repeating problem

Post by samani »

Thanks a lot ! it's working........ !
Post Reply