-
davy_yg Senior Member
   
-
Posts: 307
Threads: 129
Joined: Nov 2014
Reputation:
-26
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."
-
davy_yg Senior Member
   
-
Posts: 307
Threads: 129
Joined: Nov 2014
Reputation:
-26
07-20-2016, 08:35 AM
(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."
-
Wouter60 Posting Freak
    
-
Posts: 851
Threads: 38
Joined: Feb 2015
Reputation:
77
07-20-2016, 09:00 AM
(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>
-
mwhitney Posting Freak
    
-
Posts: 1,101
Threads: 4
Joined: Nov 2014
Reputation:
95
(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.
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..
-
davy_yg Senior Member
   
-
Posts: 307
Threads: 129
Joined: Nov 2014
Reputation:
-26
07-20-2016, 09:37 PM
(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."
-
PaulD Posting Freak
    
-
Posts: 1,061
Threads: 42
Joined: Mar 2015
Reputation:
73
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.
-
mwhitney Posting Freak
    
-
Posts: 1,101
Threads: 4
Joined: Nov 2014
Reputation:
95
(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 (  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.
|