0

I have the following function.

 return $this->_blockPhoto ( $selected_screenshots, $this->aDataEntry['author_id']); 

It requires that the variable $selected_screenshots is an array of values.

The problem is that I have to take the values from a mySQL look, that is reported below.

If there is only one value, everything works fine. But when there are more values in the DB, I cannot put all those values into the variable array.

In fact, since return $this->_blockPhoto ( $selected_screenshots, $this->aDataEntry['author_id']); is outside the mySQL loop, it gets only the first value of the loop.

So how do I store all the values from the mySQL loop into the variable? And not only the first value?

I tried to manually assign the array to the variable in the loop $selected_screenshots = array($qryrow1['media_id']); but it does not work and I do not think it has any sense :)

    $qry1="SELECT * FROM modzzz_articles_screenshots WHERE media_id='".$selected_screenshots_ID."' AND entry_id='".$this->aDataEntry['id']."'";
            $qryr1=mysql_query($qry1) or die("Error selecting: ".mysql_error());
                while($qryrow1 = mysql_fetch_array($qryr1)) {
                $selected_screenshots = array($qryrow1['media_id']);

} // END OF THE LOOK

          return $this->_blockPhoto ( $selected_screenshots, $this->aDataEntry['author_id']); 

Can anyone give me the solution, with code? I am really confused.

Thanks

0

2 Answers 2

1

Your code keeps overwriting $selected_screenshots with a new array each time. Instead, you want to append it:

$selected_screenshots = array();
while ($qryrow1 = mysql_fetch_array($qryr1)) {
    $selected_screenshots[] = $qryrow1['media_id'];
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can save all the mysql values by looping through your results and appending them to the end of $selected_screenshots to do this please look below. Right now you are just assigning $selected_screenshots one value and neglecting the other values, so $selected_screenshots is having the last value that mysql returns.

This is covered http://php.net/manual/en/language.types.array.php under the heading 'Creating/modifying with square bracket syntax'

Comments

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.