TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-10-2008, 05:21 PM   #1 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default a question , alittle of math here

hi
whats the error here =>

PHP Code:
$web="SELECT SUM(`rate`) / COUNT(`rate`) from `rate`";
$tuto=mysql_query($web) or die('Database error: ' mysql_error());
$mas=mysql_fetch_array($tuto);
echo
"The Rating of this tutorial is : ".$mas['rate']."<br><br>"
it douesnt show the result :s
__________________

Last edited by webtuto : 01-10-2008 at 06:28 PM.
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-10-2008, 05:28 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

You mean in SQL or what? If SQL is your case...(MySQL for this matter):

Code:
SELECT SUM(column_name)/COUNT(column_name)
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-10-2008, 05:32 PM   #3 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

thanks i did it but how to show to result ?
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-10-2008, 05:44 PM   #4 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

Please, you're going to have to provide more details. Your messages are vague at best. Also, please read some of the links I've provided in replies to your other threads.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 01-10-2008, 06:23 PM   #5 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

it gives this error
Database error: Unknown column 'rate' in 'field list'

even if in the table "rate" there is a column named "rate"
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-10-2008, 06:49 PM   #6 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

You need to use an ALIAS on that result, e.g.
Code:
SELECT SUM(`rate`) / COUNT(`rate`) AS average_rate from `rate`
Refer to the alias average_rate in your PHP code, i.e. $mas['average_rate'].

This is why we ask you to be more specific; the query xenon provided by example works fine as-is in MySQL, but not if you want to return the value in PHP.

I would also suggest, if you're retrieving only one column from a resultset, use mysql_result() instead of one of the mysql_fetch_* functions. You don't need an array, there is only a single row and single column result output.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 01-10-2008, 06:58 PM   #7 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

yeah i solve it thanks
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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


All times are GMT. The time now is 12:40 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design