Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How do I get this result?
Old 09-21-2007, 12:27 PM How do I get this result?
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
I have found a great PHP script to rank my scores and have played around with some data in myPHPAdmin and it works as I hoped it would.

My next challenge is using it in PHP to extract the result. Heres the example code;

PHP Code:
$query="SELECT Sum(Score) As Rank, id FROM table WHERE id='2'"
The code only produces one result - as RANK - but I can't figure out how to get that now into a PHP variable. Any ideas much appreciated.

BTW - already tried mysql_fetch_array
scrobins is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-21-2007, 12:34 PM Re: How do I get this result?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
maybe try mysql_result(): http://us2.php.net/mysql_result
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-21-2007, 12:51 PM Re: How do I get this result?
Novice Talker

Posts: 14
Name: Dmitri
Trades: 0
true!
mysql_result()
should work.
Dknight is offline
Reply With Quote
View Public Profile
 
Old 09-21-2007, 01:29 PM Re: How do I get this result?
Average Talker

Posts: 23
Trades: 0
Code:
$query="SELECT Sum(Score) As Rank, id FROM table WHERE id='2'"; 
$result = (mysql_query($query));
$row = (mysql_fetch_array($result));
This will run the query and put the records into a variable called $row

then use $row['fieldname'] to get the information from the field.

fieldname being the name of the column in the table.
__________________

Please login or register to view this content. Registration is FREE
- My Site

Please login or register to view this content. Registration is FREE
- What is my ip address?
Creadiv is offline
Reply With Quote
View Public Profile Visit Creadiv's homepage!
 
Old 09-21-2007, 01:34 PM Re: How do I get this result?
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
Ok. The query is a little more complex than first stated so maybe that has something to do with it so here it is in its entirety;

PHP Code:
$query="SELECT count(*)+1 as Rank FROM (SELECT * FROM fav_blogs WHERE favScore > (SELECT sum(favScore) from fav_blogs where blogID='2') order by favScore desc) as Rankings";
$result=mysql_result($query,0) or die mysql_error(); 
But then I still get this unexpected T_STRING error occurring.

Am I missing some syntax in this?
scrobins is offline
Reply With Quote
View Public Profile
 
Old 09-21-2007, 01:40 PM Re: How do I get this result?
Average Talker

Posts: 23
Trades: 0
Your sql is either a little more advanced than what I am used to or a cluster of stuff that doesn't work, but I don't believe you need the single quotes around the number 2.
__________________

Please login or register to view this content. Registration is FREE
- My Site

Please login or register to view this content. Registration is FREE
- What is my ip address?
Creadiv is offline
Reply With Quote
View Public Profile Visit Creadiv's homepage!
 
Old 09-21-2007, 01:41 PM Re: How do I get this result?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
An unexpected T_STRING error means that you have a terminating string somewhere, you forgot a semi-colon in your code.

die is a function. die(mysql_error()); not die mysql_error();
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-21-2007, 01:42 PM Re: How do I get this result?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Creadiv View Post
Your sql is either a little more advanced than what I am used to or a cluster of stuff that doesn't work, but I don't believe you need the single quotes around the number 2.
For integers you don't need quotes, but it doesn't hurt to have them.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-21-2007, 01:50 PM Re: How do I get this result?
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
Cheers NullPointer. Changed the function syntax.

The error I get now is;

mysql_result(): supplied argument is not a valid MySQL result resource
scrobins is offline
Reply With Quote
View Public Profile
 
Old 09-21-2007, 02:54 PM Re: How do I get this result?
Average Talker

Posts: 23
Trades: 0
Most of the time that error means that you did not connect to the db or you search didn't have any results.
__________________

Please login or register to view this content. Registration is FREE
- My Site

Please login or register to view this content. Registration is FREE
- What is my ip address?

Last edited by Creadiv; 09-21-2007 at 02:56 PM..
Creadiv is offline
Reply With Quote
View Public Profile Visit Creadiv's homepage!
 
Reply     « Reply to How do I get this result?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.72599 seconds with 12 queries