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
Mysqli Query Question
Old 08-23-2010, 07:47 PM Mysqli Query Question
Novice Talker

Posts: 6
Trades: 0
PHP Code:
$Test = ("SELECT Test, SUM(IF(Test = 'Til', 1,0)) AS `T`, SUM(IF(Test = 'Sil', 1,0)) AS `S` FROM `Show` GROUP BY `Test`"); 

$get mysqli_query($mysqli$Test)or die("Error: ".mysqli_error($mysqli)); 

$gg mysqli_fetch_array($get); 

echo 
$gg['T']; 
echo 
$gg['S']; 
When I try something like this, I can get the correct result for the first sum, but after that, it reverts to 0. I was wondering how I could get this to work for both. Thanks again.
votter is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-24-2010, 10:52 AM Re: Mysqli Query Question
Banned

Posts: 408
Name: mushget
Trades: 0
try this code

select test, sum( case test when 'Til' then 1 else 0 end) as T,
sum(case test when 'Sil' then 1 else 0 end) as S
from test
group by test

Last edited by mushget; 08-24-2010 at 10:53 AM.. Reason: word wrong
mushget is offline
Reply With Quote
View Public Profile Visit mushget's homepage!
 
Old 08-24-2010, 05:55 PM Re: Mysqli Query Question
Novice Talker

Posts: 6
Trades: 0
That will get the first one, but then will display 0 for the next.
votter is offline
Reply With Quote
View Public Profile
 
Old 08-25-2010, 06:58 AM Re: Mysqli Query Question
Banned

Posts: 408
Name: mushget
Trades: 0
I have tested this code on mysql,It's ok.I can get the right result.
mushget is offline
Reply With Quote
View Public Profile Visit mushget's homepage!
 
Old 08-25-2010, 06:08 PM Re: Mysqli Query Question
Novice Talker

Posts: 6
Trades: 0
Are you ordering it or anything?
votter is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Mysqli Query Question
 

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.63729 seconds with 12 queries