Welcome Guest, Not a member yet? Register   Sign In
At a loss...
#1

[eluser]Jbeasley6651[/eluser]
I have a database table with about 10 fields i want to focus on 2 of the fields - 1 field containing a images base url, and 1 field containing number of images. Both fields are in same table.

example

field 1

url.com/imagename.jpg

field 2

6

this means there are 7 images

url.com/imagename.jpg
url.com/imagename_2.jpg
url.com/imagename_3.jpg
url.com/imagename_5.jpg
url.com/imagename_6.jpg


How would i display this? I already have a foreach loop to show the other information in the table, would it be a foreach loop within a foreach loop? if so how would it look?

Thanks in advance,

Jbeasley
#2

[eluser]Christoffer[/eluser]
Yes, you would need to make a foreach loop inside the foreach.

Show me what you have and I can more easily help you with the exact code that would make it work as you intend Smile
#3

[eluser]@li[/eluser]
More like you'd write a for loop, e.g
Code:
for ($x=1; $x<=$field2; $x++)

If this feels untidy to you, you could write a function in which you put your for loop, and in your foreach you simply call a function like
Code:
showImages($field2);
and the function will handle your second loop
#4

[eluser]Jbeasley6651[/eluser]
Thanks, my code is posted below.

the field that contains the image base url is named

photo_url

the field that contains the quantity.

photo_quantity


Code:
&lt;?php foreach($listing_results->result() as $row) :?&gt;

        <div id="&lt;?=$row->mls_listing_id?&gt;" class="propertyview">
            &lt;?php $introtxt = word_limiter($row->remarks, 4); ?&gt;
            <h2 class="property_basic">&lt;?=$introtxt?&gt;</h2>
            <img >photo_url?&gt;" width="265" height="200"/>
            <div class="property_basic">
                <h3 class="property_basic">Basic Information</h3>
                <span class="mls_price">$&lt;?=number_format($row->sale_price,0)?&gt;</span>&lt;!-- end mls_price --&gt;
                <p>State: &lt;?=$row->last_mls_update_date?&gt;</p>
                <p>MLS Office: &lt;?=$row->mls_office_name?&gt;</p>
                <p>Office Number: &lt;?=$row->mls_office_phone?&gt;</p>
                <p>&lt;?=$row->title?&gt;<p>
                </div>
            <div class="property_images">

&lt;!-- LOOP FOR ADDITOINAL IMAGES NEEDS TO BE HERE --&gt;


</div>
            <div class="property_remarks">&lt;?=$row->remarks?&gt;</div>
            <div class="advanced_features">
                <div class="advanced_header">Advanced Features</div>
                <ul>
            &lt;?php foreach($advanced_listing_results->result() as $row) :?&gt;
                <li>&lt;?=$row->title?&gt;</li>
                &lt;?php endforeach; ?&gt;
                </ul>
            </div>
        </div>&lt;!--END specific id div --&gt;
        &lt;?php endforeach; ?&gt;
#5

[eluser]Jbeasley6651[/eluser]
Figured it out!


end result code was the following

Code:
<ul id="property_images">

                    &lt;?php for ($counter = 2; $counter <= $row->photo_quantity; $counter++)  {
                    $txt = $row->photo_url;
                    $listing = $row->mls_listing_id;
                    $image = preg_replace("/".$listing.".+?$/", "", $txt); ?&gt;

                    <li><img src="&lt;?php echo ''.$image.$listing.'_'.$counter.'.jpg'; ?&gt;" width="85" height="62" /></li>                
                    &lt;? } ?&gt;

                </ul>

First, the way it worked is they give you the image url like

http://extimages2.living.net/ImagesHomeP...901483.jpg

then they tell you there are lets say 5 images

but then you have to access the images like this

http://extimages2.living.net/ImagesHomeP...901483.jpg
http://extimages2.living.net/ImagesHomeP...1483_2.jpg
http://extimages2.living.net/ImagesHomeP...1483_3.jpg
http://extimages2.living.net/ImagesHomeP...1483_4.jpg
http://extimages2.living.net/ImagesHomeP...1483_5.jpg

So what i ended up doing was some reg exp to take the string, replace everything before the mls id in this case A3901483 then taking that into a variable and rebuilding the file extension with the counter and just a static .jpg (they will always be .jpg)

Thanks for pointing me in the right direction,

Jbeasley




Theme © iAndrew 2016 - Forum software by © MyBB