Why array don't contain all times?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Why array don't contain all times?

Post by ljCharlie »

Can anyone tell why this doesn't work?

Code: Select all

<?php
	if ($totalRows_rsSection >0 && $pixID == ""){
		if ($numOfCells ==1){
			//echo "<br>";			
			echo '<table width="535" border="0" cellpadding="0" cellspacing="0">';
			$numbOfRows = 1;
			$numbCellsFilled = 1;
			}
		while($row_rsSection = mysql_fetch_assoc($rsSection)){
			if ($numbOfRows == 1){
				echo '<tr>';
				$numbOfRows = 0;
				}		
			$fileName = $row_rsSection["fileName"];
			$location = $row_rsSection["path"];
			$picID = $row_rsSection["imgID"];
			$sectID = $row_rsSection["sectionID"];
			if ($numbCellsFilled <= 3){
				createThumbNail($picID, $self, $sectID, $location, $fileName);
				$numbCellsFilled++;
				}
			elseif($numbCellsFilled ==4){
				createThumbNail($picID, $self, $sectID, $location, $fileName);
				echo '</tr>';
				$numbCellsFilled = 1;
				$numbOfRows = 1;
				}
			$numPicsID = array($picID);
			}
			foreach($numPicsID as $value){
				echo "num pics ID: ".$value."<br>";
				}
		echo '</table>';
		}
?>
My question is why when I have this, $numPicsID = array($picID);, as show above, only the last item is store in array. However, if I put this same code, $numPicsID = array($picID);, in the function, createThumbNail($picID, $self, $sectID, $location, $fileName);, then the array does store all of the items. Should either case be working? All I care is so I can get all the items into the array and access that variable from other place on the page.

ljCharlie
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

you have to do :

Code: Select all

<?php
$numPicsID[] = $picID;
?>
Last edited by mudkicker on Fri Oct 15, 2004 3:10 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

By using

Code: Select all

$numPicsID = array($picID);
you keep overwriting the value of $numPicsID with a new array as mudkicker rightly points out, you need to add to the array instead:

Code: Select all

$numPicsID[] = $picID;
Mac
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

yeah this time i was faster ;)
Post Reply