Jump to content

problem showing values


DEVILofDARKNESS

Recommended Posts

Hi, this code only shows one row from the database and I wnated to show everyone.

 

<?php
session_start();
require_once 'login-check.php';
    /*DATABASE SETTINGS */
$userid = $_SESSION['userid'];
?>
<html>
<head>
<title>Cryptoworld</title>
<meta name="author" content="Kruptein">
</head>
<body>
<center>
Dit is een lijst met alle gebruikers.<p>
<table border="1">
<tr>
<td>User Name</td><td>Challenges Solved</td></tr>
<?php
$query = "SELECT * FROM users";
$result = mysql_query($query);
$user = mysql_fetch_assoc($result);
$query = "SELECT COUNT(DISTINCT crypto_id) FROM solved";
$result = mysql_query($query);
list($ammount) = mysql_fetch_row($result);
echo "<tr><td>" . $user['user_name'] . "</td><td>" . $ammount . "</td></tr>"; 
?>
</table>
<p><hr><p>
<a href="/login.php">Login</a> -- <a href="/logout.php">Logout</a> -- <a href="/register.php">Register</a> -- <a href="/index.php">Index</a> -- <a href="/stats.php">Stats</a>
</center>
</body>
</html>

Link to comment
Share on other sites

I would presume it is because you aren't looping anything.  Are you looking at getting the Username and then Amount for each user?

 

If so, why don't you do just one query and combine them with a join?  Then make a while loop on the result set in php.

Link to comment
Share on other sites

im not 100% on this but try

 

<?php
$count = 0;
$query = mysql_query("SELECT COUNT(DISTINCT crypto_id) FROM solved") or die(mysql_error());
list($ammount) = mysql_fetch_row($query); 
while ($user = mysql_fetch_object($query)) 
{ 
if ($count!=0){echo "";}
echo "<tr><td>$user->user_name</tr></td><tr><td>$ammount</tr></td>"; 
$count++; 
}
?>

Link to comment
Share on other sites

Ok I changed it but it still doesn't work.

And I had to do a second query because I don't know how to make a SELECT COUNT(DISTINCT) in an inner join.

 

<?php
session_start();
require_once 'login-check.php';
          /*DATABASE SETTINGS */
$userid = $_SESSION['userid'];
?>
<html>
<head>
<title>Cryptoworld</title>
<meta name="author" content="Kruptein">
</head>
<body>
<center>
Dit is een lijst met alle gebruikers.<p>
<table border="1">
<tr>
<td>User Name</td><td>Challenges Solved</td></tr>
<?php
$query = "SELECT users.*,solved.* FROM users INNER JOIN solved ON solved.user_id = users.user_id";
$result = mysql_query($query);
while($user = mysql_fetch_assoc($result)) {
$usersid = $user['user_id'];
$query = "SELECT COUNT(DISTINCT crypto_id) FROM solved WHERE user_id = '$usersid'";
$result = mysql_query($query);
list($ammount) = mysql_fetch_row($result);
echo "<tr><td>" . $user['user_name'] . "</td><td>" . $ammount . "</td></tr>"; 
}
?>
</table>
<p><hr><p>
<a href="/login.php">Login</a> -- <a href="/logout.php">Logout</a> -- <a href="/register.php">Register</a> -- <a href="/index.php">Index</a> -- <a href="/stats.php">Stats</a>
</center>
</body>
</html>

 

EDIT: I Also tried the one from jamesxg1 but that only showed me the table header, no rows from the database

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.