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

Hello,

Can anyone help me printing all the files that I have in uploads/ ? to the screen.  Each pictures must be printed in each row.

views/slideshows.php


PHP Code:
<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/pic1.jpg'); ?>" 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


How?
" If I looks more intelligence please increase my reputation."
Reply
#2

Maybe a foreach loop
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

PHP Code:
<?= form_open(); ?>
    <table>
        <thead>
            <tr>
                <th>Edit Caption</th>
                <th>Images</th>
                <th>Delete</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td colspan='3'>
                    <input type="submit" name="delete" class='btn-delete' value="Delete Selected" />
                    <input type="submit" name="update" class='btn-update' value="Update Captions" />
                </td>
            </tr>
        </tfoot>
        <tbody>
            <?php foreach $images as $image) : ?>
            <tr>
                <td><input type="text" name="caption[]" value="<?= $image['caption']; ?>" /></td>
                <td><img src="<?= base_url($image['src']; ?>" height="<?= $image['height']; ?>" width="<?= $image['width']; ?>" /></td>
                <td><input type="checkbox" class='delete' name='checked[]' value="<?= $image['id']; ?>" /></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?= form_close(); ?>
Reply
#4

(This post was last modified: 07-20-2016, 08:39 AM by davy_yg.)

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:


I revise it into this:   

Line 112:  is <td><img src="<?php echo base_url('uploads/'.<?= base_url($image['src']; ?>); ?>" height="300" width="400"></td>



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>
  
" If I looks more intelligence please increase my reputation."
Reply
#5

(This post was last modified: 07-20-2016, 12:37 PM by Wouter60.)

This will never work.

You can't start php code without closing the previous php code block.
Another mistake is to include base_url() twice in one image source path.
I think your code should be:

PHP Code:
<td><img src="<?= base_url() . 'uploads/' . $image['src'];?>" height="300" width="400" /></td
Reply
#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
#7

(This post was last modified: 07-21-2016, 12:27 AM by davy_yg. Edit Reason: slideshow )

This is what I try to print all gallery in rows.  Can somebody help me fix this error message?  Thanks in advance.

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


Line 114:  <td><img src="<?php echo base_url('uploads/'.base_url($images_item['src']; )); ?>" height="300" width="400"></td>

       
views/addslideshows.php


PHP Code:
<?php foreach ($images as $images_item): ?>
        
        <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($images_item['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>
  
        <?php endforeach; ?>


cpages/addslideshows.php

PHP Code:
public function addslideshows() {

        
$this->load->model('Mpages');
        
        
$data['images'] = $this->Mpages->call_gallery();
        
        
$this->load->view('addslideshows'$data); 
    
    } 
" If I looks more intelligence please increase my reputation."
Reply
#8

Seriously, you cannot see what might be wrong with this?

PHP Code:
<?php echo base_url('uploads/'.base_url($images_item['src']; )); ?>

And MWhitney already took the time to refer to this exact problem, reread his post or reread the documents for base_url.
Reply
#9

Might as well talk to a wall!
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

(07-20-2016, 09:37 PM)davy_yg Wrote: This is what I try to print all gallery in rows.  Can somebody help me fix this error message?  Thanks in advance.

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


Line 114:  <td><img src="<?php echo base_url('uploads/'.base_url($images_item['src']; )); ?>" height="300" width="400"></td>

Despite my better judgment, I'm going to attempt to help you here.

A semicolon (Wink indicates the end of a command in programming languages like PHP, C, JavaScript, etc. If you end a command with a semicolon before you include all of the necessary components of that command, you will get the message "syntax error, unexpected ';'". 

In this case, you're getting the error because you've called base_url() twice, but haven't closed the parentheses for either call before terminating the command.

It would appear that you need to find some PHP tutorials in addition to some CodeIgniter tutorials, and pay a little more attention to the code you're writing as well as the error messages you're receiving. You might even want to spring for a book if you're going to be doing this a while.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB