PDA

View Full Version : Hello i am trying to make a topten list


due
08-17-2006, 02:17 AM
Hello the top ten list i got made isnt showing

<?php
mysql_connect( 'Localhost', 'xxx', 'xxx' );
mysql_select_db( 'xxx' );

$sql = "SELECT ID, username, worth FROM `users` ORDER BY Money DESC LIMIT 0,10";

if ($top10sql = mysql_query($sql))
{
echo '<table border="0" align="center" width="400" cellspacing="2" cellpadding="2">
<tr>
<td> Username </td>
<td> Networth </td>
<td> ID </td>
</tr>';
while ($disp_users = mysql_fetch_assoc($top10sql))
{
echo ' <tr>';
echo ' <td>' . $disp_users['username'] . '</td>';
echo ' <td>' . $disp_users['worth'] . '</td>';
echo ' <td>' . $disp_users['ID'] . '</td>';
echo ' </tr>';
}
echo '</table>';
}
?>
anyone know why that wont show

mfhJoe
08-17-2006, 09:18 AM
I think it was the if statement that was causing the problem. The code below should work :).


<?php
mysql_connect( 'Localhost', 'xxx', 'xxx' );
mysql_select_db( 'xxx' );

$sql = "SELECT ID, username, worth FROM `users` ORDER BY Money DESC LIMIT 0,10";

echo '<table border="0" align="center" width="400" cellspacing="2" cellpadding="2">
<tr>
<td> Username </td>
<td> Networth </td>
<td> ID </td>
</tr>';
while ($disp_users = mysql_fetch_assoc($top10sql))
{
echo ' <tr>';
echo ' <td>' . $disp_users['username'] . '</td>';
echo ' <td>' . $disp_users['worth'] . '</td>';
echo ' <td>' . $disp_users['ID'] . '</td>';
echo ' </tr>';
}
echo '</table>';
?>

due
08-17-2006, 02:07 PM
I came to another problem it shows the table now
<?php
mysql_connect( 'Localhost', 'xxx', 'xxx' );
mysql_select_db( 'xxx' );

$sql = "SELECT ID, username, worth FROM `users` ORDER BY Money DESC LIMIT 0,10";

echo '<table border="0" align="center" width="400" cellspacing="2" cellpadding="2">
<tr>
<td> Username </td>
<td> Networth </td>
<td> ID </td>
</tr>';
while ($disp_users = mysql_fetch_assoc($top10sql))
{
echo ' <tr>';
echo ' <td>' . $disp_users['username'] . '</td>';
echo ' <td>' . $disp_users['worth'] . '</td>';
echo ' <td>' . $disp_users['ID'] . '</td>';
echo ' </tr>';
}
echo '</table>';
?>
It gives me an error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\index.php on line 45

arne2
08-17-2006, 02:10 PM
You used two different variables $top10sql and $sql

change
while ($disp_users = mysql_fetch_assoc($top10sql))
into:
while ($disp_users = mysql_fetch_assoc($sql))

due
08-17-2006, 02:17 PM
Still didnt work <?php
mysql_connect( 'Localhost', 'root', '' );
mysql_select_db( 'game' );

$sql = "SELECT ID, username, worth FROM `users` ORDER BY Money DESC LIMIT 0,10";

echo '<table border="0" align="center" width="400" cellspacing="2" cellpadding="2">
<tr>
<td> Username </td>
<td> Networth </td>
<td> ID </td>
</tr>';
while ($disp_users = mysql_fetch_assoc($sql))
{
echo ' <tr>';
echo ' <td>' . $disp_users['username'] . '</td>';
echo ' <td>' . $disp_users['worth'] . '</td>';
echo ' <td>' . $disp_users['ID'] . '</td>';
echo ' </tr>';
}
echo '</table>';
?>
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\index.php on line 45

Glass Casket
08-17-2006, 02:32 PM
Are you sure that you have all your variables name in your query are written correctly?

due
08-17-2006, 02:45 PM
yes they are
<?

// Initialize session data
session_start();

// Don't allow users to log in twice
if( !empty($_SESSION['id']) ) {
header( 'Location: http://localhost/go_login.php' );
exit();
}

?>
<html>
<head>
<title>Thug Money</title>
<style type="text/css">
td{
background-color: blue;
}
</style>
</head>
<body bgcolor="navy" text="#ffffff">
<div align="center"><img src="/images/logo.png" border="1">
</div>
<div align="left"><form action="login.php" method="post">
Username:<br> <input name="username" id="username" type="text" maxlength="30" /><br />
Password: <br><input name="password" id="password" type="password" /><br />
<input type="submit" value="Log In" />
</form></div>

<br>

<?php
mysql_connect( 'Localhost', sss', 'sss' );
mysql_select_db( 'sss' );

$sql = "SELECT id, username, worth FROM `users` ORDER BY Money DESC LIMIT 0,10";

echo '<table border="0" align="center" width="400" cellspacing="2" cellpadding="2">
<tr>
<td> Username </td>
<td> Networth </td>
<td> ID </td>
</tr>';
while ($disp_users = mysql_fetch_assoc($sql))
{
echo ' <tr>';
echo ' <td>' . $disp_users['username'] . '</td>';
echo ' <td>' . $disp_users['worth'] . '</td>';
echo ' <td>' . $disp_users['id'] . '</td>';
echo ' </tr>';
}
echo '</table>';
?>

guelphdad
08-17-2006, 02:50 PM
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\index.php on line 45
So is line 45 in the code you've shown or not? which is line 45?

due
08-17-2006, 02:54 PM
while ($disp_users = mysql_fetch_assoc($sql))

arne2
08-17-2006, 03:31 PM
You forgot mysql_query (and i didn't see it)
use this :
while ($disp_users = mysql_fetch_assoc(mysql_query($sql)))

due
08-17-2006, 03:36 PM
oh ya
thanks

due
08-17-2006, 03:37 PM
still error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\index.php on line 45

Mwnciau
08-17-2006, 04:12 PM
You havent done the mysql_query()...

due
08-17-2006, 04:51 PM
how would i do that
?

Mwnciau
08-17-2006, 07:05 PM
$sql = mysql_query("SELECT ID, username, worth FROM `users` ORDER BY Money DESC LIMIT 0,10");

due
08-17-2006, 10:36 PM
ok i got it
does anyone got any ebook or anything i can learn more php even sites :)

Mwnciau
08-17-2006, 11:20 PM
for starting out i reccomend this (http://www.amazon.com/gp/product/0321186486/104-1177209-4331129?v=glance&n=283155) book

due
08-17-2006, 11:24 PM
see i want a website or ebook wich is a book u read on ur pc :D

Mwnciau
08-17-2006, 11:33 PM
TBH book is way easier, that has an index etc and you can lookup things you are unsure on.

due
08-17-2006, 11:40 PM
well i cant buy it as i am 15 and cant get a job so thats why i want an ebook or sites :)

Mwnciau
08-17-2006, 11:44 PM
well im 14 and I bought it last year :rolleyes:
and I did search for online ones for about a month, and found nothing compared to that book

due
08-17-2006, 11:45 PM
yes but i cant go and waste money on a book my mom wont let me so i am gonna buy ps2 :)