Jump to content

Selecting data and ordering it from a mysql data base!


Freid001

Recommended Posts

Hi I am trying to select and order data/numbers from a colum in a mysql data base however i run the code and it returns no value just a blank page no errors or any thing so i think the code is working right but then it returns no result? Please help thanks

 

Here is the code:

 

<?php

$host= "XXXXXX";

$mysql_user = "XXXXXX";

$mysql_password = "XXXXXX";

$mysql_database = "XXXXXXX";

 

$connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server.");

mysql_select_db($mysql_database) or die ("Unable to select requested database.");

 

$row = mysql_fetch_assoc( mysql_query( "SELECT XP FROM Game ORDER BY number DESC LIMIT 1" ) );

$number = mysql_result(mysql_query("SELECT XP FROM Game ORDER BY number DESC LIMIT 1"), 0);

 

echo "The the highest XP is $number";

 

?>

 

Link to comment
Share on other sites

echo "The the highest XP is $number";

Actually that's perfectly valid.

 

 

however i run the code and it returns no value just a blank page no errors or any thing so i think the code is working right but then it returns no result?

Do you see the "The the highest XP is" text? You may have errors disabled. Add at the top of your code:

 

ini_set('display_errors', 1);
error_reporting(E_ALL);

Link to comment
Share on other sites

Thanks this has given me a error now. However im not sure how to fix it?

 

error shown:

 

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /hosted/subs/ulmb.com/e/u/europeanwar/public_html/test/leader.php on line 15

 

code:

 

<?php

ini_set('display_errors', 1);error_reporting(E_ALL);

 

$host= "xxxxx";

$mysql_user = "xxxxxx";

$mysql_password = "xxxxxx";

$mysql_database = "xxxxx";

 

$connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server.");

mysql_select_db($mysql_database) or die ("Unable to select requested database.");

 

 

$query = "SELECT XP FROM Game ORDER BY number DESC LIMIT 1";

$result = mysql_query($query);

$row = mysql_fetch_assoc($result);

echo "The the highest XP is". $row['XP'];

 

 

?>

 

 

 

Link to comment
Share on other sites

Basically what is happening is that when you run the query you should get a resource stored in $result, but if there is an error int the query (which there is in your case) then it stores false in $result, which is why the error is telling you it has been given a boolean.

 

OK, so are you sure that your table is called Game (with a capital). Are you sure that you can sort by number?

 

Try $query = "SELECT * FROM Game"; first, then slowly add in other components (ie ORDER and LIMIT) to see what the problem is.

Link to comment
Share on other sites

OK

This works it gives me the xp for the person at the top of the data base but no further down?:

$query = "SELECT XP FROM Game";

$result = mysql_query($query);

$row = mysql_fetch_assoc($result);

echo "The the highest XP is". $row['XP'];

 

But when i add ORDER BY number:

 

$query = "SELECT XP FROM Game ORDER BY number";

$result = mysql_query($query);

$row = mysql_fetch_assoc($result);

echo "The the highest XP is". $row['XP'];

 

this happens :

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /hosted/subs/ulmb.com/e/u/europeanwar/public_html/test/leader.php on line 14

The the highest XP is

 

 

My sql Data base feild: The fild name is XP it is set to text , Collation Latin1_swedish_ci and Null is notnull

 

:'( :'( :'(

 

 

 

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.