Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 2008-03-03, 08:33 AM
Junior Member
 
Join Date: Mar 2008
Posts: 1
kostasls is on a distinguished road
Default Error getting table from database

PHP Code:
<?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) or die(mysql_error());
    
$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 $myrow["other"];
            
$host $host $myrow["canhost"];
            if (
$myrow["hst"] == "Y") {
                
$need $need $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);
?>
Reply With Quote
  #2 (permalink)  
Old 2008-03-04, 01:57 PM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,096
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

order by <FIELD> order by <FIELD> is not valid.

It is order by <FIELD>, <FIELD> instead.

Other than that it looks ok. What is the error?
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:29 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.