Page 1 of 1

Problem with displaying table data

Posted: Sun Mar 02, 2008 10:00 am
by kostasls
Hello everyone
i am using this script but it doesnt diplay the date of the table
it says "sorry no records were found!" but i have confirmed that the table exists and with data.

Can anyone tell me if you see any mistake?

Code: Select all

<?php
 
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $dbname = 'camp';
    $table = 'requests';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
 
 
    mysql_select_db($dbname, $conn);
    mysql_query("SET NAMES 'utf8'");
    if ($_GET["order_by"] == "name") { $order_by = " order by namesurname"; }
    if ($_GET["order_by"] == "country") { $order_by = " order by country"; }
    if ($_GET["order_by"] == "hc") { $order_by = " order by hc"; }
    if ($_GET["order_by"] == "cs") { $order_by = " order by cs"; }
    if ($_GET["order_by"] == "need") { $order_by = " order by needhost"; }
    if ($_GET["order_by"] == "other") { $order_by = " order by other"; }
    if ($_GET["order_by"] == "accept") { $order_by = " order by canhost"; }
    if ($_GET["order_by"] == "notes") { $order_by = " order by notes"; }
 
    $result = mysql_query("SELECT namesurname as nm, email, IF(country is null, 'world', country) country, cs, hc, needhost as hst, other, canhost, notes, create_date, ipnumber, useragent, acceptlanguage FROM {$table} WHERE confirmed='Y' order by create_date" . $order_by, $conn);
    $i = 0;
    $kisi = 0;
    $need = 0;
    $host = 0;
    echo "<table style=\"font-family: tahoma; font-size: 8pt\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" border=\"0\">";
    $bgcolor = "#99aabb";
    echo "<tr>";
    echo "<td bgcolor=\"" . $bgcolor . "\"><a href=\"?order_by=name\">Name</a></td>";
    echo "<td bgcolor=\"" . $bgcolor . "\"><a href=\"?order_by=country\">Country</a></td>";
    echo "<td bgcolor=\"" . $bgcolor . "\"><a href=\"?order_by=cs\">CS Name</a></td>";
    echo "<td bgcolor=\"" . $bgcolor . "\"><a href=\"?order_by=hc\">HC Name</a></td>";
    echo "<td bgcolor=\"" . $bgcolor . "\"><a href=\"?order_by=notes\">Notes</a></td>";
    echo "</tr>\n";
if (!$result) {
    die("Query to show fields from table failed");
}
    if ($myrow = mysql_fetch_array($result)) {
        do {
            $i = $i + 1;
            $kisi = $kisi + 1 + $myrow["other"];
            $host = $host + $myrow["canhost"];
            if ($myrow["hst"] == "Y") {
                $need = $need + 1 + $myrow["other"];
            }
            echo "<tr>";
            if ($bgcolor == "#ffffff") {
                $bgcolor = "#d0d0d0";
            } else {
                $bgcolor = "#ffffff";
            }
 
 
            echo "<td style=\"border-bottom: 1px solid #f05050\">" . $myrow["nm"] . "&nbsp;</td>";
 
            echo "<td style=\"border-bottom: 1px solid #f05050\"><img style=\"border: 1px solid black\" src=\"http://www.organikkimya.com/images/flags/" . trim($myrow["country"]) . ".gif\" width=\"20px\" alt=\"". trim($myrow["country"]) . "\">
" . $myrow["country"] . "&nbsp;</td>";
 
            echo "<td style=\"border-bottom: 1px solid #f05050\">" . $myrow["cs"] . "&nbsp;</td>";
            echo "<td style=\"border-bottom: 1px solid #f05050\">" . $myrow["hc"] . "&nbsp;</td>";
            echo "<td style=\"border-bottom: 1px solid #f05050\" colspan=\"1\"><span style=\"color: red\">";
            if ($myrow["hst"] == "Y") {
                echo "i need host. ";
            };
            if (($myrow["canhost"] != "-") & ($myrow["canhost"] != "0")) {
                if ($myrow["canhost"] == "1") {
                    echo "i can accept 1 guest. ";
                } else {
                    echo "i can accept " . $myrow["canhost"] . " guests. ";
                }
            }
            if (($myrow["other"] != "-") & ($myrow["other"] != "0")) {
                if ($myrow["other"] == "1") {
                    echo "there'll be 1 other participant with me. ";
                } else {
                    echo "there'll be " . $myrow["other"] . " other participants with me. ";
                }
            }
 
 
            echo "</span><br />" . $myrow["notes"] . "&nbsp;</td>";
            echo "</tr>\n";
        } while ($myrow = mysql_fetch_array($result));
    } else {
        echo "Sorry, no records were found!";   
    }
    echo "</table>";
 
    echo "Totally " . $i . " records, " . $kisi . " participants, " . $need . " people are looking for hosts, " . $host . " of them can be hosted.";
    mysql_close($conn);
?>
thank you :)