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).
Related
I have been trying to use various combinations of anchor and html tags to code my third row as an actual URL (each time) instead of plain text, and it's not working. To be clear, I am not trying to hardcode a single URL and output as a hyperlink but rather attempting to code in such a way that this third row is consistently outputted as a clickable hyperlink. This is a .php page, and the links are .pdf URLs. I'm also finding this a little more difficult to do because it's a table (so, extra formatting there).
What I'm doing is retrieving many articles from my database, each with the third row as a URL, and then using the below code to output it in my webserver, using tags, with the php . as a separator, etc. However, I'm not able to output the row, which currently displays as plain text, as a set of clickable hyperlinks.
I'm not looking for how to HTML link or output a single link as a hardcoded hyperlink. That's not what I'm asking. I'd also like someone to take the third line below and provide a demo.
<table class="table" width="920" style="border:thin" cellpadding="10" border="1">
<tr>
<th>Topic</th>
<th>Category</th>
<th>URL</th>
</tr>
<?php
while($row = $result->fetch_assoc()){
?>
<tr>
<td><?php echo $row['Topic']; ?></td>
<td><?php echo $row['Category']; ?></td>
<td><?php echo $row['URL']; ?></td>
</tr>
<?php
}
?>
</table>
Your third line should be like this
<td> the link text </td>
if you need the link and text to be same the code will look like this
<td><?php echo $row['URL']; ?></td>
Basically, its like this
<td> ECHO THE URL TEXT HERE </td>
In HTML you can create a link with an anchor tag <a>.
Please try this:
<td>
<a target="_blank" href="<?php echo $row['URL']; ?>"> <?php echo $row['URL']; ?></a>
</td>
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>
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.
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>
I have this loop in PHP that echoes out a table of results,
<table cellspacing="0" cellpadding="3">
<tr>
<td><b>Content Image Title</b></td>
<td><b>Content Image Type</b></td>
<td><b>Headline Image</b></td>
<td><b>Content Image Belongs To</b></td>
<td><b>Date Created</b></td>
<!--<td><b>Uploaded By</b></td>-->
</tr>
<?php $colours = array("#f9f9f9", "#f3f3f3"); $count = 0;?>
<?php foreach ($allContentImages as $contentImages) : ?>
<tr bgcolor="<?php echo $colours[$count++ % count($colours)];?>">
<td><?php echo "<a href='#' class='screenshot' rel='/media/uploads/$contentImages[categoryId]/$contentImages[contentImageName]'>".$contentImages['contentImageName']; ?></td>
<td><?php echo $contentImages['contentImageType']; ?></td>
<td><?php if($contentImages['isHeadlineImage'] == 1){ echo "Y";}else{echo "N";} ?></td>
<td><?php echo $contentImages['contentTitle'] ?></td>
<td><?php echo date("d-m-Y", $contentImages['contentImageDateUploaded']); ?></td>
<td align="left"><a class="delete" href="<?php echo base_url();?>dashboard/deleteContentImage/<?php echo $contentImages['contentImageId'];?>"><img src="/media/images/icons/cancel.png" alt="Delete A Category"/></a></td>
</tr>
<?php
if($contentImages['isHeadlineImage'] == '0') {
echo "<tr bgcolor='red'>";
echo "<td><p>You need to assign a headline image</p></td>";
echo "</tr>";
?>
<?php endforeach; ?>
</table>
I need to check for each content piece with the same title that there is headline image, and if not then echo a new row that is red...but all I get is a new row every time there is an image that is not a headline image. Can anyone help me? I don't mind using javascript if that helps to match the values of the td's? But obviously my attempt is not correct.
It sounds like what you want to do has to be precalculated, since the foreach loop can not know about future content.
Maybe something like this before your foreach statement:
$contentHasHeadlineImage = array();
foreach ($allContentImages as $contentImages) {
if ( $contentImages['isHeadlineImage'] == 1)
$contentHasHeadlineImage[ $contentImages['contentTitle'] ] = true;
}
And then you can use
if (array_key_exists($contentImages['contentTitle'], $contentHasHeadlineImage)) {
// Has headline image...
}
to to verify if a certain title has a headline.
Try my code below:
<table cellspacing="0" cellpadding="3">
<tr>
<td><b>Content Image Title</b></td>
<td><b>Content Image Type</b></td>
<td><b>Headline Image</b></td>
<td><b>Content Image Belongs To</b></td>
<td><b>Date Created</b></td>
<td>Action</td>
</tr>
<?php
$colours = array("#f9f9f9", "#f3f3f3");
$num_colours = count($colours);
$i = 0;
?>
<?php foreach ($allContentImages as $row) : ?>
<tr bgcolor="<?php echo $colours[($i++) % $num_colours]; ?>">
<td><a href="#" class="screenshot"
rel="/media/uploads/<?php echo $row['categoryId']; ?>/<?php echo $row['contentImageName']; ?>">
<?php echo $row['contentImageName']; ?>
</a></td>
<td><?php echo $row['contentImageType']; ?></td>
<td><?php echo $row['isHeadlineImage'] == 1 ? "Y" : "N"; ?></td>
<td><?php echo $row['contentTitle']; ?></td>
<td><?php echo date("d-m-Y", $row['contentImageDateUploaded']); ?></td>
<td align="left"><a class="delete"
href="<?php echo base_url(); ?>dashboard/deleteContentImage/<?php echo $row['contentImageId'];?>">
<img src="/media/images/icons/cancel.png" alt="Delete A Category" />
</a></td>
</tr>
<?php if ( $row['isHeadlineImage'] == 0 ): ?>
<tr bgcolor="red">
<td colspan="6"><p>You need to assign a headline image</p></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
While tidying your code, I found an unclosed a href in the first column. For the special extra row, I add colspan. I assume $row['isHeadlineImage'] have value only 1 or 0 (integer or boolean).
I also found out that you access array key without using quote. It can become potential bug in the future.
Write the code in tidy indentation and consistent when using block or echoing the php variable will help you found the bug quickly. Also, inspect the result in browser using Firebug in firefox or Web Inspector in Safari and Google Chrome to see if the page structure is like you want to have, all the tag is balanced and closed in right place.