Jump to content

Array producing extra data I don't want


siwelis

Recommended Posts

I have this code...

$prodimg = array();
$prods = mysql_query($prods) or die ("<p>Sorry, an error has occurred!</p>");
while($row = mysql_fetch_assoc($prods))
{
stripslashes(extract($row));
while ($tagArray[$prod_id] > 1){
echo "<br />".$tagArray[$prod_id];
$prodoptions.= $prod_name."  <select name=\"".$tagArray[$prod_id]."_prodid".$prod_id."\">".$imgoptions."</select><br /><br />";
$prodimg[] = $prod_img;
$prodimg[$prod_img] = $tagArray[$prod_id];
$tagArray[$prod_id]--;
}
}

 

For some reason when I echo it, it comes out like this:

8x10.png - 0

2 - 8x10.png

8x10.png - 1

8x10.png - 2

8x10.png - 3

4-4x5.png - 4

2 - 4-4x5.png

2-5x7.png - 5

2 - 2-5x7.png

2-5x7.png - 6

2-5x7.png - 7

2-5x7.png - 8

8wall.png - 9

2 - 8wall.png

8wall.png - 10

8wall.png - 11

8wall.png - 12

8wall.png - 13

8wall.png - 14

8wall.png - 15

8wall.png - 16

 

print_r

Array ( [0] => 8x10.png [8x10.png] => 2 [1] => 8x10.png [2] => 8x10.png [3] => 8x10.png [4] => 4-4x5.png [4-4x5.png] => 2 [5] => 2-5x7.png [2-5x7.png] => 2 [6] => 2-5x7.png [7] => 2-5x7.png [8] => 2-5x7.png [9] => 8wall.png [8wall.png] => 2 [10] => 8wall.png [11] => 8wall.png [12] => 8wall.png [13] => 8wall.png [14] => 8wall.png [15] => 8wall.png [16] => 8wall.png ) 

 

I can't figure out where the results in BOLD are coming from. Does anyone have any clue?

Link to comment
https://forums.phpfreaks.com/topic/199329-array-producing-extra-data-i-dont-want/
Share on other sites

Figured it out... it should be:

 

$prodimg = array();

$prods = mysql_query($prods) or die ("<p>Sorry, an error has occurred!</p>");

while($row = mysql_fetch_assoc($prods))

{

stripslashes(extract($row));

while ($tagArray[$prod_id] > 1){

echo "<br />".$tagArray[$prod_id];

$prodoptions.= $prod_name."  <select name=\"".$tagArray[$prod_id]."_prodid".$prod_id."\">".$imgoptions."</select><br /><br />";

$prodimg[] = $prodimg[$prod_img] = $tagArray[$prod_id];

$tagArray[$prod_id]--;

}

}

 

might even be able to take it a step further...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.