Jump to content

stats prob


DEVILofDARKNESS

Recommended Posts

If I open this code in my webbrowser it always get stuck. :S

all the other pages don't

 

it did work until I added $cattop['ammount']

 

<?php
#leden
#gedichten
#gedichten / lid
#top 10 posters
#top 10 categories
#...

/* DATABASE SETTINGS */

$query = "SELECT COUNT(user_id) FROM users";
$result = mysql_query($query);
list($users) = mysql_fetch_row($result);  # Number of users

$query = "SELECT COUNT(poem_id) FROM poems";
$result = mysql_query($query);
list($poems) = mysql_fetch_row($result);  #  Number of poems

$ppu = $poems / $users;                   # $ppu = $poems per user

$query = " SELECT user_name, ammount, (
SELECT count( * ) + 1
FROM users b
WHERE a.ammount < b.ammount
) AS rank
FROM users a
ORDER BY rank
LIMIT 0 , 10 ";
$ress = mysql_query($query);
while($usertop = mysql_fetch_array($ress)) {

$query = " SELECT category_name, ammount, (
SELECT count( * ) + 1
FROM categories b
WHERE a.ammount < b.ammount
) AS rank
FROM categories a
ORDER BY rank
LIMIT 0 , 10 ";
$res = mysql_query($query);
while($cattop = mysql_fetch_array($res)) {
?>
<html dir="ltr">
    <head>
        <title>STATISTIEKEN</title>
        <link href="../../standard.css" type="text/css" rel="stylesheet" />
<link href='dichtkunst.css' type='text/css' rel="stylesheet" />
    </head>
    <body>
        <table class="look" height="100%" width="100%" border="1">
            <tbody>
                <tr>
                    <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe>
                    </td>
                    <td><center>
<table border="0"><tr><td colspan="2"><b>STATISTIEKEN</b></td></tr>
<tr><td>Aantal gebruikers:</td><td><b><?php echo $users; ?></b></td></tr>
<tr><td>Aantal gedichten:</td><td><b><?php echo $poems; ?></b></td></tr>
<tr><td>Aantal gedichten per gebruiker:</td><td><b><?php echo $ppu; ?></b></td></tr>
<tr><td>Top 10 gebruikers:</td><td><b><?php echo "{$usertop['rank']} | {$usertop['user_name']} | {$usertop['ammount']}"; ?>
</b></td></tr>
<tr><td>Top 10 categorien:</td><td><b><?php echo "{$cattop['rank']} | {$cattop['category_name']} | {$cattop['ammount']}"; ?></b></td></tr>
</table>
<?php
}
}
?>
                    </center></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/148371-stats-prob/
Share on other sites

sorry I'm just getting irritated about that st*pid bug. it wasn't the meaning to react that way on u :),

The problem is just if I use code 1 for the site (without the cattegories)

it works fast

 

if I use code 2 with the catteogries, the browser get stuck and I have to end the proces.

I want to know what the source from that bug is and I wished somebody could help me.

 

code 1:

<?php
#leden
#gedichten
#gedichten / lid
#top 10 posters
#top 10 categories
#...

/*DATABASE SETTINGS */

$query = "SELECT COUNT(user_id) FROM users";
$result = mysql_query($query);
list($users) = mysql_fetch_row($result);  # Number of users

$query = "SELECT COUNT(poem_id) FROM poems";
$result = mysql_query($query);
list($poems) = mysql_fetch_row($result);  #  Number of poems

$ppu = ($poems / $users);                   # $ppu = $poems per user

$query = " SELECT user_name, ammount, (
SELECT count( * ) + 1
FROM users b
WHERE a.ammount < b.ammount
) AS rank
FROM users a
ORDER BY rank
LIMIT 0 , 10 ";
$ress = mysql_query($query);
while($usertop = mysql_fetch_array($ress)) {

?>
<html dir="ltr">
    <head>
        <title>STATISTIEKEN</title>
        <link href="../../standard.css" type="text/css" rel="stylesheet" />
<link href='dichtkunst.css' type='text/css' rel="stylesheet" />
    </head>
    <body>
        <table class="look" height="100%" width="100%" border="1">
            <tbody>
                <tr>
                    <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe>
                    </td>
                    <td><center>
<table border="0"><tr><td colspan="2"><b>STATISTIEKEN</b></td></tr>
<tr><td>Aantal gebruikers:</td><td><b><?php echo $users; ?></b></td></tr>
<tr><td>Aantal gedichten:</td><td><b><?php echo $poems; ?></b></td></tr>
<tr><td>Aantal gedichten per gebruiker:</td><td><b><?php echo $ppu; ?></b></td></tr>
<tr><td>Top 10 gebruikers:</td><td><b><?php echo "{$usertop['rank']} | {$usertop['user_name']} | {$usertop['ammount']}"; ?>
</b></td></tr>
</table>
<?php
}
?>
                    </center></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

 

code 2:

