Jump to content

Appear under differnet headlines


snallemap

Recommended Posts

<?php

        include "config.php";

$sql = "SELECT id, username FROM gusers";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      echo "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
    }
  }
}

 

Now i were wondering if there were a way to sort the outcome of pages, currently there comes all the members names, and when you click you get to their profile page, which is pretty much perfect!

 

Now i were just wondering if there were any way to put them up in categories? Like:

 

Admins:

- All with status +4 here

 

Honored Members:

- All with status 2 and 3 here

 

Members:

- All with 1 here

 

 

I have been searching for tutorials and everything... and since im a newb to Php i cant solve it myself... So im looking for help :) Could any of you guys help me out ?

Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Maybe use in your query ORDER BY rank DESC --

To put them in order (assuming you have a field named rank in your table)

 

And in your while loop add something like;

 

switch($rank){
            case 4:
                echo '<b>ADMIN: </b>';
                echo "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
                break;
            case 2 or 3:
                echo '<b>Honored Members: </b>';
                echo "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
                break;
            case 1:
                echo '<b>Member: </b>';
                echo "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
                break;
        }

 

Hope this helps a bit

Link to comment
Share on other sites

Maybe something like this:

 


<?php

        include "config.php";

$sql = "SELECT id, username FROM gusers";
if ($result = mysql_query($sql)) 
{
  if (mysql_num_rows($result)) 
  {
   $adminLinks = "";
   $honoredLinks = "";
   $memberLinks = "";
   while ($row = mysql_fetch_assoc($result)) 
    {
    switch ($row['status'])
     {
      case '1':
      $membersLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '2' or '3':
      $honoredLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '4':
      $adminLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
     }
    }
    echo $adminLinks . "<br>" . $honoredLinks . "<br>" . $memberLinks;
  }
}

 

Or, instead, you could create an array (Links) with three nodes (Admin, Honored, Member) and all those can be arrays of links. Then print out the original array (links).

 

(I think a problem with what fortnox007 suggested is you're going to end up with a title (Admin:, Honored Members:, or Member:) before each link... which I don't think is what you'd wanted.

Link to comment
Share on other sites

Parse error: parse error in C:\wamp\www\kawaii\memberlist.php on line 27

 

<?php

        include "config.php";

$sql = "SELECT id, username, status FROM gusers";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
    
     switch($status){
            case 4:
                echo '<b>ADMIN: </b>';
                echo "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
                break;
            case 2 or 3:
                echo '<b>Honored Members: </b>';
                echo "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
                break;
            case 1:
                echo '<b>Member: </b>';
                echo "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
                break;
                
     }
}

?>

 

Sorry mate, either i coudln't figure out how it works otherwise it dosent work :(... Thats my code, i get an error in the end nomatter what i do and i cannot figure out how to stop it -.-.

 

 

Link to comment
Share on other sites

Maybe something like this:

 


<?php

        include "config.php";

$sql = "SELECT id, username FROM gusers";
if ($result = mysql_query($sql)) 
{
  if (mysql_num_rows($result)) 
  {
   $adminLinks = "";
   $honoredLinks = "";
   $memberLinks = "";
   while ($row = mysql_fetch_assoc($result)) 
    {
    switch ($row['status'])
     {
      case '1':
      $membersLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '2' or '3':
      $honoredLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '4':
      $adminLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
     }
    }
    echo $adminLinks . "<br>" . $honoredLinks . "<br>" . $memberLinks;
  }
}

 

Or, instead, you could create an array (Links) with three nodes (Admin, Honored, Member) and all those can be arrays of links. Then print out the original array (links).

 

(I think a problem with what fortnox007 suggested is you're going to end up with a title (Admin:, Honored Members:, or Member:) before each link... which I don't think is what you'd wanted.

 

your right, he was looking for headlines, not labels per item nice solution you added ty for sharing ::)

Link to comment
Share on other sites

Maybe something like this:

 


<?php

        include "config.php";

$sql = "SELECT id, username FROM gusers";
if ($result = mysql_query($sql)) 
{
  if (mysql_num_rows($result)) 
  {
   $adminLinks = "";
   $honoredLinks = "";
   $memberLinks = "";
   while ($row = mysql_fetch_assoc($result)) 
    {
    switch ($row['status'])
     {
      case '1':
      $membersLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '2' or '3':
      $honoredLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '4':
      $adminLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
     }
    }
    echo $adminLinks . "<br>" . $honoredLinks . "<br>" . $memberLinks;
  }
}

 

Or, instead, you could create an array (Links) with three nodes (Admin, Honored, Member) and all those can be arrays of links. Then print out the original array (links).

 

