Welcome Guest, Not a member yet? Register   Sign In
Looping file
#6

(07-20-2016, 08:35 AM)davy_yg Wrote: Hello,

I try this:  <?= base_url($image['src']; ?>


PHP Code:
<br><br>
<
table style="padding: 10px;">
<
tr>
<
td><b>EDIT CAPTION</b></td>
<
td><center><b>IMAGES</b></td>
<
td><b>DELETE</b></center></td>
</
tr>
<
tr>
<
td><input type="text" name="caption" value=""></td>
<
td><img src="<?php echo base_url('uploads/'.<?= base_url($image['src']; ?>'); ?>" height="300" width="400"></td>
<
td><button class="delete">DELETE</button></td>
</
tr>
<
tr>
<
td><input type="text" name="caption" value=""></td>
<
td><img src="<?php echo base_url('uploads/pic2.jpg'); ?>" height="300" width="400"></td>
<
td><button class="delete">DELETE</button></td>
</
tr>
       </table>
</
div>

       <?php echo form_close(); ?>
       <?php if (isset($success_msg)) { echo $success_msg; } ?>
       </div> 

And it does not read my codes.

Parse error: syntax error, unexpected '<' in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\addslideshows.php on line 112
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected '<'
Filename: views/addslideshows.php
Line Number: 112
Backtrace:

That's because you copied part of one line of my code into the wrong place within your existing code. 

PHP Code:
<?= 'something'?>

is a short-hand for 

PHP Code:
<?php echo 'something'?>

and it is an error to put <?= inside a PHP tag.

The basic idea is that your controller would pass an array called $images to the view which contains a series of arrays, each of which contains the definition of the various properties of your image (caption, src, width, height). 

PHP Code:
$images = [
    [
        'caption' => '',
        'src' => 'uploads/pic1.jpg',
        'height' => 300,
        'width' => 400,
        'id' => 1,
    ],
    [
        'caption' => '',
        'src' => 'uploads/pic2.jpg',
        'height' => 300,
        'width' => 400,
        'id' => 2,
    ],
];

$this->load->view('add slideshows', ['images' => $images]); 

Then you could loop through $images to extract the properties of each $image into a row in your table. So, $image['src'] would return 'uploads/pic1.jpg' for your first image, 'uploads/pic2.jpg' for your second image, etc..
Reply


Messages In This Thread
Looping file - by davy_yg - 07-20-2016, 03:25 AM
RE: Looping file - by InsiteFX - 07-20-2016, 03:38 AM
RE: Looping file - by mwhitney - 07-20-2016, 06:42 AM
RE: Looping file - by davy_yg - 07-20-2016, 08:35 AM
RE: Looping file - by mwhitney - 07-20-2016, 01:47 PM
RE: Looping file - by davy_yg - 07-20-2016, 09:37 PM
RE: Looping file - by mwhitney - 07-22-2016, 10:56 AM
RE: Looping file - by Wouter60 - 07-20-2016, 09:00 AM
RE: Looping file - by PaulD - 07-21-2016, 03:09 AM
RE: Looping file - by InsiteFX - 07-21-2016, 03:18 AM
RE: Looping file - by Ivo Miranda - 07-22-2016, 12:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB