CodeIgniter Images - php

Using CodeIgniter, I am trying to place several images onto my view page as follows
...
<?php foreach($results_found as $item): ?>
<tr>
<td><?php echo base_url();?>images/$item->img.jpg</td>?
<td><?php echo $item->title ?></td>
</tr>
...
but all this displays is the url for the images.
I've stored the names of the images in my database, hence my attempt to use $item->img to get access the name. The images are located in my root directory (htdocs\website_name\images)
Any help would be really appreciated. Thanks in advance

You need an image tag. The CodeIgniter way to do it is:
<tr>
<td><img src="<?= base_url(); ?>images/<?= $item->img ?>.jpg" /></td>
<td><?php echo $item->title ?></td>
</tr>
Try it, and check View -> Source to make sure the syntax of the image element reads like this once its been rendered into html:
<img src="http://mysite.com/images/myimage.jpg" />

You need an image element!!! Im not sure what your $item object looks like but try this
<tr>
<td><img src="/images/<?php echo $item->img ?>.jpg"></td>
<td><?php echo $item->title ?></td>
</tr>

Related

Retrieve Server Data from a mysql db

I have question about how i shall do this.
First i have taken out a list from a mysql database which.
What I want to do is to be able to click on one of these items in the list so that I can get the underlying facts for this particular item.
Now i want to use this as a link to get one row from the database.
The database is done and the list i can see in a website but i dont get the last part to work
show_all_symbol.php
//This show the list
<?php
include 'connect.php';
$sql = "SELECT * FROM t1_symbolism ";
$q = $pdoconn->query($sql);
$q ->setfetchmode(PDO::FETCH_ASSOC);
?>
<table>
<head>
<tr><th>Symbol</th><th>Alternativtnamn</th> <th>Symboltyp</th></tr>
</thead>
<tbody>
<?php while ($row = $q->fetch()): ?>
<td><img src="<?php echo "/symbol/",$linksbild,($row['symb_type']),"/",($row['symb_pic']); ?>"/></td>
<tr>
<td> <a id="leftside_meny" href= <?php echo "/symbol/show_symbol.php";?> target= "texten"> <?php echo ($row['symb_name']); ?></a></td>
<td><?php echo ($row['symb_name_other']); ?></td>
<td><?php echo ($row['symb_type']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</body>
show_symbol.php
<body>
<?php
$funamn = trim($_POST['symbname']);
include 'connect.php';
$sqlanswer = $pdoconn->query(" SELECT * from t1_symbolism where symb_name '$funamn'");
$row = $sqlanswer->fetch();
?>
<table >
<thead>
<tr><th>Symbol</th><th>Symbolnamn</th><th>Alternativtnamn</th> <th>Symboltyp</th><th>Fakta</th></tr>
</thead>
<tr>
<td><img src="<?php echo "/symbol/",$linksbild,($row['symb_type']),"/",($row['symb_pic']); ?>" width="250" height="250"/></td>
<td><?php echo ($row['symb_name']); ?></td>
<td><?php echo ($row['symb_name_other']); ?></td>
<td><?php echo ($row['symb_type']); ?></td>
<td><?php echo ($row['symb_history']); ?></td>
</tr>
</table>
</body>
What i want to do is to use this part as Use this part as a clickable link so I can view a record in the table.
<td> <a id="leftside_meny" href= <?php echo "/symbol/show_symbol.php";?> target= "texten"> <?php echo ($row['symb_name']); ?></a></td>
Thank in the advance!
it looks like you are looking for a way to pass this value $row['symb_name'] to this value $_POST['symbname']. Here's what i think you should try :
in your show_all_symbol.php
<td>
<a id="leftside_meny" href="<?php echo "/symbol/show_symbol.php?symb_name=" . $row['symb_name'];?>" target="texten">
<?php echo ($row['symb_name']); ?>
</a>
</td>
in your show_symbol.php
$funamn = trim($_GET['symb_name']);
If you want to use $_POST then you will have to either figure a way to make a form out of each clickable element and configure it to make a POST or do it using javascript or jquery.

html load picture using web address

I'm getting the web address of pictures on the internet from my database and displaying them back on the page, it is currently displaying the actual web address and not loading the actual picture, is it possible to get the actual picture to be loaded? (on the database the web address of the image is stored as a string)
<tr>
<!--<th>id</th>
<td><?php echo $row['id']; ?></td> -->
<th>Name</th>
<td><?php echo $row['hname']; ?></td>
<th>image</th>
<td><?php echo $row['himage']; ?></td>
<th>Description</th>
<td><?php echo $row['hdesc']; ?></td>
</tr>
What you're looking for is called an img tag. Something like this:
<td><img src="<?php echo $row['himage']; ?>" /></td>
If your image is stored for example in the root in the folder itages, then
<td><img src="/images/<?php echo $row['himage'];?>" /></td>
OR
<td><img src="/images/<?=$row['himage'];?>" /></td>

Display image slideshow by using php mysql

i have a database named hotel_booking,it contains field named imglinks which stores the link of the images and i am only able to display single image in the site. i want to display a slide show of the images of the respective hotels.
<tr>
<th>NAME OF HOTELS</th>
<th>CATEGORY</th>
<th>DESCRIPTION</th>
<th>ADDRESS</th>
<th>GALLERY</th>
</tr>
<?php
while($row=mysql_fetch_array($query))
{
$f1=$row['name'];
$f2=$row['category'];
$f3=$row['description'];
$f4=$row['address'];
?>
<tr>
<td><?php echo $f1 ?></td>
<td><?php echo $f2 ?></td>
<td><?php echo $f3 ?></td>
<td><?php echo $f4 ?></td>
<td><img src="<?php echo $row['imglinks'];?>" height="200" width="55"></td>
link to image of what i want to achieve
You can use bootstrap to achieve this easily with a few lines of code.
http://getbootstrap.com/javascript/#carousel
Go through this link and if there is any problem let me know :)

`iframe` inside an HTML table

I am displaying some data from a database into my cms, using tables (tr, td).
<tr align="center">
<td><?php echo $i++; ?></td>
<td><?php echo $post_image; ?></td>
<td><?php echo $post_title; ?></td>
<td>
<iframe width="100px" frameborder="0" id='inneriframe' scrolling=yes >
<?php echo $post_description; ?>
</iframe>
</td>
<td>Edit</td>
<td>Delete</td>
</tr>
Unfortunately the description php variable is not displayed at all inside my iframe. However, if I take out the iframe tag, everything works fine, and I can see all the stored values from the database.
<tr align="center">
<td><?php echo $i++; ?></td>
<td><?php echo $post_image; ?></td>
<td><?php echo $post_title; ?></td>
<td><?php echo $post_description; ?></td>
<td>Edit</td>
<td>Delete</td>
</tr>
So my main question is how to use iframes inside tds?
As I mentioned in comments (but gotten no response from).
iframe requires a source src="file.xxx".
https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe
Taken from example #1:
<iframe src="page.html" width="400" height="300">
<p>Your browser does not support iframes.</p>
</iframe>
What you need to do is to remove the <?php echo $post_description; ?> from the iframe and just do:
<iframe src="file_for_iframe.php" width="100px" frameborder="0" id='inneriframe' scrolling=yes >
</iframe>
and have the variables inside file_for_iframe.php to be echo'd in there.
That's how you'll get your iframe to show the contents "on screen" rather than in HTML source.
If you had a look at your HTML source as I also mentioned in comments, you would indeed have seen the contents.
They're in there alright, but not being echo'd properly (on screen).
The (and as an example) file_for_iframe.php file that I have stated above, will contain whatever content you wish to display.
For example:
<?php
echo $post_description = "Whatever is presently assigned to this...";
?>
Important note:
echo $post_description = "x"; is valid syntax and you need to keep the echo for it. Otherwise, it won't work.
iframe elements load external documents; the HTML that goes between their start and end tags is alternative content for browsers which do not support iframes.
If you want a scrolling area on a page, apply the CSS overflow property to an appropriate element (probably a div in this case).

result with code is fine but last column 'update' show not active with href

result with code is fine but last column 'update' show not active with
href
<?php
while($row=mysql_fetch_array($res))
{
?>
<tr><th colspan="4">Image</th><th>Title</th><th>Details</th>
<th>Country</th><th>City</th></tr>
<tr><td colspan="4"><img src="<?php echo $row['image']?>"width="50px"
height="50px" > </td>
<td><?php echo $row['title']?></td>
<td><?php echo $row['details']?></td>
<td><?php echo $row['country']?></td>
<td><?php echo $row['city']?></td>
<td>update</td>
</tr>
<?php }?>
The issue is, you are using the href value as # for your update link! Instead, you should use a URL there. Because when you click on the link, the browser takes you to the page that you had specified in that href attribute!
So in short, replace this:
<td>update</td>
with something like this:
<td>update</td>
Hope it helps.

Categories