If statment to echo an image if var=EUR doesnt work - php

This code added currency switcher to a menu,
But unfortunately I don't have access to MySQL database so I can't add image "flag" to each currency, then execute them
So I tried to use if statement.
This is my code:
$currency_switcher_enable = houzez_option('currency_switcher_enable');
$is_multi_currency = houzez_option('multi_currency');
if( $currency_switcher_enable != 0 && $is_multi_currency != 1 ) {
if (class_exists('FCC_Rates')) {
$supported_currencies = houzez_get_list_of_supported_currencies();
if (0 < count($supported_currencies)) {
$current_currency = houzez_get_wpc_current_currency();
echo '<li class="btn-price-lang btn-price">';
echo '<form id="houzez-currency-switcher-form" method="post" action="#" class="open">';
echo '<button id="houzez-selected-currency" class="btn dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span>' . $current_currency . '</span> <i class="fa fa-sort"></i></button>';
echo '<ul id="houzez-currency-switcher-list" class="dropdown-menu" aria-labelledby="dropdown" style="display:none;">';
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
if (data-currency-code='EUR') {
echo '<img src="images/euro-flag.png"';
if (data-currency-code='TR') {
echo '<img src="images/turkish-flag.png"';
}
}
echo '</ul>';
echo '<input type="hidden" id="houzez-switch-to-currency" name="houzez_switch_to_currency" value="' . $current_currency . '" />';
echo '<input type="hidden" id="currency_switch_security" name="nonce" value="' . wp_create_nonce('houzez_currency_converter_nonce') . '"/>';
echo '</form>';
echo '</li>';
}
}
}
?>
But it doesn't work? What I'm doing wrong?
This is the original code:
$currency_switcher_enable = houzez_option('currency_switcher_enable');
$is_multi_currency = houzez_option('multi_currency');
if( $currency_switcher_enable != 0 && $is_multi_currency != 1 ) {
if (class_exists('FCC_Rates')) {
$supported_currencies = houzez_get_list_of_supported_currencies();
if (0 < count($supported_currencies)) {
$current_currency = houzez_get_wpc_current_currency();
echo '<li class="btn-price-lang btn-price">';
echo '<form id="houzez-currency-switcher-form" method="post" action="#" class="open">';
echo '<button id="houzez-selected-currency" class="btn dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span>' . $current_currency . '</span> <i class="fa fa-sort"></i></button>';
echo '<ul id="houzez-currency-switcher-list" class="dropdown-menu" aria-labelledby="dropdown" style="display:none;">';
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
}
echo '</ul>';
echo '<input type="hidden" id="houzez-switch-to-currency" name="houzez_switch_to_currency" value="' . $current_currency . '" />';
echo '<input type="hidden" id="currency_switch_security" name="nonce" value="' . wp_create_nonce('houzez_currency_converter_nonce') . '"/>';
echo '</form>';
echo '</li>';
}
}
}
?>

You have many fails here:
The first is as #kerbh0lz mentioned, the "=" and "==" is not the same purpose. here yours is wrong.
Second your second currency If is in the 1st Currency If so it wont ever pass by.
Third you are comparing a string without quote or a var without $ before data-currency-code so instead you should use $currency_code
Try this:
foreach ($supported_currencies as $currency_code) {
echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';
if ($currency_code =='EUR')
echo '<img src="images/euro-flag.png"';
elseif ($currency_code == 'TR')
echo '<img src="images/turkish-flag.png"';
}

Related

PHP function to make more values = 0 if an id = 52 (value)

