0

Hi all I am request the following data from the database (image_id and description).
I need to put each of them in a separate arrays and then echo out contents of both arrays

I have tried array_push and implode without success. Any assistance would we appreciated.

Thanks in advance
D

    mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
    mysql_select_db("$db_name")or die("cannot select db");

    $sql ="  SELECT
      web_customised_partners.image_id,
      web_customised_partners_id,
      description,
                  web_images.image_id,
                  web_images.image_filename
        FROM
      web_customised_partners
         LEFT JOIN
      web_images ON web_images.image_id = web_customised_partners.image_id ";
      $result=mysql_query($sql);
        ?>
     <div class="content">
        <div id="about_customised_partner">
            <div class="inner">
                <?php
                  while($row = mysql_fetch_array($result))
                     {

                         $image_value = array();
                         array_push ($image_value,$row['image_id']);
                         print_r($image_value);

                         $description_value = array();
                         array_push ($description_value,$row['description']);
                         print_r($description_value);
                      }
                ?>
            </div>
         </div>
      </div>
3
Contributors
3
Replies
28
Views
4 Years
Discussion Span
Last Post by davidjennings
0

Move these:

$image_value = array();
$description_value = array();

outside the while statement, otherwise the array resets after each loop. Also you can avoid the use of array_push() by writing:

while($row = mysql_fetch_array($result))
{
    $image_value[] = $row['image_id'];
    $description_value[] = $row['description'];
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.