Zoroaster Posted September 4, 2009 Share Posted September 4, 2009 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. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted September 4, 2009 Share Posted September 4, 2009 Well how are you trying to do it? Quote Link to comment Share on other sites More sharing options...
Zoroaster Posted September 4, 2009 Author Share Posted September 4, 2009 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> Quote Link to comment Share on other sites More sharing options...
attock Posted September 4, 2009 Share Posted September 4, 2009 Replace: $sql4 = "SELECT * FROM Login WHERE username LIKE '$username';"; To: $sql4 = "SELECT * FROM Login"; Now it will display all users from Login table. Quote Link to comment Share on other sites More sharing options...
Zoroaster Posted September 4, 2009 Author Share Posted September 4, 2009 No that displayed only the last user (the one with the highest ID) Quote Link to comment Share on other sites More sharing options...
SilveR316 Posted September 4, 2009 Share Posted September 4, 2009 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>"; } Quote Link to comment Share on other sites More sharing options...
Zoroaster Posted September 4, 2009 Author Share Posted September 4, 2009 <?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? Quote Link to comment Share on other sites More sharing options...
SilveR316 Posted September 4, 2009 Share Posted September 4, 2009 Formatting how the usernames are displayed is HTML's job. You can add a quick line break with: echo "<br />"; A link can be done like this. echo "<a href=''>$username</a>"; Quote Link to comment Share on other sites More sharing options...
Zoroaster Posted September 4, 2009 Author Share Posted September 4, 2009 Yeah but that would just link all the usernames as one link and also just add a break under or above all the usernames. Not between the usernames. Quote Link to comment Share on other sites More sharing options...
SilveR316 Posted September 4, 2009 Share Posted September 4, 2009 I'm not sure what you want exactly. Can you post an example of how you want them to look like? Quote Link to comment Share on other sites More sharing options...
Zoroaster Posted September 4, 2009 Author Share Posted September 4, 2009 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? Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 <?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 />' } ?> Quote Link to comment Share on other sites More sharing options...
Zoroaster Posted September 4, 2009 Author Share Posted September 4, 2009 Great, thanks. Straight to the point - that's how I like it Thank you. 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.