Mysql combine link with title - php

I have 2 fields in a mysql database. They are title which is the news article title and (description/link) which is the link to the article. The web page is http://vince.netau.net .Type bitcoin in the search field. I would like to be able to click on the title and bring up the link to the article. I don't want to even see the description column with the link like it is currently.
Here is the code I have currently which has the Title with the link but I'm showing the link in the next column which I don't want. Also, is there a way to not have the title underlined?
<td><a href="<?php echo $row['description']; ?>"
<td><?php echo $row['post_title']; ?></td>
Thanks for the help!!!!

You did not close tags correctly. Try this, they will be in same column
<td><a href="<?php echo $row['description']; ?>">
<?php echo $row['post_title']; ?></a></td>
I hope this helps
Edit:
Also for not underlined link you can use this css attribute:
<td><a style="text-decoration: none;" href="<?php echo $row['description']; ?>">
<?php echo $row['post_title']; ?></a></td>

Your html code is not really correct. You have to close all tags and you should read about HTML and the HTML structure.
<td>
<a href="<?php echo $row['link']; ?>">
<?php echo $row['post_title']; ?>
</a>
</td>

Use link instead of description.
Using css you can remove the underline:
<td>
<a href="<?php echo $row['link']; ?>" style="text-decoration: none;">
<?php echo $row['post_title']; ?>
</a>
</td>

Related

Printing URL links within a function

I am creating a movie database. I need View, Edit, and Delete to link to other pages within my site. For example, I want view to go to a link called show.php but I need the page to dynamically load with the $movie[id] information. How can I do that from within the function. Here's what I have so far:
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
$movie['id'],
$movie['title'],
$movie['director'],
$movie['year'],
printDropdown ($movie['cast']),
'<img src="'.$movie ['poster'].'" height="100" width="75"/>',
'<a class="action" href="">'.'View'.'</a>',
'<a class="action" href="">'.'Edit'.'</a>',
'<a class="action" href="">'.'Delete'.'</a>',
);
}
Edited on 5/12:
I decided to take a different approach. The poster column appears in the table but it shows that all the images are broken even though the URL image source is correct for each array. What am I missing from the table column that contains the image source?
<?php foreach($movies as $movie) { ?>
<tr>
<td><?php echo h($movie['id']); ?></td>
<td><?php echo h($movie['title']); ?></td>
<td><?php echo h($movie['director']); ?></td>
<td><?php echo h($movie['year']); ?></td>
<td><?php echo printDropdown($movie['cast']); ?></td>
<td><img src="'.$movie['poster'].'" height="100" width="75"/></td>
<td><a class="action" href="<?php echo url_for('show.php?id=' . h(u($movie['id']))); ?>">View</a></td>
<td><a class="action" href="<?php echo url_for('edit_movie.php?id=' . h(u($movie['id']))); ?>">Edit</a></td>
<td><a class="action" href="">Delete</a></td>
</tr>
<?php } ?>
</table>
Read up on PHP GET. And you should be able to do it.
You have to do something like this:
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
$movie['id'],
$movie['title'],
$movie['director'],
$movie['year'],
printDropdown ($movie['cast']),
'<img src="'.$movie ['poster'].'" height="100" width="75"/>',
'<a class="action" href="show.php?action=view&id=' . $movie['id'] . '">'.'View'.'</a>',
'<a class="action" href="">'.'Edit'.'</a>',
'<a class="action" href="">'.'Delete'.'</a>',
);
Within the other page. like show.php you can get the given action and id like:
$id = $_GET['id']; // the given id
$action = $_GET['action']; // view
You can use GET method
In this case you place parameters in the url of the href attributes. Like:
<a href='<url>?movie_id={$movie['id']}&title={$movie['title']}'>

Variable not being formatted with CSS - Magento

When I echo my own variable to a div container it comes out as plaint text (unformatted). I don't understand why echoing a Magento variable comes out formatted but mine doesn't? Here's my code, in particular the <?php if(!isset($specialPrice)): { ?> section which I created. Here is the code:
<div class="product">
<a href="<?php echo $_item->getProductUrl() ?>"
title="<?php echo $this->escapeHtml($_item->getName()) ?>" class="product-image"><img
src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail') ?>"
alt="<?php echo $this->escapeHtml($_item->getName()) ?>"/></a>
<div class="product-details">
<p class="product-name">
<?php echo $this->escapeHtml($_item->getName()) ?>
</p>
<?php $specialPrice = $productToCheck->getData('special_price');
$orignalPrice = $productToCheck->getData('price');
?>
<?php if(!isset($specialPrice)): { ?>
<?php echo $product['price'] ?>
<?php } else: { ?>
<?php echo $specialPrice ?>
<?php } endif ?>
</div>
</div>
Echoing $product['price'] shows up with its CSS like this:
but if it enters the ELSE statement to display my variable it shows like this:
Does anyone know what could be going wrong?
$product['price'] returns you a unformatting price value.
Maybe you can call a block function, for example $block->getPrice() and in getPrice() you need to format the price by your custom preferences.
If you want to add styles to your price value then you need to use a magento tag class

