0

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'];

?

2 Answers 2

4

Why not?

while ($row = mysql_fetch_assoc($recordSet)){
    $row['random'] = rand() * 1000;
    $results[] = $row;    
}
Sign up to request clarification or add additional context in comments.

2 Comments

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
Unless your question is wrong or you're doing something weird, this is the correct answer. What's going astray?
0

Add the random values in $result array

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

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.