Here is the page:

<?php

include( "mypath.php" );
include( "{$filepath}/config/clientdbconnect.php" );
if ( ------------------------- )
{
    #exit( "Security Violation" );
}
include( "header.php" );

$sqle = "select * from helpconfig where cid = '1'";
if ( !( $resulte = mysql_query( $sqle ) ) )
{
    exit( mysql_error( ) );
}
while ( $rowe = mysql_fetch_array( $resulte ) )
{
    $ticketlimit = $rowe['ticketlimit'];
    $ticketdlimit = $rowe['ticketdlimit'];
    $flash = $rowe['flash'];
}
$interface = grab_template( "support_center_head.html", $cusid );
$sqle = "select * from helpconfig where cid = '1'";
if ( !( $resulte = mysql_query( $sqle ) ) )
{
    exit( mysql_error( ) );
}
while ( $rowe = mysql_fetch_array( $resulte ) )
{
    $chaturl = $rowe['chaturl'];
}
if ( $chaturl )
{
    $chaturl = str_replace( "{username}", $username, $chaturl );
    $chaturl = str_replace( "{password}", $password, $chaturl );
    $interface = str_replace( "javascript: openwindow('chat.php');", "{$chaturl}", $interface );
}
if ( $flash != "Y" )
{
    $interface = str_replace( "<img src=\"".$url."/templates/skin/button_flashtut.gif\" width=\"144\" height=\"35\" border=\"0\">", "", $interface );
}
echo $interface;

$sqle = "select * from helpconfig where cid = '1'";
if ( !( $resulte = mysql_query( $sqle ) ) )
{
    exit( mysql_error( ) );
}
while ( $rowe = mysql_fetch_array( $resulte ) )
{
    $supporturl = $rowe['supporturl'];
    $chaturl = $rowe['chaturl'];

    echo "<table width=\"95%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing= \"0\">\n        <tr>\n          <td> </td>\n          <td valign=\"top\"><div align= \"left\">\n              <table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding= \"0\">\n                <tr>\n                  <td width=\"5%\"><img src=\"../images/view- statistics.gif\" width=\"26\" height=\"20\"> </td>\n                  <td width=\"95% \">  <strong>My Help Requests</strong></td>\n                </tr>\n               </table>\n          </div></td>\n          <td> </td>\n        </tr>\n        <tr>\n           <td width=\"13\" background=\"../images/leftbar.gif\"> </td>\n          <td  valign=\"bottom\" background=\"../images/top-bar.gif\"><div align=\"right\"></div></td>\n           <td width=\"16\" background=\"../images/rightbar.gif\"> </td>\n        </tr>\n         <tr>\n          <td> </td>\n          <td><table width=\"100%\" border=\"0\"  align=\"center\" cellpadding=\"2\" cellspacing=\"2\" bordercolor=\"#FFFFFF\">\n                 <tr bordercolor=\"#eeeeee\" bgcolor=\"#f5f5f5\">\n              <td> <div align=\"left \"><font color=\"#000000\">Call\n                  ID</font></div></td>\n              <td>  <div align=\"left\"><font color=\"#000000\">Status</font></div></td>\n              <td>  <div align=\"left\"><font color=\"#000000\">Subject</font></div></td>\n              <td>  <div align=\"left\"><font color=\"#000000\">Date\n                   Opened</font></div></td>\n            </tr>\n            ";
    $sqlc = "SELECT * from `calls` WHERE 1 AND status!='CLOSED' and cid='".$cid."' LIMIT 0,  30";
    if ( !( $resultc = mysql_query( "{$sqlc}" ) ) )
    {
        exit( mysql_error( ) );
    }
    while ( $rowc = mysql_fetch_array( $resultc ) )
    {
        $rowc['subject'] = str_replace( "&", "&", $rowc['subject'] );
        $pid = $rowc['pid'];
        echo "  <tr bgcolor='#f5f5f5'  onMouseOver=this.style.cursor='pointer',this.style.backgroundColor='#F4FAFD'  onMouseOut=this.style.backgroundColor='#F5F5F5'  onclick=this.style.backgroundColor='#84B5CB',location.href='view_ticket.php?pid=".$pid."'  bordercolor=#FFFFFF>";
        echo "    <td><div align='left'> <a href=view_ticket.php?pid=".$pid.">";
        echo $rowc['pid'];
        echo "</a></td><td><div align='left'><a href=view_ticket.php?pid=".$pid."> ";
        echo $rowc['status'];
        echo "</a></td><td><div align='left'> <a href=view_ticket.php?pid=".$pid.">";
        echo $rowc['subject'];
        echo "</a></td><td><div align='left'> ";
        echo $rowc['date'];
        echo "</td></tr>";
    }
    $totalrows = mysql_num_rows( $resultc );
    if ( $totalrows == 0 )
    {
        echo "<tr bordercolor=#FFFFFF><td height=22><font face='Arial, Helvetica, sans- serif'>  No Calls Opened</td><td> </td><td> </td><td> </td></tr>";
    }
    echo "          </table></td>\n          <td> </td>\n        </tr>\n        <tr>\n           <td background=\"../images/bottomleft.gif\"> </td>\n          <td background= \"../images/bottom.gif\"> </td>\n          <td background=\"../images/bottomright.gif \"> </td>\n        </tr>\n      </table>                   \n        ";
}

