Jump to content

Problem with displaying table data


kostasls

Recommended Posts

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?

 

<?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"] . " </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"] . " </td>";

	    echo "<td style=\"border-bottom: 1px solid #f05050\">" . $myrow["cs"] . " </td>";
		echo "<td style=\"border-bottom: 1px solid #f05050\">" . $myrow["hc"] . " </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"] . " </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 :)

 

EDITED BY WILDTEEN88: Please use code (


) tags when posting code.

Link to comment
Share on other sites

try or die(mysql_error())

 

<?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 + 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"] . " </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"] . " </td>";

	    echo "<td style=\"border-bottom: 1px solid #f05050\">" . $myrow["cs"] . " </td>";
		echo "<td style=\"border-bottom: 1px solid #f05050\">" . $myrow["hc"] . " </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"] . " </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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.