Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a function like this:

function searchSingleUrlGraph($mysql){
    $query="SELECT * FROM `dailydata` WHERE `userid`='".$_SESSION['userdata']['userid']."' AND `url`='faboolis.com'";
    $HTML='[';
    $result=$mysql->query($query);
        while($row=$result->fetch_assoc()){
            $HTML .= "[
                        ['".$row['date']."',".$row['fblikes']."],
                        ['".$row['date']."',".$row['fbshares']."],
                    ],";
        }
    $HTML .=']';
    return $HTML;
}   

the result I want is this:

[[['Jun 4',224],['Jun 5',34],],[['Jun 4',220],['Jun 5',30],],];

but right now Im getting:

[[['Jun 4',224],['Jun 4',34],],[['Jun 5',220],['Jun 5',30],],];

I know there is an easy solution I'm just brain dead right now and its driving me crazy.

share|improve this question
    
Are you trying to build a JSON array? Am I missing something here, as what you want and what you are getting look the same to me. –  Mike Brant Jun 5 '13 at 22:24
    
No, im using this data to construct a graph with javascript. I want the dates different. look at the dates and you will see what I mean. –  Johnny Kay Jun 5 '13 at 22:29
    
however it IS a JSON Array –  steven Jun 5 '13 at 22:30
    
so you should build a simple php array and then do json_encode($array) –  steven Jun 5 '13 at 22:31
    
Isn't your desired output going to be duplicates/redundant? Jun 4, 224 fblikes / Jun 4, 224 fblikes and Jun 5, 34 fbshares / Jun 5, 30 fbshares. That doesn't make sense. –  Sean Jun 5 '13 at 22:43

1 Answer 1

The simplest solution would be to just use 2 while loops.

while($row=$result->fetch_assoc()){
    //process likes
}
$result->data_seek(0); //go back to the beginning.
while($row=$result->fetch_assoc()) {
    //process shares
}
share|improve this answer
    
Tried that, its a no go. –  Johnny Kay Jun 5 '13 at 22:55
    
I actually tried a variation of the $result->data_seek(0) and it worked fine. Thanks. –  Johnny Kay Jun 19 '13 at 15:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.