echo "<br>\n<table width=\"95%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n  <tr>\n    <td> </td>\n    <td valign=\"top\"><div align=\"center\">\n        <table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n          <tr> <a name=\"statistics\" id=\"statistics\"></a>\n              <td width=\"36\"><div align=\"center\"><img src=\"../images/helpdesk.gif\" width=\"20\" height=\"16\"></div></td>\n              <td width=\"96%\"><strong>  Closed Tickets </strong></td>\n              <td width=\"36\"> </td>\n          </tr>\n        </table>\n    </div></td>\n    <td> </td>\n  </tr>\n  <tr>\n    <td width=\"13\" background=\"../images/leftbar.gif\"> </td>\n    <td valign=\"bottom\" background=\"../images/top-bar.gif\"><div align=\"right\"></div></td>\n    <td width=\"16\" background=\"../images/rightbar.gif\"> </td>\n  </tr>\n  <tr>\n    <td> </td>\n    <td><table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"2\" bordercolor=\"#FFFFFF\">\n        <tr bordercolor=\"#eeeeee\" bgcolor=\"#eeeeee\">\n          <td bordercolor=\"#eeeeee\"><div align=\"left\"><strong>Call ID</strong></div></td>\n          <td><div align=\"left\"><strong>Status</strong></div></td>\n          <td><div align=\"left\"><strong>Subject</strong></div></td>\n          <td><div align=\"left\"><strong>Date Opened</strong></div></td>\n        </tr>\n        ";
$a = 1;
$sqlc = "SELECT * from `calls` WHERE 1 AND status='CLOSED' and cid='".$cid."' ORDER by `pid` DESC";
if ( !( $resultc = mysql_query( "{$sqlc}" ) ) )
{
    exit( mysql_error( ) );
}
while ( $rowc = mysql_fetch_array( $resultc ) )
{
    $rowc['subject'] = str_replace( "&", "&", $rowc['subject'] );
    if ( $a == "3" )
    {
        $a = 1;
    }
    if ( $a == "1" )
    {
        $bgcolor = "#EEEEEE";
    }
    else
    {
        $bgcolor = "#F5F5F5";
    }
    $pid = $rowc['pid'];
    echo "  <tr onMouseOver=this.style.cursor='pointer',this.style.backgroundColor='#CCCCCC' onMouseOut=this.style.backgroundColor='#eeeeee' onclick=this.style.backgroundColor='#84B5CB',location.href='view_ticket.php?pid=".$pid."' bordercolor=#FFFFFF bgcolor={$bgcolor}>";
    echo "    <td><div align='left'> ";
    echo $rowc['pid'];
    echo "</td><td><div align='left'> ";
    echo $rowc['status'];
    echo "</td><td><div align='left'> <a href=view_ticket.php?pid=";
    echo $rowc['pid'];
    echo ">";
    echo $rowc['subject'];
    echo "</a></td><td><div align='left'> ";
    echo $rowc['date'];
    echo "</td></tr>";
    $a += 1;
}
echo "</table>";
$totalrows = mysql_num_rows( $resultc );
if ( $totalrows == 0 )
{
    echo "<table width=100%>  No Closed Tickets</table>";
}
echo "    </table></td>\n    <td> </td>\n  </tr>\n  <tr>\n    <td background=\"../images/bottomleft.gif\"> </td>\n    <td background=\"../images/bottom.gif\"> </td>\n    <td background=\"../images/bottomright.gif\"> </td>\n  </tr>\n</table>\n<p align=\"center\">";
include( "footer.php" );
echo "</p>\n";
?>

