Jump to content

array created in 1 place but used separately


dmirsch

Recommended Posts

I need my code to generate the following HTML:

div id="wowslider-container1">
<div class="ws_images">
<span><img src="https://alaskapac.centertix.net/UPLImage/aca_beauty.jpg" alt="Disney's Beauty & the Beast" title="Disney's Beauty & the Beast" id="wows0" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/ss_scaredscriptless.jpg" alt="Scared Scriptless" title="Scared Scriptless" id="wows1" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/aysc_worldcupofwines.jpg" alt="World Cup of Wines" title="World Cup of Wines" id="wows2" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/aso_outofthisworld.jpg" alt="Anchorage Symphony's Out of This World" title="Anchorage Symphony's Out of This World" id="wows3" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/aca_mikegarson.jpg" alt="Mike Garson" title="Mike Garson" id="wows4" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/ctc_pinkalicious.jpg" alt="Pinkalicious!" title="Pinkalicious!" id="wows5" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/aso_silentfilm.jpg" alt="Anchorage Symphony's Silent Film Double Feature" title="Anchorage Symphony's Silent Film Double Feature" id="wows6" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/aca_rockofages.jpg" alt="Rock of Ages" title="Rock of Ages" id="wows7" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/pdc_concert.jpg" alt="Pulse Dance Company in Concert" title="Pulse Dance Company in Concert" id="wows8" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/aca_mannheimsteamroller.jpg" alt="The Christmas Music of Mannheim Steamroller" title="The Christmas Music of Mannheim Steamroller" id="wows9" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/alex_zlatkovski.jpg" alt="Alexander Zlatkovski" title="Alexander Zlatkovski" id="wows10" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/wsp_joshritter.jpg" alt="Josh Ritter" title="Josh Ritter" id="wows11" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/z_acpa_giftcertificates.jpg" alt="Gift Certificates" title="Gift Certificates" id="wows12" /></span>
<span><img src="https://alaskapac.centertix.net/UPLImage/adp_fireice.jpg" alt="New Year's Eve Celebration" title="New Year's Eve Celebration" id="wows13" /></span>
</div><div class="ws_bullets"><div>
<a href="#wows0" title="Disney's Beauty & the Beast"><img src="https://alaskapac.centertix.net/UPLImage/aca_beauty.jpg" alt="Disney's Beauty & the Beast" />1</a>
<a href="#wows1" title="Scared Scriptless"><img src="https://alaskapac.centertix.net/UPLImage/ss_scaredscriptless.jpg" alt="Scared Scriptless" />2</a>
<a href="#wows2" title="World Cup of Wines"><img src="https://alaskapac.centertix.net/UPLImage/aysc_worldcupofwines.jpg" alt="World Cup of Wines" />3</a>
<a href="#wows3" title="Anchorage Symphony's Out of This World"><img src="https://alaskapac.centertix.net/UPLImage/aso_outofthisworld.jpg" alt="Anchorage Symphony's Out of This World" />4</a>
<a href="#wows4" title="Mike Garson"><img src="https://alaskapac.centertix.net/UPLImage/aca_mikegarson.jpg" alt="Mike Garson" />5</a>
<a href="#wows5" title="Pinkalicious!"><img src="https://alaskapac.centertix.net/UPLImage/ctc_pinkalicious.jpg" alt="Pinkalicious!" />6</a>
<a href="#wows6" title="Anchorage Symphony's Silent Film Double Feature"><img src="https://alaskapac.centertix.net/UPLImage/aso_silentfilm.jpg" alt="Anchorage Symphony's Silent Film Double Feature" />7</a>
<a href="#wows7" title="Rock of Ages"><img src="https://alaskapac.centertix.net/UPLImage/aca_rockofages.jpg" alt="Rock of Ages" />8</a>
<a href="#wows8" title="Pulse Dance Company in Concert"><img src="https://alaskapac.centertix.net/UPLImage/pdc_concert.jpg" alt="Pulse Dance Company in Concert" />9</a>
<a href="#wows9" title="The Christmas Music of Mannheim Steamroller"><img src="https://alaskapac.centertix.net/UPLImage/aca_mannheimsteamroller.jpg" alt="The Christmas Music of Mannheim Steamroller" />10</a>
<a href="#wows10" title="Alexander Zlatkovski"><img src="https://alaskapac.centertix.net/UPLImage/alex_zlatkovski.jpg" alt="Alexander Zlatkovski" />11</a>
<a href="#wows11" title="Josh Ritter"><img src="https://alaskapac.centertix.net/UPLImage/wsp_joshritter.jpg" alt="Josh Ritter" />12</a>
<a href="#wows12" title="Gift Certificates"><img src="https://alaskapac.centertix.net/UPLImage/z_acpa_giftcertificates.jpg" alt="Gift Certificates" />13</a>
<a href="#wows13" title="New Year's Eve Celebration"><img src="https://alaskapac.centertix.net/UPLImage/adp_fireice.jpg" alt="New Year's Eve Celebration" />14</a>
</div></div>
</div>        

 

So I assumed that it would be something similar to the following:

	while ($Row = mysqli_fetch_assoc($carouselResult)){
	$EventName = $Row['EventTitle'];
	$image = $Row['eImage'];

/* $big_image = LISTING OF ALL IMAGES */
$big_image =  array('<span><img src="https://alaskapac.centertix.net/UPLImage/' . $image . '" alt="' . $EventName. '" title="' . $EventName . '" id="wows'. $i .'" /></span>'."\n");
$i2 = $i;
$i = $i+1;
/* $nav_image = TINY BOXES TO NAVIGATE THROUGHOUT CAROUSEL */
$nav_image = array('<a href="#wows' . $i2 . '" title="'.$EventName.'"><img src="https://alaskapac.centertix.net/UPLImage/' . $image . '" alt="' . $EventName. '" />'.$i.'</a>'."\n");
$i2 = $i2+1;
}	

echo '<div id="wowslider-container1">'."\n".'<div class="ws_images">'."\n";
echo array($big_image);
echo '</div><div class="ws_bullets"><div>'."\n";
echo array($nav_image);
echo '</div></div>'."\n".'</div>';

 

But array($big_image) and array($nav_image) do not work as I expected and it just produces the following HTML code:

<div id="wowslider-container1">
<div class="ws_images">
Array</div><div class="ws_bullets"><div>
Array</div></div>
</div> 

 

Can anyone help out a beginner in PHP?

Link to comment
Share on other sites

a fast visit to here and look at the examples would better help to understand arrays

http://php.net/manual/en/language.types.array.php

 

when you place array(), that creates an array, to display an array it must loop the results, it looped them the first time in your while loop.

If your goal is to make a new array, sort them or display elsewhere, then use

$big_image[] =  '<span><img src="https://alaskapac.centertix.net/UPLImage/' . $image . '" alt="' . $EventName. '" title="' . $EventName . '" id="wows'. $i .'" /></span>'."\n";
$nav_image[] = '<a href="#wows' . $i2 . '" title="'.$EventName.'"><img src="https://alaskapac.centertix.net/UPLImage/' . $image . '" alt="' . $EventName. '" />'.$i.'</a>'."\n";

 

then outside your while loop must do a foreach to get each array result

echo '<div id="wowslider-container1">'."\n".'<div class="ws_images">'."\n";
foreach($big_image as $b_image){
echo $b_image;
}
echo '</div><div class="ws_bullets"><div>'."\n";
foreach($nav_image as $n_image){
echo $n_image;
}
echo '</div></div>'."\n".'</div>';

 

you could play around with your styles and dividers

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.