tags:

views:

23

answers:

2

Hello there - is it possible to add custom data to the results so it can be used the same as the $results being returned?

ie i'd like to add a random number to the results;

$recordSet = mysql_query($sql,$this->conn);
$results = array();
while ($row = mysql_fetch_assoc($recordSet)){
    $results[]=$row;
    /// add to results[] a custom field and value, ie 'random' = 1000
}
return $results;

and then i can use it the same as;

foreach($results as $res) $title = $res['title'], $random = $res['random'];

?

+1  A: 

Why not?

while ($row = mysql_fetch_assoc($recordSet)){
    $row['random'] = rand() * 1000;
    $results[] = $row;    
}
n1313
hey n1313 - that doesn't get returned as part of the $results array. think i need somink like 'add to results array'; array( 'random' => '1000'), just looking again now
daniel Crabbe
Unless your question is wrong or you're doing something weird, this is the correct answer. What's going astray?
Bart van Heukelom
you're right - sorry had a typo! Cheers nI3I3!
daniel Crabbe
A: 

Add the random values in $result array

 
$row['random'] = $random_val # calculated random values 1000  

pavun_cool
adding it to the array is where im stuck!
daniel Crabbe
You need to add this statement ( $row['random']=$random_val ) in your while loop ,before adding $row in $result Array
pavun_cool