--

Here is the double form:

(not sure how to post a image in this thread)

Dani AI

Generated

Short summary and practical next steps.

The duplicate table output was caused by the template being emitted once for every matching row in the helpconfig result set. That matches ’s observation about the loop and ’s later finding that the helpconfig table contained two rows for the same cid. Using LIMIT 1 is only a temporary mask for the symptom; as pointed out, the real fix is to remove duplicate data and prevent it from happening again.

Safe, ordered workflow (backup first)

  • Back up the table before any deletes:
    mysqldump my_database helpconfig > helpconfig_backup.sql
  • Find which cid values are duplicated:
    SELECT cid, COUNT(*) AS dupcount
    FROM helpconfig
    GROUP BY cid
    HAVING dupcount > 1;
  • List the actual duplicate rows (replace pk_name with the real primary key column):
    SELECT *
    FROM helpconfig
    WHERE cid IN (
    SELECT cid FROM helpconfig GROUP BY cid HAVING COUNT(*)>1
    )
    ORDER BY cid, pk_name;

Remove duplicates safely

  • Keep the canonical row (usually the lowest or highest PK) and delete the rest. Example (replace pk_name with the actual primary key column):
    DELETE h1
    FROM helpconfig h1
    JOIN helpconfig h2
    ON h1.cid = h2.cid
    AND h1.pk_name > h2.pk_name;

    Run the SELECT version of that JOIN first to verify which rows would be removed. If the table is InnoDB, run inside a transaction when appropriate.

Prevention and code hygiene

  • After deduping, add a uniqueness constraint to prevent reinsertion:
    ALTER TABLE helpconfig ADD UNIQUE KEY (cid);
  • Refactor the PHP so the config row is queried once and reused (avoid repeating identical queries). Migrate away from deprecated mysql_* calls to mysqli or PDO and use prepared statements. Example using mysqli prepared statements:
    $mysqli = new mysqli($host,$user,$pass,$db);
    $stmt = $mysqli->prepare('SELECT pk_name, cid, chaturl, supporturl FROM helpconfig WHERE cid = ?');
    $stmt->bind_param('s', $cid);
    $stmt->execute();
    $config = $stmt->get_result()->fetch_assoc();
  • Also apply output escaping (htmlspecialchars) where values are inserted into HTML to avoid accidental markup/XSS.

Note: ’s point about quoting is relevant for maintainability—use a templating approach or heredoc/nowdoc rather than escaping many quotes inside long echo strings.

Recommended Answers

All 4 Replies

Your table is being echoed in a while loop though, so it's not impossible to have it show up more than once, if there is more than one item in the array.

$sqle = "select * from helpconfig where cid = '1'";
if ( !( $resulte = mysql_query( $sqle ) ) )
{
exit( mysql_error( ) );
}
while ( $rowe = mysql_fetch_array( $resulte ) )
{
    //table building

Does that part really return one result?

FYI, about the mysql_fetch_array you're using:

Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

    mysqli_fetch_array()
    PDOStatement::fetch()

escaping those html tags must hurt your pinky finger :). Years back, there was a great argument on " single quotes vs. double quotes".

so, this one is pretty valid

$form = '<form action="" method="post">';

although this is valid, it keeps your pinky finger busy.

$form = "<form action =\"\" method=\"post\">";

while this one is just the complete opposite of the two. I don't recommend it.

$form = "<form action='' method='post'>";

This fixed it:

Run this statement against your database directly..

php: [Select]
1
select * from helpconfig where cid = '1'

It will return 2 rows..

If you change it to ..

php: [Select]
1
select * from helpconfig where cid = '1' LIMIT 1

then you will get 1 row back

select * from helpconfig where cid = '1'
It will return 2 rows..

If you get 2 or more rows returned from what you said, something is not right. Either your table has 2 duplicated rows or something in your setting is off... You should never need to LIMIT the number of rows if you know that the condition given is a unique value in the table.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.