Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

PHP/SQL ORDER BY Problems =S


  • This topic is locked This topic is locked

#1
Linden

Linden

    Member

  • Member
  • PipPip
  • 57 posts
Okay, I am working on a script that will display a table which shows peoples characters and their honor.

I want the results to be a kind of Ranking board and the person with the most honor points is first and so on.
Buuttt, me being a php/sql nub has its let downs :).

Problem part of the script so far:
$result = mysql_query("SELECT * FROM characters ORDER BY name LIMIT 0, 50");

echo "<table border='1'>
<tr>
<th>Name</th>
<th>Login</th>
<th>Security Level</th>
<th>Banned</th>
<th>Last Login</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>honorPoints</th>
<th>5</th>
</tr>";

while($row = mysql_fetch_array($result))	 /* <--- Line 32   */
  {
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['race'] . "</td>";
  echo "<td>" . $row['class'] . "</td>";
  echo "<td>" . $row['gender'] . "</td>";
  echo "<td>" . $row['level'] . "</td>";
  echo "<td>" . $row['online'] . "</td>";
  echo "<td>" . $row['playedtime'] . "</td>";
  echo "<td>" . $row['publicNote'] . "</td>";
  echo "<td>" . $row['guildid'] . "</td>";
  echo "<td>" . $row['honorPoints'] . "</td>";
  echo "<td>" . $row['killsLifeTime'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

I just want the top 50 players listed.

Problems:

When I run it, it has some problem with

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mounted-storage/home61c/sub007/sc38326-TTKC/www/honor.php on line 32


How can I make it so it displays a list of numbers at the start of the table descending from 1 > 50 IE Ranking the players.

How can I make the First player bold, font size something like 32, second player bold, font size something like 27 and out line the top 3 players?

I'm not really sure about editing appearance of the results individually as you can see :).

Any help is much appreciated!! :)

Thanks so much guys,

-Linden
  • 0

Advertisements


#2
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 33,101 posts
First things first. The error you get usually means that you misspelled something in the query.
Try the command below. The error should give you some more useful information.
mysql_query ("SELECT * FROM characters ORDER BY name LIMIT 0, 50"') or die ('Error: '.mysql_error ());
To number the lines and highlight the first few, you can add a counter that gets increased every time the loop runs.
I'll probably get shot if I suggest using a for ($i = 1; $<=50;$i++) loop, but you know exactly how many you want to display and you can simply add a line like this one
echo "<td>" . $i . "</td>";
to get the lines numbered.
Next you can add conditional statements like
if ($i==1) { 
  <STYLE="font-size: 32px; font-weight: bold;">
  }
after the <tr> tag to highlight the first few.
  • 0

#3
Linden

Linden

    Member

  • Topic Starter
  • Member
  • PipPip
  • 57 posts
Thanks heaps :). The problem was the order I had the things listed >_>.

Now everything is how I want, I just need a little more help :).

I want to arrange the info by adding 3 tables together. I've tried:

$honor1 = $row['honorPoints']+$row['honorToday']+$row['honorYesterday'];
$result = mysql_query("SELECT * FROM `characters` ORDER BY '$honor1' DESC LIMIT 3,47");

but it didn't work :). Any Ideas?

Thanks :).

--Linden
  • 0

#4
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 33,101 posts
I'm not that experienced with MySQL, but I don't think that you can do that.

I'm afraid you'll have to query before you can start adding.

But maybe someone else knows better.
  • 0

#5
Linden

Linden

    Member

  • Topic Starter
  • Member
  • PipPip
  • 57 posts
Thanks heaps :).
Any one else? that can help?
  • 0

#6
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 33,101 posts
For lack of attention continued here:

http://www.geekstogo...ms-t182007.html

Closing this one.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP