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.

The Database Forum


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



Reply
Old 09-08-2005, 05:15 PM sql question
Experienced Talker

Posts: 38
Location: Holland
Trades: 0
hey

i like to know how i can store this result:

PHP Code:
<?php
$sql 
"SELECT count(*) as cnt, rank
        FROM members
        GROUP BY rank"
;

$result mysql_query($sql);

while(
$row mysql_fetch_assoc($result)) {
  echo 
$row['rank']."  = ".$row['cnt']."<br>";
}
?>
the code works nice, it give me the amounts of rank from the database for each different rank. But how can i store these results into variables instead of writing them down?

and how can i request them again? for later in the coding?
excalibur112 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-08-2005, 06:33 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Probably best thing to do is read them all into a big array:

PHP Code:
<?php
$sql 
"SELECT count(*) as cnt, rank
        FROM members
        GROUP BY rank"
;

$result mysql_query($sql);

$rankdata = Array();

while(
$row mysql_fetch_assoc($result)) {
  
$rankdata[] = $row;
}

//Stuff here

//More stuff here.....


//Much later in the script:

echo $rankdata[5]['rank'];

echo 
$rankdata[1]['cnt'];


?>
$rankdata[n]['rank'] gives you the rank for the nth row of the database result, same for 'cnt'.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 09-09-2005, 03:15 AM
Experienced Talker

Posts: 38
Location: Holland
Trades: 0
hey

thanx oberon that really helped me out
... you're smart

greets me
excalibur112 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to sql 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.11509 seconds with 12 queries