Hello i have a table when i want to display some td value = 0 if the status of the task has the id=52!
Down i will put a picture of the table!
I tried to use this code for that:
if ($status['id']) { $calC = $calCminusrealcost = $realCost =0; }
Here $calC, $calCminusrealcost and $realCost are the values i want to become 0!
Here is the pucture of the table: [!https://i.stack.imgur.com/YWOwb.png][1]][1]
So after i use this code it works but in general for all tasks, not just for those which have the id = 52, and if i try to replace id with 52 in the function it doesn't work!
Does someone know what can I do?
this is the full code i have about status:
$outputStatus = '';
$outputStatus .= '<span class="inline-block label" style="color:' . $status['color'] . ';border:1px solid ' . $status['color'] . '" task-status-table="' . $aRow['status'] . '">';
$outputStatus .= $status['name'];
if ($canChangeStatus) {
$outputStatus .= '<div class="dropdown inline-block mleft5 table-export-exclude">';
$outputStatus .= '<a href="#" style="font-size:14px;vertical-align:middle;" class="dropdown-toggle text-dark" id="tableTaskStatus-' . $aRow['id'] . '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">';
$outputStatus .= '<span data-toggle="tooltip" title="' . _l('ticket_single_change_status') . '"><i class="fa fa-caret-down" aria-hidden="true"></i></span>';
$outputStatus .= '</a>';
$outputStatus .= '<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="tableTaskStatus-' . $aRow['id'] . '">';
foreach ($task_statuses as $taskChangeStatus) {
if ($aRow['status'] != $taskChangeStatus['id']) {
$outputStatus .= '<li>
<a href="#" onclick="task_mark_as(' . $taskChangeStatus['id'] . ',' . $aRow['id'] . '); return false;">
' . _l('task_mark_as', $taskChangeStatus['name']) . '
</a>
</li>';
}
}
if ($status['id']) {
$calC = $calCminusrealcost = $realCost =0;
}
$outputStatus .= '</ul>';
$outputStatus .= '</div>';
}
$outputStatus .= '</span>';
$row[] = $outputStatus;
[1]: https://i.stack.imgur.com/YWOwb.png

PHP Why Else statment strangely doesnt work

I have this following piece of code
include_once("config/connection.php");
$sql = "SELECT * FROM qqqq WHERE LOWER(pdf_ad) LIKE '%" . $aranacak_metin . "%'";
$result = $DBcon->query($sql);
if ($result && is_array($result) && count($result) > 0) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$yeniad = seo($row['pdf_ad']);
echo '<form action="/indir/' . $yeniad . '/' . $row['pdf_liste_no'] . '" id="sorgu" method="post">';
echo '<li class="list-group-item">';
echo '<input type="hidden" name="id" value="' . $row['pdf_liste_no'] . '">';
echo '<input type="hidden" name="name" value="' . $row['pdf_ad'] . '">';
echo '<img alt="' . $row['pdf_ad'] . '" src="' . $row['pdf_resim'] . '" width=120" height="150"><a style="font-size:20px; text-decoration:none; color:black;" href="#"> ' . $row['pdf_ad'] . '</a> ';
echo '<button type="submit" class="btn btn-success">';
echo '<i class="fa fa-arrow-circle-right fa-lg"></i>';
echo '</button>';
echo '</li>';
echo '</form>';
}
} else {
echo $aranacak_metin;
}
if statement does its job if the result is set shows the rows but if there is no match in DB else statement
doesnt work am i missing something need your help thank you
update:it turns else everytime now
in current scenario $result is always set. so just check you got any match record or not, based on that put conditions as below.
if($result && $result->num_rows && $result->num_rows > 0){
} else {
}
if its PDO query then
if($result && is_array($result) && count($result) > 0){
} else {
}
Try below code:
if ( is_array($result) && count($result) > 0 ) {
// staff
} else {
echo $aranacak_metin;
}
Changed my php version it worked ?

Wordpress Coding Issue

Being a complete numpty at this....
I am having troubles getting the below code to work (just shows the white screen of death)
case 'venue' :
if( self::isValid($atts['venue'])) {
$output .= '<td>' . apply_filters( 'ecs_event_list_venue', tribe_get_venue(), $atts ) . '</span></td>';
if( !empty(tribe_get_event_website_link()) ) {
$output .= '<td><a class="btn btn-danger btn-small" href="' . tribe_get_event_website_link() . '">Bookings</a></td>';
} else {
$output .= '<td><a class="btn btn-danger btn-small" href="' . tribe_get_event_link() . '">Read More</a></td>';
}
}
}
break;
The original code was
case 'venue' :
if( self::isValid($atts['venue'])) {
$output .= '<td>' . apply_filters( 'ecs_event_list_venue', tribe_get_venue(), $atts ) . '</span></td>';
}
break;
This works fine..
Any assistance appreciated and respected!!
You can try this :
if( self::isValid($atts['venue'])) {
$output .= '<td>' . apply_filters( 'ecs_event_list_venue', tribe_get_venue(), $atts ) . '</span></td>';
$is_value = tribe_get_event_website_link();
if( !empty($is_value) ) {
$output .= '<td><a class="btn btn-danger btn-small" href="' . tribe_get_event_website_link() . '">Bookings</a></td>';
} else {
$output .= '<td><a class="btn btn-danger btn-small" href="' . tribe_get_event_link() . '">Read More</a></td>';
}
}
You can't use function return value like this.

How to sort from for each in PHP

