PDA

View Full Version : PHP Help Request



ChristopherH
01-04-2012, 03:10 AM
Hello Guys!

I am after a little help,

I am setting up a user-system with RMB's user-system as i quite like it,
Now i know their is security flaws and what not, But I'll sort them out.

It's been doing my head in trying to get this to work but i would like to
know if you could recode this to make the member list showup like this:

Userlist:

[MemberName] [MemberName] [MemberName]

[MemberName] [MemberName] [MemberName]

But Currently it's showing up like:

[MemberName]
[MemberName]
[MemberName]
[MemberName]
[MemberName]

Etc..

Here is the code:


}
}else{
//gets all the members from the database
$getusers = mysql_query("SELECT * FROM `authme` ORDER BY `id` ASC") or die(mysql_error());
//loops there name out
while ($user = mysql_fetch_array($getusers)) {
echo "<a href='members.php?user=$user[username]'>$user[username]</a><br>";
}
}
echo "<center>";
?>

Would be appreciated if you could help me with this asap.

Thanks,
Chris.

N!ck
01-04-2012, 12:39 PM
A little bit messy and untested, but something like this should work.

}
}else{
//gets all the members from the database
$getusers = mysql_query("SELECT * FROM `authme` ORDER BY `id` ASC") or die(mysql_error());
//loops there name out
$i = 1;
while ($user = mysql_fetch_array($getusers)) {
if ($i % 3 != 0) {
echo "<a href=\"members.php?user={$user['username']}\">{$user['username']}</a> ";
} else {
echo "<a href=\"members.php?user={$user['username']}\">{$user['username']}</a><br />";
}
i++;
}
}
echo "<center>";
?>

ChristopherH
03-04-2012, 09:39 AM
Cheer's for that mate, Ill check it about asap.

ChristopherH
06-04-2012, 04:46 AM
Ok so that did work, but it didn't

I was after it to display diffrent users name's 3 across so on,
but the script you sent displays as many as it can fit on the page across.

Could you posiblly re-design the code to do this?

[Username1] [Username2] [Username3]
[Username4] [Username5] [Username6]
So on..

In tables?

Blinger
06-04-2012, 05:22 AM
Okay this is pseudocode since I'm not on a Pc!


while($i < 3){
..if($i == 3){
....echo "<tr><td>username</td></tr>"
....$i=0
..} else {
....echo "<td>username</td>
..}
..$i ++
}

ChristopherH
06-04-2012, 05:28 AM
Okay this is pseudocode since I'm not on a Pc!


while($i < 3){
..if($i == 3){
....echo "<tr><td>username</td></tr>"
....$i=0
..} else {
....echo "<td>username</td>
..}
..$i ++
}


So ill just remove the ..?

Blinger
06-04-2012, 05:49 AM
Ill jump on a Pc now and type up what should work!

