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
https://forums.phpfreaks.com/topic/153169-problem-showing-values/
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++; 
}
?>

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

Can't anybody help me?

I have a table users (user_id,user_name)

And I have a table solved (user_id,crypto_id)

 

I want to have a table with left the username and right the COUNT(DISTINCT crypto_id) From solved.

This should be orderd on that count DESC???

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.