(I think a problem with what fortnox007 suggested is you're going to end up with a title (Admin:, Honored Members:, or Member:) before each link... which I don't think is what you'd wanted.

 

Thanks for it, but im still not getting any results out of it :(... This is what shows up:

 

0

 

Yes only that single 0 ... :(

Link to comment
Share on other sites

Yeah I guess I could have put it through notepad++ and checked it out first :(

 

As far as the assignment part goes: I'm not going to bother fixing that since he asked about it in another thread, I gave him a clean way to do it, and he ignored the answer. So, then I won't bother to fix it (again) here x.x"

 

 

OP: Did you fix the brace error?

Link to comment
Share on other sites

Changed an error (has misnamed $memberLinks at some point), fixed your mysql logic at the top (you should read up on it though, and yes the other page was better and useful read to you), and added a check in case you have no members of certain statuses.

<?php

include "config.php";

$sql = "SELECT id, username FROM gusers";
$result = mysql_query($sql) or die (mysql_error());
$rows = mysql_num_rows($result);
if ($rows > 0) 
  {
   $adminLinks = "";
   $honoredLinks = "";
   $memberLinks = "";
   while ($row = mysql_fetch_assoc($result)) 
    {
    switch ($row['status'])
     {
      case '1':
      $memberLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '2' or '3':
      $honoredLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '4':
      $adminLinks += "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
     }
    }
if (blank($adminLinks)) { $adminLinks = "There are no administrators."; }
if (blank($honoredLinks)) { $adminLinks = "There are no honored members."; }
if (blank($memberLinks)) { $adminLinks = "There are no members."; }
    echo $adminLinks . "<br>" . $honoredLinks . "<br>" . $memberLinks;
  }
}

Link to comment
Share on other sites

Don't apologize im just more than happy that you would give yourself time to help me out :) Its not perfect yet but no errors popping up!

 

<?php

include "config.php";

$sql = "SELECT id, username, status FROM gusers";
$result = mysql_query($sql) or die (mysql_error());
$rows = mysql_num_rows($result);
if ($rows > 0) 
  {
   $adminLinks = "";
   $honoredLinks = "";
   $memberLinks = "";
   while ($row = mysql_fetch_assoc($result)) 
    {
    switch ($row['status'])
     {
      case '1':
      $memberLinks .= "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '2' or '3':
      $honoredLinks .= "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '4':
      $adminLinks .= "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
     }
    }

    

if (empty($adminLinks)) { $adminLinks = "There are no administrators."; }

    

if (empty($honoredLinks)) { $adminLinks = "There are no honored members."; }

    

if (empty($memberLinks)) { $adminLinks = "There are no members."; }
    echo $adminLinks . "<br>" . $honoredLinks . "<br>" . $memberLinks;
  }

?>

 

 

This is how it appears in the browser:

 

There are no members.

test

 

 

(test is admin user), apperently the "There are no honorable members." is missing, aswell as the headlines :(

 

--------------

 

Added a user with status 1 now this appears:

 

 

There are no administrators.

test

 

bulle

 

-----------

 

Added 1 user with Status 1 more and 1 with status 2...

 

 

There are no administrators. <- There is a user with status 4 (test) Still not working here...

snalle <- Status 2

test <- Status 4

 

snallesnal <- Status 1

bulle <- Status 1

 

Help anyone XD?

Link to comment
Share on other sites

Don't apologize im just more than happy that you would give yourself time to help me out :) Its not perfect yet but no errors popping up!

 

<?php

include "config.php";

$sql = "SELECT id, username, status FROM gusers";
$result = mysql_query($sql) or die (mysql_error());
$rows = mysql_num_rows($result);
if ($rows > 0) 
  {
   $adminLinks = "";
   $honoredLinks = "";
   $memberLinks = "";
   while ($row = mysql_fetch_assoc($result)) 
    {
    switch ($row['status'])
     {
      case '1':
      $memberLinks .= "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '2' or '3':
      $honoredLinks .= "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
      case '4':
      $adminLinks .= "<a href='profile.php?id={$row['id']}'>{$row['username']} \n<br/></a>";
      break;
     }
    }

    

if (empty($adminLinks)) { $adminLinks = "There are no administrators."; }

    

if (empty($honoredLinks)) { $adminLinks = "There are no honored members."; }

    

if (empty($memberLinks)) { $adminLinks = "There are no members."; }
    echo $adminLinks . "<br>" . $honoredLinks . "<br>" . $memberLinks;
  }

?>

 

 

This is how it appears in the browser:

 

There are no members.

test

 

 

(test is admin user), apperently the "There are no honorable members." is missing, aswell as the headlines :(

 

--------------

 

Added a user with status 1 now this appears:

 

 

There are no administrators.

test

 

bulle

 

 

Your missing a connection var in mysql_query()  look in to this : http://php.net/manual/en/function.mysql-query.php

It should have 2 parameters

same is for your "or die" clause

 

mysql_error() should have the connection var in it.

 

the connection var is something like this

 

$dbc = mysql_connect (etc etc etc);  than put that $dbc in thos things above as extra parameter

 

-edit: it's the connection var from you config.php btw

Link to comment
Share on other sites

Your missing a connection var in mysql_query()  look in to this : http://php.net/manual/en/function.mysql-query.php

It should have 2 parameters

 

Not strictly true, mysql_query() will inherit any established connection, so if there is an established connection in the config file, php will use that one to perform a query, so you can leave the second parameter off... I just thought I should clear any ambiguity up on that part..

 

Rw

Link to comment
Share on other sites

Your missing a connection var in mysql_query()  look in to this : http://php.net/manual/en/function.mysql-query.php

It should have 2 parameters

 

Not strictly true, mysql_query() will inherit any established connection, so if there is an established connection in the config file, php will use that one to perform a query, so you can leave the second parameter off... I just thought I should clear any ambiguity up on that part..

 

Rw

: ) your totally true.

Link to comment
Share on other sites

Ok,

<?php

include "config.php";

$sql = "SELECT `id`, `username`, `status` FROM `gusers` ";
$result = mysql_query($sql) or die (mysql_error());
echo $rows = mysql_num_rows($result);

if ($rows > 0) {

   $adminLinks,$honoredLinks,$memberLinks = "";
   
   while ($row = mysql_fetch_assoc($result)){
   
   //see what is in the actuall value being checked/switched over
   print_r($row['status']);
   
   //change to suit - could do with a default case in this, but get it functional first
    switch ($row['status']){
      case '1':
      $memberLinks .= "<a href=\"profile.php?id=".$row['id']."\">".$row['username']."</a>\n\r";
      break;
      case '2' or '3':
      $honoredLinks .= "<a href=\"profile.php?id=".$row['id']."\">".$row['username']."</a>\n\r";
      break;
      case '4':
      $adminLinks .= ""<a href=\"profile.php?id=".$row['id']."\">".$row['username']."</a>\n\r";
      break;
     }
    }

    

if (empty($adminLinks)) { $adminLinks = "There are no administrators."; }

    

if (empty($honoredLinks)) { $adminLinks = "There are no honored members."; }

    

if (empty($memberLinks)) { $adminLinks = "There are no members."; }
    echo $adminLinks . "<br>" . $honoredLinks . "<br>" . $memberLinks;
  }
//and for the hell of it see where we are with the others
echo $adminLinks . "<br>" . $honoredLinks . "<br>" . $memberLinks;
?>

 

Changed some of the concatenations on this, all I need to see now is an excerpt of the data from the database, then from that we can see what you should be getting.

 

I have echoed the row count too so that you can see how many records there are being pulled from the Db and commented some things for you too, see where that gets you. Hopefully this will be solved by the time I get up, I am WAY past my bed time...

 

Rw

Link to comment
Share on other sites

CREATE TABLE IF NOT EXISTS `gusers` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `username` varchar(16) NOT NULL,
  `password` char(100) NOT NULL,
  `name` varchar(40) NOT NULL,
  `age` int(2) NOT NULL,
  `sex` int(2) NOT NULL,
  `email` varchar(25) NOT NULL,
  `status` int(10) NOT NULL,
  `info` varchar(1000) NOT NULL,
  `class` int(2) NOT NULL,
  `charm` int(6) NOT NULL,
  `str` int(5) NOT NULL,
  `dex` int(5) NOT NULL,
  `luk` int(5) NOT NULL,
  `wis` int(5) NOT NULL,
  `vit` int(5) NOT NULL,
  `level` int(3) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`,`email`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Data dump for tabellen `gusers`
--

INSERT INTO `gusers` (`id`, `username`, `password`, `name`, `age`, `sex`, `email`, `status`, `info`, `class`, `charm`, `str`, `dex`, `luk`, `wis`, `vit`, `level`) VALUES
(1, 'snalle', 'test123', '', 0, 0, 'redacted1@example.com', 2, 'Bla bla', 1, 1, 1, 1, 1, 1, 1, 1),
(2, 'snallesnal', '*676243218923905', '', 0, 0, 'redacted2@example.com', 1, '', 0, 0, 0, 0, 0, 0, 0, 0),
(3, 'bulle', '*F26FC230028BCEC3DC4AA3D4C00961B896E101AE', '', 0, 0, 'redacted3@example.com', 1, '', 0, 0, 0, 0, 0, 0, 0, 0),
(4, 'test', '*676243218923905CF94CB52A3C9D3EB30CE8E20D', 'Simon', 18, 1, 'redacted4@example.com', 4, 'Hej jeg hedder Simon, jeg laver hjemmeside! Er jeg ikke sej!?', 5, 0, 0, 0, 0, 0, 0, 0);
The mysql...

 

Now i will try your edited version to see if that works out.

 

 

Result:

 

Parse error: parse error in C:\wamp\www\kawaii\memberlist.php on line 11

 

Also theres an error on line 27 (i dunno what, it just shows that in Dreamweaver).

Edited by requinix
redacting email addresses
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.