<ul>
<li> Telephone number : <?php echo $row[3]?> </li>
<li> Website : <a href = "<?php echo $row[4]?>" ></a> </li>
</ul>
$row[4] represents the column in database that has the link to website.
I'm trying this code to get href but it's not working for some reason. Any hints what am I doing wrong here?
If I echo it without making it an href then it's working fine. So my database connection is perfectly working.
Thanks in advance.
Well, you filled only the href attribute of the link. The text to be displayed must be put between the link tags:
<?php echo $row[4]; ?>
Related
I have a URL that looks like:
example.com/profile.php?id=1
I want to dynamically generate the URL by taking username from the form input in the database's id field. Like :
example.com/profile.php?id=username
This link give errors.If I use below link than it works
example.com/profile.php?id="username"
But , I am facing problem in anchor tag.My Code :
<a href="contributor-profile.php?id=<?PHP echo "$data['id']";?>">
<h4 class="contributor-name">
<?PHP echo $data ['name'];?>
</h4>
</a>
I have also used urlencode fuction but it is not working.
<a href="profile.php?id=<?PHP echo urlencode($data['id']);?>">
<h4>
<?PHP echo $data ['name'];?>
</h4>
</a>
I'm building a wordpress theme. In the backend, the user has the option to enter the url for their social networks (i.e. twitter, facebook, instagram etc). These URL's are then dynamically added to images in the theme front end linking to the respective networks.
The issue I have is that if a user doesn't enter a url for a network, I don't want the image to display. I am trying to write code that says, if the url is blank, echo 'class="hidden"' - this class has display:none in the css.
here is a snippet of my php:
<ul class="icons">
<li <?php if (get_theme_mod('footer_twitter')==0) {echo 'class="hidden"'; } ?>><span class="label">Twitter</span></li>
</ul>
and the css:
ul.icons li.hidden {
display:none;
}
The php code above currently outputs the echo statement for all cases, even when a url is entered in the backend. Can anyone help me with this code
Check the return of "get_theme_mod()" You can check this by using, cause i dont think it "== 0". http://codex.wordpress.org/Function_Reference/get_theme_mod
var_dump(get_theme_mod('footer_twitter'));
//string(0)
Here is your new code:
<ul class="icons">
<li class="<?php echo empty(get_theme_mod('footer_twitter')) ? 'hidden' : ''; ?>">
<a href="<?php echo get_theme_mod('footer_twitter'); ?> " class="icon circle fa-twitter">
<span class="label">Twitter</span>
</a>
</li>
</ul>
Please check this Syntax: http://php.net/manual/en/control-structures.alternative-syntax.php its the best way to code control structures in your "View" code.
<?php if (!empty (get_theme_mod( 'set_address2' ))) {
echo get_theme_mod( 'set_address2');
}?>
This seemed to work for me in Wordpress.
Let me know if this works.
I am using this code in a PHP include to give a class to the active page the user is currently browsing.
<li id="nav11">
<a <?php if ($_SERVER['REQUEST_URI']=="contact") echo " class=\"actv\""; ?> href="contact">Contact</a>
</li>
My page is called http://www.domain.com/contact.php
However, nothing happens with my code above.
<li id="nav11">
<a <?php if ($_SERVER['REQUEST_URI']=="/contact.php") echo " class=\"actv\""; ?> href="contact">Contact</a>
</li>
Have you tried to change "contact" to "/contact.php"?
I'm trying to make my sub category looks different when it's selected, for that I've used sub_cat variable in my php.
So value of $sub_cat depends on the page that loads.
On the top I've this code:
if(!empty($_GET['sub_cat'])){
$sub_cat=$_GET['sub_cat'];
}
else{
$sub_cat=0;
}
Now what my code for displaying list.
<li <?php if($sub_cat==11) echo "style='color:#C00'"; ?> >Popular</li>
<li <?php if($sub_cat==12) echo "style='color:#C00'"; ?> >Exotic</li>
<li <?php if($sub_cat==13) echo "style='color:#C00'"; ?> >Fibrous Veg</li>
But it doesn't seem to make any difference, value of $sub_cat is coming fine as in 11,12,13 but this code is not working. Can anyone spot the minor mistake or major mistake?
How about transferring the style attribute to the a element instead of placing it in the li.
<li><a href="vegetables.php?sub_cat=11" <?php if($sub_cat==11) echo "style='color:#C00'"; ?>>Popular</a></li>
<li><a href="vegetables.php?sub_cat=12" <?php if($sub_cat==12) echo "style='color:#C00'"; ?>>Exotic</a></li>
<li><a href="vegetables.php?sub_cat=13" <?php if($sub_cat==13) echo "style='color:#C00'"; ?>>Fibrous Veg</a></li>
Try this:
if(isset($_GET['sub_cat'])){
$sub_cat=$_GET['sub_cat'];
}
else{
$sub_cat=0;
}
I'm using Drupal CMS. I'm a newbie in Drupal and PHP.
In one of my *.tpl.php file I've a PHP code snippet as follows:
<div class="form-section">
<h3>Job Alerts: jobs delivered to your inbox! <strong>(optional) </strong> <span class="info-ico"><em><?php echo bfstring('tooltip_register_job_alerts'); ?></em></span></h3>
<?php $alerts = bevforce_get_user_option($user->uid, 'alert', false); ?>
<ul class="jobs-alerts-list">
<?php foreach ($alerts as $a) : ?>
<li><?php echo $a['value']['alert_name']; ?> edit</li>
<?php endforeach; ?>
</ul>
<p><!--<a class="popup-loader" href="<?php echo url(); ?>?bf-ajax=create-job-alert&page=register"><strong>Create Job Alert</strong></a>-->
<a class="popup-loader" href="/?bf-ajax=create-job-alert&page=register">Create New Job Alert</a>
</p>
</div>
I'm not getting what's the purpose of data-oid="<?php echo $a['oid']; ?>" in anchor tag(<a>). I've never seen such attribute anywhere in <a> tag.
Following is another code snippet from my PHP code :
<li><a class="popup-loader" href="/?bf-ajax=delete-job-alert&eid=&oid=0">Remove</a></li>
If I hover the mouse cursor over the hypertext Remove, I'm getting the following URL:
xyz.com/bf-ajax=delete-job-alert&oid=3805462
How could this happen that I'm passing the value oid=0 in query string but it is showing some different value when I hover the hypertext? Is this happening due to the data-oid attribute we used in <a> tag above?
So in short my doubt is what's the purpose of attribute data-oid in <a> tag and how the value is getting changed from the value I set in the code?
Can anyone clear my above doubts?
Thanks in advance.
The data-* attribute is primarily for JavaScript in HTML 5. See: http://html5doctor.com/html5-custom-data-attributes/
Using the jQuery library, it's really easy to reference a data attribute: $("#someLink").data("name") for something like Click Me -- the .data("name") is simply for data-name.