Jump to content

[SOLVED] Show all registered usernames


Zoroaster

Recommended Posts

Hi. I've been struggling with this for a while, sorry but I'll have to come ask for your help once again.

 

I'm trying to show all the registered usernames from the database on my site, I've only managed to make it show the username you're logged in on, not every username. Thanks. :)

Link to comment
Share on other sites

Here, take a look at the whole code. Here I did what I planned to do. And it works, with no troubles at all. However, now I want to try and edit this code to show ALL the usernames in the database, not just the one the person is logged in to. Take a look at the code and see if you come up with an idea.

 

<?php

session_start();
if(!session_is_registered(myusername)) {
header("location:index.php");
}

$username = $_SESSION['myusername'];
$moneybutton = $_POST['moneybutton'];


$connect = mysql_connect("localhost","zoroaste","***");
mysql_select_db("zoroaste_test1");


$sql4 = "SELECT * FROM Login WHERE username LIKE '$username';";
$query = mysql_query($sql4);

while($row = mysql_fetch_array($query))
{
    $uusername = $row['username'];
    $money= $row['money'];
}

echo "<br><br><b>Hello $uusername </b><br>";
echo "<b>You have: $money coins!</b>";

if ($moneybutton)
{
$rand = (rand(2,10));
$newamount = $money + $rand;
mysql_query("UPDATE Login SET money = $newamount
WHERE username LIKE '$username'");


echo "<br><br>congratulations you found $rand coins!";
}

?>


<html>
<body bgcolor="#000066">
<br>
<br>
<b><center>THIS IS THE MAIN PAGE! WELCOME!</b>

<br>
<br

<form action='page1.php' method='post'>
<input type='submit' name='moneybutton' value='Click this button to search for coins!'>
</form>
</body>
</html>

Link to comment
Share on other sites

You need to put the echo statements inside the while loop. Also remove the WHERE condition from the query like the previous poster said.

 

while($row = mysql_fetch_array($query))
{
    $uusername = $row['username'];
    $money= $row['money'];
    echo "<br><br><b>Hello $uusername </b><br>";
    echo "<b>You have: $money coins!</b>";
}


Link to comment
Share on other sites

<?php

session_start();
if(!session_is_registered(myusername)) {
header("location:index.php");
}

$connect = mysql_connect("localhost","zoroaste","***");
mysql_select_db("zoroaste_test1");


$sql4 = "SELECT * FROM Login";
$query = mysql_query($sql4);

while($row = mysql_fetch_array($query))
{$uusername = $row['username'];
echo "$uusername";}

?>

 

Thanks, that worked! However, the output is the usernames all next to eachother without spaces. Any idea how I could put in a break line between them? And also make their names a link?

Link to comment
Share on other sites

Ok look.

echo "$uusername"

is one variable of course, and that one variable shows all the usernames. The output is:

 

"pieZoroastertesttertblobBoldheadJoeHallomerdboofergunnar"

 

What I'd want it to be would be:

 

"

pie

Zoroaster

test

tert

blob

Boldhead

Joe

Hallo

merd

boofer

gunnar

"

 

But how can I set a line break between the usernames when all the usernames are in the one and same variable?

Link to comment
Share on other sites

<?php

session_start();
if(!session_is_registered(myusername)) {
header("location:index.php");
}

$connect = mysql_connect("localhost","zoroaste","***");
mysql_select_db("zoroaste_test1");


$sql4 = "SELECT * FROM Login";
$query = mysql_query($sql4);

while($row = mysql_fetch_array($query)) {
$uusername = $row['username'];
echo $uusername;
echo '<br />'
}

?>

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.