<?php
#leden
#gedichten
#gedichten / lid
#top 10 posters
#top 10 categories
#...

/*DATABASE SETTINGS */

$query = "SELECT COUNT(user_id) FROM users";
$result = mysql_query($query);
list($users) = mysql_fetch_row($result);  # Number of users

$query = "SELECT COUNT(poem_id) FROM poems";
$result = mysql_query($query);
list($poems) = mysql_fetch_row($result);  #  Number of poems

$ppu = ($poems / $users);                   # $ppu = $poems per user

$query = " SELECT user_name, ammount, (
SELECT count( * ) + 1
FROM users b
WHERE a.ammount < b.ammount
) AS rank
FROM users a
ORDER BY rank
LIMIT 0 , 10 ";
$ress = mysql_query($query);
while($usertop = mysql_fetch_array($ress)) {

$query = " SELECT category_name, ammount, (
SELECT count( * ) + 1
FROM categories b
WHERE a.ammount < b.ammount
) AS rank
FROM categories a
ORDER BY rank
LIMIT 0 , 10 ";
$res = mysql_query($query);
while($cattop = mysql_fetch_array($res)) {
?>
<html dir="ltr">
    <head>
        <title>STATISTIEKEN</title>
        <link href="../../standard.css" type="text/css" rel="stylesheet" />
<link href='dichtkunst.css' type='text/css' rel="stylesheet" />
    </head>
    <body>
        <table class="look" height="100%" width="100%" border="1">
            <tbody>
                <tr>
                    <td width="10%" height="100%"><iframe class="frames" src="../../functieknoppen/functieknoppendichtkunst.htm" frameborder="0" width="100%" height="100%" scrolling="no"></iframe>
                    </td>
                    <td><center>
<table border="0"><tr><td colspan="2"><b>STATISTIEKEN</b></td></tr>
<tr><td>Aantal gebruikers:</td><td><b><?php echo $users; ?></b></td></tr>
<tr><td>Aantal gedichten:</td><td><b><?php echo $poems; ?></b></td></tr>
<tr><td>Aantal gedichten per gebruiker:</td><td><b><?php echo $ppu; ?></b></td></tr>
<tr><td>Top 10 gebruikers:</td><td><b><?php echo "{$usertop['rank']} | {$usertop['user_name']} | {$usertop['ammount']}"; ?>
</b></td></tr>
<tr><td>Top 10 categorien:</td><td><b><?php echo "{$cattop['rank']} | {$cattop['category_name']} | {$cattop['ammount']}"; ?></b></td></tr>
</table>
<?php
}
}
?>
                    </center></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778967
Share on other sites

Might be way off here but do you really need to run that query inside the while loop?

 

<?php

$query = " SELECT category_name, ammount, (
SELECT count( * ) + 1
FROM categories b
WHERE a.ammount < b.ammount
) AS rank
FROM categories a
ORDER BY rank
LIMIT 0 , 10 ";

?>

 

It doesn't seem to draw any information from the other query (or it seems to me). So your running it every loop of the above while loop when it looks like it doesn't have to (again I maybe way off, if so sorry).

Link to comment
https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-778984
Share on other sites

Okay, lets say it works,

 

I still have one problem.

the statistic page generates a page wich lists all top 10 users, but there is one problem.

IF you visit the site, you will see it  http://4ade.uuuq.com/statistics.php

 

the problem is that I generate a while loop in a table, the while loop orders all the top ten users,

and should place them in a next row in the same table, but it generates it in a next row in a new table.

 

how can I solve this?

this is the main code:

<?php
$query = "SELECT COUNT(user_id) FROM users";
$result = mysql_query($query);
list($users) = mysql_fetch_row($result);  # Number of users

$query = "SELECT COUNT(poem_id) FROM poems";
$result = mysql_query($query);
list($poems) = mysql_fetch_row($result);  #  Number of poems

$ppu = ($poems / $users);                   # $ppu = $poems per user

$query = " SELECT user_name, ammount, (
SELECT count( * ) + 1
FROM users b
WHERE a.ammount < b.ammount
) AS rank
FROM users a
ORDER BY rank
LIMIT 0 , 10 ";
$ress = mysql_query($query);
while($usertop = mysql_fetch_array($ress)) {
?>

<table border="0"><tr><td colspan="2"><b>STATISTICS</b></td></tr>
<tr><td>Ammount of users:</td><td><b><?php echo $users; ?></b></td></tr>
<tr><td>Ammount of poems:</td><td><b><?php echo $poems; ?></b></td></tr>
<tr><td>Ammount poems / user:</td><td><b><?php echo $ppu; ?></b></td></tr>
<tr><td>Top 10 users:</td><td><b><?php echo "{$usertop['rank']} | {$usertop['user_name']} | {$usertop['ammount']}"; ?>
</b></td></tr>
</table><?php } ?>

Link to comment
https://forums.phpfreaks.com/topic/148371-stats-prob/#findComment-780571
Share on other sites

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.