Im on a dynamic webpage written in php and would like to have an if else statement that would look inside mysql database table and check if the string "description" is present inside a certain database table column. if the word "description" is present echo "Visit Discounted Venue" text inside the button, else echo "Visit venue website" string inside the button.
I currently have the code below, its in a php file.
<?php if(stripos( $forum_data['venue_url_text'],"discount") == false) ?>
VISIT VENUE WEBSITE
<?php elseif: ?>
VISIT DISCOUNTED VENUE
<?php endif: ?>
<?php
if(stripos( $forum_data['venue_url_text'],"discount") == false)
{
echo '<button class="btn" target="_blank" rel="nofollow"> VISIT VENUE WEBSITE </button>';
}
else {
echo '<button class="btn" target="_blank" rel="nofollow"> VISIT DISCOUNTED VENUE</button>';
}
?>
I don't know if you're using button or input, so replace <button> with <input type="submit" value="VISIT ..." /> if you want input instead of button.
UPDATE: sorry i coded it bad, updated
Try this:
<? if (stripos( $forum_data['venue_url_text'],"discount") !== false): ?>
<a class="btn" target="_blank" rel="nofollow"> VISIT DISCOUNTED VENUE </a>
<? else: ?>
<a class="btn" target="_blank" rel="nofollow"> VISIT VENUE WEBSITE </a>
<? endif; ?>
Hope this helps.
You have to put a colon (:) after if statement declaration, to change elseif condition with else and to put a semicolon (;) instead of colon after endif:
<?php if(stripos( $forum_data['venue_url_text'],"discount") == false): ?>
VISIT VENUE WEBSITE
<?php else: ?>
VISIT DISCOUNTED VENUE
<?php endif; ?>
Heres my solution, using php and regexp:
<?php
$venue_url_button = "Venue Website";
if(preg_match('/discount(.*)/i',$forum_data['venue'['venue_url_text']) ) {
$venue_url_button = "CLICK FOR DISCOUNTED HOTEL ROOMS"; }
else{
$venue_url_button = "CLICK TO VISIT VENUE WEBSITE";
}
?>
Related
I am looping through some images of houses where all have a link to the house detail page. But i have one image that is in the that has a different link where it is being linked to the staff page.
Issue
How do i get that one link to go to the Staff detail page. I have tried to show different blocks of code depending on what class is inserted from the CMS? any suggestions?
<?php
$page_link = team;
if ( $page_link == {#page} ) {
?>
<a href="/team" class="{#remove_link} {#page}" >
<div class="project {#grey_scale} grid-item {#tile_size_width} {#tile_size_height}" style="background:url('{#image_1}{#video_image}');background-size: cover; background-position:center;">
</div>
</a>
<?php
} else {
?>
<a href="{#guid}" class="{#remove_link} {#page}" >
<div class="project {#grey_scale} grid-item {#tile_size_width} {#tile_size_height}" style="background:url('{#image_1}{#video_image}');background-size: cover; background-position:center;">
</div>
</a>
<?php
}
?>
First of all, you dont need to duplicate the whole HTML. You could just set the if around the <a> like:
<?php
$page_link = "team";
if ( $page_link == {#page} ) {
?>
<a href="/team" class="{#remove_link} {#page}" >
<?php } else { ?>
<a href="{#guid}" class="{#remove_link} {#page}" >
<?php } ?>
You need to know what is on {#page}. If it's "team", then you can do your if thing. If not, you have to adjust your $page_link to the same of your {#page} var.
If your team-page adress is something like stansmith.com/pages/team, then you have to change the <a href="/team"> to <a href="/pages/team">.
Please tell me if you need more help.
I want a button to show on my navigation bar only if the page is = to employees.
I was doing this to accomplish this.
on employees.php
<?php $pg = employees; ?>
on header.php
<?php
if ($pg == $employees)
?>
<?php
<a class="btn btn-info" href="https://www.ebillity.com/Firm4.0/Login.aspx?CorpLogin=1">Time Sheets</a>
?>
Here is the error im getting in the browser
Parse error: syntax error, unexpected '<' in /Applications/XAMPP/xamppfiles/htdocs/lpnew/includes/header.php on line 60
You have done some typing errors, so you have got an error
on employees.php
<?php $pg = $employees; ?>
on header.php
<?php
if($pg == $employees){
?>
<a class="btn btn-info" href="https://www.ebillity.com/Firm4.0/Login.aspx?CorpLogin=1">Time Sheets</a>
<?php } ?>
The error you are getting is because you aren't using echo on your link and you need to swap your double quotes for single quotes.
Try this for your link:
echo "<a class='btn btn-info' href='https://www.ebillity.com/Firm4.0/Login.aspx?CorpLogin=1'>Time Sheets</a>";
It looks like your if statement is not finished either you don't have anything in {}. It also appears you are trying to call the current page? I'm making a few assumptions but try this:
if (basename($_SERVER['PHP_SELF'])== 'employee.php'){
//do something
}
else{
//do something else
}
Please can someone help me with this. I have this MySQL query which lists users on my site, and echos a link that can be clicked to take you to the user's profile:
<?php
$online_set = online_channel();
while ($online = mysql_fetch_array($online_set)) {
echo "<div class=\"online_row\"><img width=25px height=25px src=\"data/photos/{$online['user_id']}/_default.jpg\" class=\"online_image\"/><div class=\"online_text\">{$online['display_name']}</div></div>";?>
<? } ?>
The link goes to profile.php and echos the users 'user_id' so it knows which users profile to take you to, and now I am wanting to include a session variable in the link somehow so a message is displayed on that users profile after clicking the link.
I have tried including $_SESSION['chat'] in the link but it doesn't work:
<?php
$online_set = online_channel();
while ($online = mysql_fetch_array($online_set)) {
echo "<div class=\"online_row\"><img width=25px height=25px src=\"data/photos/{$online['user_id']}/_default.jpg\" class=\"online_image\"/><div class=\"online_text\">{$online['display_name']}</div></div>";?>
<? } ?>
I am also trying to execute the session in profile.php by using this:
<?
session_start();
if(isset($_SESSION['chat']))
echo $_SESSION['chat']="<div class=\"infobox-favourites\"><strong>Deleted from Favourites</strong> - This user has successfully been deleted from your favourites.</div><div class=\"infobox-close4\"></div>";
unset($_SESSION['chat']);
?>
What I have tried is not working and i'm not sure i'm doing it right, so I would really appreciate any help with this. Thanks
Try this...for easier debugging the entire code you have
<?php
$online_set = online_channel();
while ($online = mysql_fetch_array($online_set)) {
?>
<div class="online_row">
<a href="profile.php?id=<?php echo $online['user_id'];?>">
<img width=25px height=25px src="data/photos/<?php echo $online['user_id'];?>/_default.jpg/" class="online_image" />
<div class="online_text\">
<?php echo $online['display_name'];?>
</div>
</a>
</div>
<?php
}
?>
Just review the code I posted to learn the better way to echo an entire div
I am trying add an if statement to an anchor like so.
<div class="box-button">
<a href="
<?php $header_button = of_get_option('header_text'); ?>
<?php if($header_button){?>
<?php echo of_get_option('header_text'); ?>
<?php } else { ?>
#
<?php } ?>
" class="button">Connect Now</a>
</div>
I can click the button on the homepage and I will get linked to "#" so it is as if wordpress doesn't recognize as a theme option. Is my syntax the problem?
You know you can do the logic outside the html and then insert the result into the href
<?php
$header_button = of_get_option('header_text');
$link = (!empty($header_button)?$header_button:'#');
?>
<div class="box-button">
Connect Now
</div>
I'm having trouble writing an if else statement. Considering that I've been doing so for years in ColdFusion, this make me feel very stupid.
Here's the task.
I need to pull first name, last name, email, co-chair status from a database and return the results. However not everyone has an email, so I need a statement that will include a mailto link for those that have emails, and exclude a mailto link for those that don't.
Here's the code I'm using that includes the mailto link for all.
What adjustments do I need to make?
thanks,
david
<?php do { ?>
<?php echo $row_GetMembers['BACmember_First']; ?> <?php echo $row_GetMembers['BACmember_Last']; ?>
<?php /*START_PHP_SIRFCIT*/ if ($row_GetMembers['BACmember_CoChair']=="Yes"){ ?>
<strong> Co-Chair</strong>
<?php } /*END_PHP_SIRFCIT*/ ?><br />
<?php } while ($row_GetMembers = mysql_fetch_assoc($GetMembers)); ?>
This is the line of code you want to optionally display as a link (split for readability):
<a href="mailto:<?php echo $row_GetMembers['BACmember_Email']; ?>">
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
</a>
You'll want something like this instead:
<?php if (!empty($row_GetMembers['BACmember_Email'])): ?>
<a href='mailto:<?php echo $row_GetMembers['BACmember_Email']?>>
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
</a>
<?php else: ?>
<?php echo $row_GetMembers['BACmember_First']; ?>
<?php echo $row_GetMembers['BACmember_Last']; ?>
<?php endif; ?>
If the email field isn't empty (the ! negates the result, so we're checking if it isn't empty), it prints the first and last name inside an anchor tag. If it is empty, it prints the name without it.
A more elegant solution may be to provide the email address as a separate field or link, as opposed to having a list of some names that are links and some that aren't.