snallemap Posted September 23, 2010 Share Posted September 23, 2010 <?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 ? Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 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 -.-. Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 I don't know what line 27 is in your code sorry. But I suggest you use the code of Miss_rebelx since it provides Headlines instead of labels like my script. -edit: count your curly braces and you will see what your error is Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 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 ... Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 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? Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 Well, if your saying you helped me with this once already, then your wrong :/... I've tried what you said though... But it still aint working which is kinda sad Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 http://www.phpfreaks.com/forums/index.php/topic,310819.msg1467918.html#msg1467918 Your getting one zero? That's it? A blank screen, with a zero? No error messages? Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 http://www.phpfreaks.com/forums/index.php/topic,310819.msg1467918.html#msg1467918 Your getting one zero? That's it? A blank screen, with a zero? No error messages? Yes a 0 and a blank screen ... Nothing else... No errors in the brower or in Adobe, and sorry but i cant work that other thread in here Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 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; } } Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 Fatal error: Call to undefined function blank() in C:\wamp\www\kawaii\memberlist.php on line 31 Thats the check that causes that. And when i remove the check just to see what happens... its all blank again with the zero. :/ Now im totally lost xD Quote Link to comment Share on other sites More sharing options...
Miss_Rebelx Posted September 23, 2010 Share Posted September 23, 2010 I think I messed up when I said to use " += ". I think a string concatenation is " .= ". Can you try switching that in at the 3 places in the code? Also, switch blank() with empty().... I'm about to leave work so please accept my apologies for this. Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 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? Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 23, 2010 Share Posted September 23, 2010 += overwrites the first instance & adds the newer value .= builds the variable by appending the data to the end of the string:- check me out! Rw Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 23, 2010 Share Posted September 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 Guys really, im still lost sorry xD... I dont know what i should fix in my code to make it work.... i have no clue where the errors is All i know is it dosent do as it should Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 small question. If you leave out the headlines code with the switch statements. Are you able to output the values from the database including RANKS? and if you can please post that code exactly as you use it. Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 23, 2010 Share Posted September 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 (edited) 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 May 24, 2017 by requinix redacting email addresses Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 in any editor there are line numbers please tell use what stuff is on line 11 and 27 Quote Link to comment Share on other sites More sharing options...
snallemap Posted September 23, 2010 Author Share Posted September 23, 2010 Line 11: $adminLinks,$honoredLinks,$memberLinks = ""; Line 27: $adminLinks .= ""<a href=\"profile.php?id=".$row['id']."\">".$row['username']."</a>\n\r"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.