---------- Post added 06-04-2012 at 04:03 PM ----------



} else {
// row counter
$i = 0;
// Echo the start of the table
echo("<table width=\"90%\" border=\"0\"><tr>");
// Start fetching usernames
while ($user = mysql_fetch_array($getusers)) {
// Check whether we are at the 3rd member
if($i < 3){
// Since we are, echo start of a new row
echo("</tr><tr>");
}
// Show the users
echo ("<td width=\"33%\" align=\"center\"><a href=\"members.php?user={$user['username']}\">{$user['username']}</a></td>");
}
// End of the table and users
echo("</tr></table>");


That should work

ChristopherH
06-04-2012, 06:35 AM
Ill jump on a Pc now and type up what should work!

---------- Post added 06-04-2012 at 04:03 PM ----------



} else {
// row counter
$i = 0;
// Echo the start of the table
echo("<table width=\"90%\" border=\"0\"><tr>");
// Start fetching usernames
while ($user = mysql_fetch_array($getusers)) {
// Check whether we are at the 3rd member
if($i < 3){
// Since we are, echo start of a new row
echo("</tr><tr>");
}
// Show the users
echo ("<td width=\"33%\" align=\"center\"><a href=\"members.php?user={$user['username']}\">{$user['username']}</a></td>");
}
// End of the table and users
echo("</tr></table>");


That should work

OK so i have this:



";

}
}else{
//gets all the members from the database
$getusers = mysql_query("SELECT * FROM `authme` ORDER BY `id` ASC") or die(mysql_error());
//loops there name out
while ($user = mysql_fetch_array($getusers)) {
// row counter
$i = 0;
// Echo the start of the table
echo("<table width=\"90%\" border=\"0\"><tr>");
// Start fetching usernames
while ($user = mysql_fetch_array($getusers)) {
// Check whether we are at the 3rd member
if($i < 3){
// Since we are, echo start of a new row
echo("</tr><tr>");
}
// Show the users
echo ("<td width=\"33%\" align=\"center\"><a href=\"members.php?user={$user['username']}\">{$user['username']}</a></td>");
}
// End of the table and users
echo("</tr></table>");
echo("");
?>


And it's showing it back to this format?
{member}
{member}
{member}
{member}
{member}
{member}

Blinger
06-04-2012, 06:36 AM
You need to close the while loop.

ChristopherH
06-04-2012, 06:39 AM
Hahah I'm really ****** at this kind of stuff Blinger :)
Would love it if you could help me with that one?

Blinger
06-04-2012, 06:59 AM
Okay, I'm guessing you are new to PHP? Every time you open a loop/if condition with the curly brackets { you need to close it when it has finished with the } bracket. The error code tells you what it is expecting.

Not going to fully help out now because I'm not in the mood to do coding work..

---------- Post added 06-04-2012 at 05:01 PM ----------

Also, you need to put the code I showed you above inside your content DIV. make an if statement to see whether the username is set at all and if it ISN'T then show the userlist. What you currently have would look like this:

Blinger
21 male australia
[email protected]
mysace whatever

------
(c) Blinger 2012 doin' his ****, my footer here.

<img of end of site>

BLINGER
2nd User
3rd user
Wixi
Tiegan

ChristopherH
06-04-2012, 07:06 AM
Yeah i fixed the error code about the end, But then it showed the format as what you're saying but it's setup not to show the profile unless you request it by going. ?user=chris

So I've got the profile side setup good, But the main part where i am having issues is the Member List witch is showing up like:

{MemberName}
{MemberName}
{MemberName}

I inserted the code you gave me and it is still displaying like that.

*sent you a pm btw*

N!ck
06-04-2012, 12:30 PM
My previous code didn't work because there's a typo in it :). I'm used to C++ at the moment and missed a $ symbol.


}
}else{
//gets all the members from the database
$getusers = mysql_query("SELECT * FROM `authme` ORDER BY `id` ASC") or die(mysql_error());
//loops there name out
$i = 1;
while ($user = mysql_fetch_array($getusers)) {
if ($i % 3 != 0) {
echo "<a href=\"members.php?user={$user['username']}\">{$user['username']}</a> ";
} else {
echo "<a href=\"members.php?user={$user['username']}\">{$user['username']}</a><br />";
}
$i++;
}
}
echo "<center>";
?>

ChristopherH
06-04-2012, 03:18 PM
My previous code didn't work because there's a typo in it :). I'm used to C++ at the moment and missed a $ symbol.


}
}else{
//gets all the members from the database
$getusers = mysql_query("SELECT * FROM `authme` ORDER BY `id` ASC") or die(mysql_error());
//loops there name out
$i = 1;
while ($user = mysql_fetch_array($getusers)) {
if ($i % 3 != 0) {
echo "<a href=\"members.php?user={$user['username']}\">{$user['username']}</a> ";
} else {
echo "<a href=\"members.php?user={$user['username']}\">{$user['username']}</a><br />";
}
$i++;
}
}
echo "<center>";
?>

You're a bloody Legend!
one small favor are you able to help me get it to display maybe 5 Lines and do a pagination type thing?

Tomm
06-04-2012, 04:13 PM
What have you tried?

http://mattgemmell.com/2008/12/08/what-have-you-tried/

Dentafrice
07-04-2012, 09:15 PM
I'm sorry to say this, but can you not just Google PHP Pagination and easily see how to format your queries and display to do this?

Want to hide these adverts? Register an account for free!