Member help

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

Post Reply
ek5932
Forum Commoner
Posts: 25
Joined: Mon Jun 28, 2004 5:55 pm

Member help

Post by ek5932 »

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) &#123;
    echo("<p>Error performing query: " . mysql_error() . "</p>");
    exit();
  &#125;
  while ( $row = mysql_fetch_array($result) ) &#123;
  echo("<tr bgcolor=222222><td>" . $row&#1111;"kingdom_name"] . " (X:" . $row&#1111;"x"] . ",Y:" . $row&#1111;"y"] . ")</td>");
    echo("<td>" . $row&#1111;"net"] . "</td></tr>");
	&#125;
?>
But that just loops all the kingdoms and displays nothing when no one has signed up. Any help would be greatly apreciated.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

I tried looking at that but it dosnt give me much help. I will keep on looking around.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

How does it not help you?
ek5932
Forum Commoner
Posts: 25
Joined: Mon Jun 28, 2004 5:55 pm

Post by ek5932 »

I get the result but im not sure how to loop the results empty or the users details
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

thanks :D
Post Reply