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
ek5932
Forum Commoner
Posts: 25 Joined: Mon Jun 28, 2004 5:55 pm
Post
by ek5932 » Tue Aug 17, 2004 3:48 am
I want to seperate all my users into a sector sort of thing with 20 users to one sector. In the sector when there are no users instead of not showing anything and setting a max limit to 20 i want it to display as
empty and every time a user joins up from the bottom upwards the empty changes to a user. The current code I have is
Code: Select all
<?
include 'db.php';
$result = @mysql_query("SELECT kingdom_name, x, y, net FROM users WHERE galaxy='$g' AND sector='$s' ORDER BY userid ASC");
if (!$result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
while ( $row = mysql_fetch_array($result) ) {
echo("<tr bgcolor=222222><td>" . $rowї"kingdom_name"] . " (X:" . $rowї"x"] . ",Y:" . $rowї"y"] . ")</td>");
echo("<td>" . $rowї"net"] . "</td></tr>");
}
?>
But that just loops all the kingdoms and displays nothing when no one has signed up. Any help would be greatly apreciated.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 10:12 am
using [php_man]mysql_num_rows[/php_man](), you can check how many were found, if any. This will allow you to write out empty and whatnot..
ek5932
Forum Commoner
Posts: 25 Joined: Mon Jun 28, 2004 5:55 pm
Post
by ek5932 » Tue Aug 17, 2004 12:00 pm
I tried looking at that but it dosnt give me much help. I will keep on looking around.
ek5932
Forum Commoner
Posts: 25 Joined: Mon Jun 28, 2004 5:55 pm
Post
by ek5932 » Tue Aug 17, 2004 4:49 pm
I get the result but im not sure how to loop the results empty or the users details
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 4:55 pm
if num_rows returns zero, you print an empty results signage.. otherwise, do your loop..
ek5932
Forum Commoner
Posts: 25 Joined: Mon Jun 28, 2004 5:55 pm
Post
by ek5932 » Tue Aug 17, 2004 5:25 pm
i must of explained my self wrong. if there is 1 user there are 19 rows field with empty and 1 with the users details, not just say its empty
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 17, 2004 5:27 pm
okay.. then take the difference of your limit and the number found.. print that many empty slots...
ek5932
Forum Commoner
Posts: 25 Joined: Mon Jun 28, 2004 5:55 pm
Post
by ek5932 » Tue Aug 17, 2004 6:08 pm
thanks