Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

associative multidimensional array

9:29 pm on Nov 9, 2013 (gmt 0)

5+ Year Member

Hi there,

What I'm trying to do... I'm working on a project where users can select photographs they want (more than one) and then proceed through to the next pages selecting the sizes they want for each one..

I've got demo here => [flexdanceinc.co.uk ]

trouble I have is on the final page..I want to display the photographs the users have picked and their sizes they've chosen (for each particular photograph) directly underneath..

At the moment, how it works is that the sizes don't match directly up to their corresponding image..

See the example here => [flexdanceinc.co.uk ]

Below is the current code i use on that page

$how_many = count($photographs);

//echo $how_many;
echo '<p><strong>Quantity chosen:</strong> <em>'.$how_many.'</em></p>'. "\n";
if ($how_many>0) {
echo '<p>You chose the following photograph/s: <strong>Now please select the size/s you would like</strong></p>'. "\n";
echo '<ul class="basic_gallery">'. "\n";
for ($i=0; $i<$how_many; $i++) {
echo '<li><a href="" ><img src="../order/photo/'.$photographs[$i].'" /></a>'. "\n";
echo '<input type="text" name="photographs[]" value = "'.$photographs[$i].'" />';

echo "<div id='options'> ". "\n";
echo "<ul>
<li><label>" . ($i+1) . '- ' . $photographs[$i] ."</label></li>
</ul> ". "\n";
echo '<ul class="photograph_size">';
echo "<li><h4>Selected Sizes:</h4></li>";
echo '<li><input type="text "name="large[]" value="'.$large[$i].'" /></li>';
echo '<li><input type="text "name="small[]" value="'.$small[$i]. '" /></li>';
echo "</ul>

</li>". "\n";
echo "</ul>". "\n";

I understand why it displays it that way, it displays the chosen sizes. But i want the images that are selected to have their sizes chosen underneath, so they match up ...have this for each photograph..

I've been digging around and I'm thinking I might need to use associative multidimensional array..

something like this;

[0] => Array
[name] => img_34.jpg
[large] => 10 x 8
[small] =>

[1] => Array
[name] => img_221.jpg
[large] => 10 x 8
[small] => 6 x 4

So hopefully the end result would be displayed in a nicely

...like this => [flexdanceinc.co.uk ]

...but for the life of me I can't get my head around how to code it..

Any help would be great..

11:51 pm on Nov 11, 2013 (gmt 0)

WebmasterWorld Senior Member Top Contributors Of The Month

echo '<li><input type="text "name="large[]" value="'.$large[$i].'" /></li>';
echo '<li><input type="text "name="small[]" value="'.$small[$i]. '" /></li>';

echo '<li><input type="radio "name="size[]" value="'.$large[$i].'" /> "'.$large[$i].'"</li>';
echo '<li><input type="radio "name="size[]" value="'.$small[$i]. '" /> "'.$small[$i]. '"</li>';

I haven't tested, but that will likely get you closer, because then you should end up with basically the equivalent of:

[0] => Array(
[name] => name.ext
[size] => size_selected
[1] => Array(
[name] => name_2.ext
[size] => size_selected_2

Unless you pass both arrays into an array it will actually be:

$name[0] == 'name.ext';
$size[0] == 'size_selected';


Featured Threads

Hot Threads This Week

Hot Threads This Month