From an array I start for each entry a function with a argument from the array (its friends from facebook). The function returns either 0 or a number bigger than 0. So at the moment, it justs displays it all mixed up, but I want it to show first all entries which get the result bigger than 0 from the function and then all, which are 0. I've no idea, how to do this.
This is my current code.
foreach ($friends as $key=>$value) {
//removed unimportant things
$friendresult = friendscore($id = $fvalue[id]);
if ($friendresult == "0") {
echo '<li>';
echo '<a class="box" href="javascript:invite('. $fvalue[id] . ')">';
echo '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
echo '<label>' . $fvalue[name] . '</label>';
echo '<b>Invite</b>';
echo '</a>';
echo '</li>';
}
if ($friendresult !=="0"){
echo '<li>';
echo '<a class="box">';
echo '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
echo '<label>' . $fvalue[name] . '</label>';
echo '<div class="totaltext">Score:'.$friendresult. '</div>';
echo '</a>';
echo '</li>';
}}
Edit: Found solution. Sometimes its too simple.
if ($friendresult == "0") {
$friend.= '<li>';
$friend.= '<a class="box" href="javascript:invite('. $fvalue[id] . ')">';
$friend.= '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
$friend.= '<label>' . $fvalue[name] . '</label>';
$friend.= '<b>Invite</b>';
$friend.= '</a>';
$friend.= '</li>';
}
if ($friendresult !="0"){
$nofriend.= '<li>';
$nofriend.= '<a class="box">';
$nofriend.= '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
$nofriend.= '<label>' . $fvalue[name] . '</label>';
$nofriend.= '<div class="totaltext">Score:'.$friendresult. '</div>';
$nofriend.= '</a>';
$nofriend.= '</li>';
}
echo $friend.$nofriend;

Could this code be cleaner?? It looks a right state?

I have this code to pull data from the database and insert the data into one of 4 columns,
I have spent a whole day searching and just cant seem to find out how to do it..
Ideally, I want to select all from database and then where the fetch array has a column id of 1 - echo that then the sama for the next column etc..
<?php
echo '<div class="column grid_3 clearfix" id="column0" >';
echo ' ';
$user_sites_0=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='0' ORDER BY sort_no");
if(!$user_sites_0) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else {
while($user_site_0=mysqli_fetch_array($user_sites_0))
{
$id = stripslashes($user_site_0['id']);
$site_name = stripslashes($user_site_0['site_name']);
$site_address = stripslashes($user_site_0['site_address']);
$site_desc = stripslashes($user_site_0['site_desc']);
$site_category = stripslashes($user_site_0['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_0['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column1" >';
echo ' ';
$user_sites_1=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='1' ORDER BY sort_no");
if(!$user_sites_1) {
echo '';
}
else {
while($user_site_1=mysqli_fetch_array($user_sites_1))
{
$id = stripslashes($user_site_1['id']);
$site_name = stripslashes($user_site_1['site_name']);
$site_address = stripslashes($user_site_1['site_address']);
$site_desc = stripslashes($user_site_1['site_desc']);
$site_category = stripslashes($user_site_1['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_1['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column2">';
echo ' ';
$user_sites_2=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='2' ORDER BY sort_no");
if(!$user_sites_2) {
echo '';
}
else {
while($user_site_2=mysqli_fetch_array($user_sites_2))
{
$id = stripslashes($user_site_2['id']);
$site_name = stripslashes($user_site_2['site_name']);
$site_address = stripslashes($user_site_2['site_address']);
$site_desc = stripslashes($user_site_2['site_desc']);
$site_category = stripslashes($user_site_2['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_2['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column3">';
echo ' ';
$user_sites_3=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='3' ORDER BY sort_no");
while($user_site_3=mysqli_fetch_array($user_sites_3))
{
$id = stripslashes($user_site_3['id']);
$site_name = stripslashes($user_site_3['site_name']);
$site_address = stripslashes($user_site_3['site_address']);
$site_desc = stripslashes($user_site_3['site_desc']);
$site_category = stripslashes($user_site_3['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_3['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
echo '</div>';
?>
The code looks a right state.. Could I do it better?
Use for and change the code, some code :
<?php
for ($i=0; $i<4; $i++)
{
echo '<div class="column grid_3 clearfix" id="column'.$i.'" >';
echo ' ';
$user_sites=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='".$i."' ORDER BY sort_no");
if(!$user_sites) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else
{
while($user_site=mysqli_fetch_array($user_sites))
{
... // Do it yourself
maybe
function get_site($column_id){
$str = "";
$user_sites = mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='".$column_id."' ORDER BY sort_no");
if(!$user_sites_0) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else {
while($user_site_0=mysqli_fetch_array($user_sites_0))
{
$id = stripslashes($user_site_0['id']);
$site_name = stripslashes($user_site_0['site_name']);
$site_address = stripslashes($user_site_0['site_address']);
$site_desc = stripslashes($user_site_0['site_desc']);
$site_category = stripslashes($user_site_0['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
$str.= '<div class="dragbox" id="item'.$id.'">';
$str.= '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
$str.= '<div class="dragbox-content" ';
if($user_site_0['collapsed']==1)
echo 'style="display:none;" ';
$str.= '>';
$str.= '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
$str.= '<p>' . $site_category . '</p>';
$str.= '<p>' . $site_address . '</p>';
$str.= '<p>' . $site_desc . '</p>';
$str.=' </div>
</div>';
}
}
$str.='</div>';
return $str;}
echo '<div class="column grid_3 clearfix" id="column0">';
echo ' ';
echo oget_site(0);
echo '<div class="column grid_3 clearfix" id="column1">';
echo ' ';
echo oget_site(1);
//....

Categories