How do I add a target=_blank to php code to open in new window?

I have a simple link that looks like this in php code:
<a class="feed-link" title="<?php echo esc_attr(sprintf( $rss['feedtitle'],
get_bloginfo('name'), $rss['separator'] )); ?>" href="<?php echo get_feed_link(); ?>">
<img alt="img" src="<?php echo FEEDBURNER_EMAIL_SUBSCRIPTION_URL; ?>/img/rss.png" />Posts
<abbr title="Really Simple Syndication">RSS</abbr></a>
How would I add a target="_blank" into that chunk of php code so it doesn't take the user off my page?
Thanks!
It's an HTML attribute of the <a> tag so you add it to your HTML.
<a target="_blank" class="feed-link" title="<?php echo esc_attr(sprintf(
$rss['feedtitle'], get_bloginfo('name'), $rss['separator'] )); ?>" href="<?php echo get_feed_link(); ?>">

Joomla intro image as read more link

I want to make the joomla articles intro image to behave like the read more, and the title link. So the user clicks the image, and the article loads.
I'm not an PHP expert but maybe this is the readmore links code:
<a href="<?php echo $this->item->readmore_link; ?>" class="button<?php echo $this->item->params->get('pageclass_sfx'); ?>">
<?php if ($this->item->readmore_register) :
echo JText::_('Register to read more...');
elseif ($readmore = $this->item->params->get('readmore')) :
echo $readmore;
else :
echo JText::_("Read Article");
endif; ?></a>
This is what i want to do with every intro image on my joomla site.
Thanks !
Just resolved it!
your way of thinking helped me. Thank you!
here's my code:
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>">
<?php
$images = json_decode($item->images);
if (isset($images->image_intro) and !empty($images->image_intro)) {
$imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro;
$class = (htmlspecialchars($imgfloat) != 'none') ? ' class="size-auto align-'.htmlspecialchars($imgfloat).'"' : ' class="size-auto"';
$title = ($images->image_intro_caption) ? ' title="'.htmlspecialchars($images->image_intro_caption).'"' : '';
echo '<img'.$class.$title.' src="'.htmlspecialchars($images->image_intro).'" alt="'.htmlspecialchars($images->image_intro_alt).'" />';
}
echo $this->item->introtext;
?>
</a>
for Joomla 2.5:
in your override for _item.php (Location: yourtemplate\html\mod_articles_news\item.php)
place the following line:
<?php if ($params->get('image')) : ?>
<?php $images = json_decode($item->images); ?>
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<img src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
<?php endif; ?>
<?php endif; ?>
Place it there where you would like it to show up
For example after:
<?php echo $item->beforeDisplayContent; ?>
Your intro image has become a link now.
the isset part, makes sure that if a viewer uses Internet Explorer, it doesn't show up a small red cross box.
Just for the information:
in blog_item.php you can find an example code how it's shown up in an article. Here you can also find the code for imagefloat etc.
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
<div class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</div>
<?php endif; ?>
So let me start by explaining what the code that you've posted above does. The entire block of code generates one link: there are a bunch of if statements that are determined based off some settings. For example, if you have set that people need to register in order to read more, the link will say "Register to read more..."
The part that we're interested in here, however, since we want to turn images into links, is the URL that we want the images to link to. This is right in the first line:
<a href="<?php echo $this->item->readmore_link; ?>"
so we know that the URL is provided dynamically thanks to $item->item->readmore_link and all this code is doing is echoing it into the HTML.
All that's left is to edit your Joomla template of the page on which you have your images (probably the same file you took this code from). It looks like this should be part of a greater PHP loop, which loops through all the posts. Somewhere above where you found this code, should be code for the intro image that goes along with that post.
I'm not sure what it'll look like, it could be a <img src="<? stuff here; ?> /> or it could be dynamically generated. Keep reading. If you're still not sure where to find it at the end, edit your post with the full code of the template where you got the above snipping from. Regardless of what it looks like, it is referred to as <WHATEVER IMAGE CODE YOU FOUND ABOVE> in the following step:
You have to wrap that image with "a" tags so that it looks like the following:
<WHATEVER IMAGE CODE YOU FOUND ABOVE>
That should do it. Let me know if you have any trouble, I'll be more than happy to make my post more specific if you can provide more detailed information, but I've tried to explain it well enough that you should be able to figure it out with a couple tries.
As you stated you are not a PHP expert, it sounds like your best bet will be to use a Joomla extension that has similar functionality to what you want.
I believe mod_minifrontpage will work for what you need. It allows you to display a list of articles, and it generates thumbnails for those articles based on the first image to be referenced.
There are article intro images in J, since 1.7.5 and now in latest 2.5.3
what you need is change the defaults for component_content,
you can do it 2 ways, editing views in yourinstall/components/com_content/views/
or use template overrides , you first need to know if your template IS using overrides otherwise if you edit component views in the component itself you will not see changes.
to verify this , go to
site_name/templates/template_name/html folder and check if there is folder name
com_content ,
if that is the case than your template is using overrides and any edits should be done trough there not through component
now to the actual code
this is in
components\com_content\views\featured\tmpl\default_item.php ( THIS I DEFAULT FRONTPAGE ARTICLE VIEW)
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
<div class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</div>
<?php endif; ?>
all you would need to do is wrap a element around IMG tag with readmore link like this
<a href="<?php echo $this->item->readmore_link; ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</a>
DO NOT forget that if there is template override for com_content you wold need to edit the featured/default_item.php inside it
In Joomla 3.1, the intro_image layout has been moved to the layouts/joomla/content folder. In my situation, it is called from com_content/views/category/tmpl/blog_item.php like so:
<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>
I moved that file to my template/html/com_content/category/blog_item.php and then wrapped the call to JLayoutHelper like so:
<?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>
<a href="<?php echo $link; ?>">
<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>
</a>
If you have Gantry installed on Joomla 3.1, the overrides are in a different location. You will want to navigate to plugins/system/gantry/overrides/3.0/2.5/com_content/category/blog_item.php and wrap the intro image with the read more link code.
<?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>
<a href="<?php echo $link; ?>"><img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/></a>

PHP behaves weird, mixing up HTML markup

Thanks for looking on this problem.
I have a page that is totally valid page, and there is a PHP loop that brings in a <li> for each entry of the table.
When i check this page locally it looks 100% OK, but when veiwing the page online the left side bar (which creates this markup is broken randomly mixing <div>'s and <li>'s and i have no clue what the problem is.
This problem is on FF mac and PC (safari looks good)
See page (problem is on the left side)
php code
<?php do { ?>
<li class="clear-block" id="<?php echo $row_Recordset1['penSKU']; ?>">
<a title="Click to view the <?php echo $row_Recordset1['penName']; ?> collection" rel="<?php echo $row_Recordset1['penSKU']; ?>">
<img src="prodImages/small/<?php echo $row_Recordset1['penSKU']; ?>.png" alt="" />
<div class="prodInfoCntnr">
<div class="basicInfo">
<span class="prodName"><?php echo $row_Recordset1['penName']; ?></span>
<span class="prodSku"><?php echo $row_Recordset1['penSKU']; ?></span>
</div>
<div class="secondaryInfo">
<span>As low as .<?php echo $row_Recordset1['price25000']; ?>¢ <!--<em>(R)</em>--></span>
<div class="colorPlacholder" rel="<?php echo $row_Recordset1['penColors']; ?>"></div>
</div>
</div>
<div class="additPenInfo">
<div class="imprintInfo"><span>Imprint area: </span><?php echo $row_Recordset1['imprintArea']; ?></div>
<div class="colorInfo"><span>Available in: </span><?php echo $row_Recordset1['penColors']; ?></div>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Amount</th>
<th>500</th>
<th>1,000</th>
<th>2,500</th>
<th>5,000</th>
<th>10,000</th>
<th>20,000</th>
</tr>
<tr>
<td>Price <span>(R)</span></td>
<td><?php echo $row_Recordset1['price500'];?>¢</td>
<td><?php echo $row_Recordset1['price1000'];?>¢</td>
<td><?php echo $row_Recordset1['price2500'];?>¢</td>
<td><?php echo $row_Recordset1['price5000'];?>¢</td>
<td>Please Contact</td>
<td>Please Contact</td>
</tr>
</table>
</div>
</a>
</li>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
You cannot put a <div> inside of <a>.
Divs are block level elements. Anchors are not. Basically, it's like putting <span> outside of <div>. Doesn't make any sense.
Solution: Move the anchors to inside the divs.
(In the future, if different browsers are displaying it differently, it's probably not the PHP but the HTML.)

Categories