I have an API that's showing almost 100 trades that I want to limit to just 10. I've tried
if($bitcointrades == 10) break
but that didn't work. Do I run a for loop after I pull the data? Should I break up the functions into two parts as opposed to using elseif to present $trades? Here's what I'm working with:
<?php
require_once('bitcoin.class.php');
$data = new Bitcoin();
$type = $_GET['type'];
$currency = $_GET['currency'];
if($type == 'ticker') {
$bitcoinlive = $data->getPrice($currency);
echo '<h2>1 Bitcoin is currently worth <span class="bitvalue">' .
number_format((float)$bitcoinlive['last'], 2) . ' <span class="upper">'
. $currency . '</span></span></h2>';
echo ' <p><span><i class="icon-arrow-up-circle"></i> High: ' .
number_format((float)$bitcoinlive['high'], 2) . '</span> <span><i
class="icon-arrow-down-circle"></i> Low: ' .
number_format((float)$bitcoinlive['low'], 2) . '</span>';
} elseif($type == 'trades') {
$bitcointrades = $data->getTrades($currency);
foreach($bitcointrades as $trade) {
if($trade['type'] == 'buy') {
$ttype = '<span class="green"><i class="icon-plus-circle"></i> Buy
Order</span>';
} else {
$ttype = '<span class="blue"><i class="icon-circle-minus"></i> Sell
Order</span>';
}
echo' <tr> <th scope="row">' . $ttype . '</th> <td>' . $trade['price']
. ' <span class="upper">' . $currency . '</span></td> <td>' .
$trade['amount'] . '</td> <td>' . $data->timeAgo($trade['date']) .
'</td> </tr>';
}
}
It's normal if($bitcointrades == 10) break isn't going to work.
$bitcointrades should be an array with trades which you define as $trade.
You need to use an iterator i like in the example below:
<?php
$i = 0;
foreach($bitcointrades as $trade) {
if($i==10)
break;
// your logic here
$i++;
}
You can finish a foreach execution using break so you can use a cnt and break
$my_cnt = 0;
foreach($bitcointrades as $trade) {
if ($my_cnt >= 10) {
break;
}
if($trade['type'] == 'buy') {
$ttype = '<span class="green"><i class="icon-plus-circle"></i> Buy
Order</span>';
} else {
$ttype = '<span class="blue"><i class="icon-circle-minus"></i> Sell
Order</span>';
}
$my_cnt++;
}
Do Like this way
$i = 0;
foreach ($bitcointrades as $trade) {
if ($trade['type'] == 'buy') {
$ttype = '<span class="green"><i class="icon-plus-circle"></i> Buy Order</span>';
} else {
$ttype = '<span class="blue"><i class="icon-circle-minus"></i> Sell Order</span>';
}
echo ' <tr> <th scope="row">' . $ttype . '</th> <td>' . $trade['price']
. ' <span class="upper">' . $currency . '</span></td> <td>' .
$trade['amount'] . '</td> <td>' . $data->timeAgo($trade['date']) .
'</td> </tr>';
$i++;
if ($i == 10) {
break;
}
}
Related
This one kills me every time it happens: something that worked just fine the last time it was run doesn't work the next time I try to run it and no changes were made anywhere in the script. Especially this issue because other times it had been awhile since I ran the script so changes had been made in included files that caused the script to not work, but this time, it worked yesterday when I logged off for the day but when I log back on today, it doesn't all of a sudden. Because that makes sense, right?!
The script's functionality is to display data for products stored in MySQL database along with search & sorting options for the more than 1600 products stored(this will be over 14,000 in the future so this needs to be fixed/optimized now to prevent future issues). It's largely unfinished but the main function, displaying the table and data, worked fine yesterday. Also, when I went to check for errors, I discovered an error_log with over 300MB-worth of two repeating errors:
mysqli_connect(): (HY000/1040): Too many connections in ...
mysqli_error() expects parameter 1 to be mysqli, boolean given in ...
I had received this error once before and did some searching to discover that I never closed any of my connections. After adding mysqli_close($db) to all of my functions that opened a connection, the error went away and everything was fine. Now it's throwing the error again even with mysqli_close($db) and I'm at a loss here. And on top of that, I don't understand why it throws this error and continuously repeats till I stop the page reloading instead of just ending the process with one error reported.
Products Table Script
function dispTable($var) {
require 'db-inc.php'; // << Database connection file
require 'dlc-forms.php'; // << Holds $search_bar and $view_per_page forms
// Define and validate variables
$currentpage=$order_by=$limit_view=$query=$column=$direction='';
getVars();
// Query
$sql="SELECT * FROM tbl" . $query . $order_by . $limit_view;
$res=mysqli_query($db, $sql);
$count=mysqli_num_rows($res);
// Display result count
if (($var == 'results') && (isset($_GET['q']))) {$res_count='Search returned ' . $count . ' results.';}
// Loop through result set
if ($var == 'table') {echo '
<table>
<thead>
<tr>
// Not sure about having 2 table headers, but I want
// the search bar to be right above the header row.
<th></th>
<th colspan="2">' . $search_bar . '</th>
</tr>
<tr>
<th>' . sortBtn('id') . '</th>
<th>' . sortBtn('title') . '</th>
<th>' . $view_per_page . '</th>
</tr>
</thead>
<tbody>';
while ($row=mysqli_fetch_assoc($res)) {
$id=$row['id'];
$title=$row['title'];
$link=$row['link'];
echo '<tr><td>' . $id . '</td><td>' . $title . '</td><td>' . $link . '</td></tr>';
} echo '
</tbody>
<tfoot>';
// Display pagination
if (($var == 'pages') && (isset($_GET['view']))) {pagination();}echo '
</tfoot>
</table>';
} mysqli_close($db);
}
Scripts For Reference
function getVars() {
$x='0'; $r='0'; $row=array(); $range='3';
$num='item_num'; $name='item_name'; $btn='item_btn';
if (isset($_GET['search'])) {
return $search=checkData(trim($_GET['search']));
return $query=" WHERE title LIKE '%" . $search . "%'";
}
if (isset($_GET['col'])) {
return $col=checkData(trim($_GET['col']));
}
if (isset($_GET['sort'])) {
return $dir=checkData(trim(strtoupper($_GET['sort'])));
return $order_by=" ORDER BY " . $col . " " . $dir;
}
if ((isset($_GET['view'])) && (is_numeric($_GET['view']))) {
return $view=checkData(trim($_GET['view']));
return $limit_view=" LIMIT 0," . $view;
}
if ((isset($_GET['page'])) && (is_numeric($_GET['page']))) {
return $page=checkData(trim($_GET['page']));
}
}
function pagination() {
$dbase='thesof73_dlc';
require 'inc/db-inc.php';
getVars();
$tbl_total=mysqli_num_rows(mysqli_query($db, "SELECT * FROM dlc_tbl"));
$total=ceil($tbl_total/$view);
$prev=$currentpage - 1;
$next=$currentpage + 1;
if ($currentpage > $total) {$currentpage=$total;}
if ($currentpage < 1) {$currentpage=1;}
if ($currentpage > 1) {echo '
<li>First</li>
<li>Back</li>';
}
for ($x=($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $total)) {
if ($x == $currentpage) {
echo '<li>' . $x . '</li>';
} else {
echo '<li>' . $x . '</li>';
}
}
}
if ($currentpage != $total) {echo '
<li>Next</li>
<li><a class="material-icons" href="' . htmlspecialchars($_SERVER['PHP_SELF']) . '?page=' . $total . '">Last</a></li>';
} mysqli_close($db);
}
function sortBtn($var) {
if ($var == 'id') {$header='Item No.';}
elseif ($var == 'title') {$header='Product Name';}
getVars();
$asc='asc';
$desc='desc';
if ((isset($_GET['sort'])) && ($col == $var)) {
if ($dir == 'desc') {
return '<a id="sort" href="?q=' . $q . '&sort=' . $desc . '&col=' . $var . '">' . $header . ' <span class="fa fa-sort-' . $desc . '"></span></a>';
} elseif ($dir == 'asc') {
return '<a id="sort" href="?q=' . $q . '&sort=' . $asc . '&col=' . $var . '">' . $header . ' <span class="fa fa-sort-' . $asc . '"></span></a>';
}
} else {
return '<a id="sort" href="?q=' . $q . '&sort=' . $desc . '&col=' . $var . '">' . $header . ' <span class="fa fa-sort"></span></a>';
}
}
I know it's a mess to look at, even worse before I put pieces of the code into functions, but I'm only providing the code for reference seeing as it worked fine yesterday. Thanks in advance!
The following code is displaying product name in one row and quantity,price and subtotal in new row, how to get all these on same row. Output screenshot as been attached below.
code output
<table class="table table-striped table-condensed">
<tbody>
<?php
$r = 1;
$tax_summary = array();
foreach ($rows as $row) {
if (isset($tax_summary[$row->tax_code])) {
$tax_summary[$row->tax_code]['items'] += $row->quantity;
$tax_summary[$row->tax_code]['tax'] += $row->item_tax;
$tax_summary[$row->tax_code]['amt'] += ($row->quantity * $row->net_unit_price) - $row->item_discount;
} else {
$tax_summary[$row->tax_code]['items'] = $row->quantity;
$tax_summary[$row->tax_code]['tax'] = $row->item_tax;
$tax_summary[$row->tax_code]['amt'] = ($row->quantity * $row->net_unit_price) - $row->item_discount;
$tax_summary[$row->tax_code]['name'] = $row->tax_name;
$tax_summary[$row->tax_code]['code'] = $row->tax_code;
$tax_summary[$row->tax_code]['rate'] = $row->tax_rate;
}
echo '<tr><td colspan="2">#' . $r . ': ' . product_name($row->product_name) . ($row->variant ? ' (' . $row->variant . ')' : '') . '<span class="pull-right">' . $row->tax_code . '</span></td></tr>';
echo '<tr><td>' . $this->sma->formatNumber($row->quantity) . ' x ';
if ($row->item_discount != 0) {
echo '<del>' . $this->sma->formatMoney($row->net_unit_price + ($row->item_discount / $row->quantity) + ($row->item_tax / $row->quantity)) . '</del> ';
}
echo $this->sma->formatMoney($row->net_unit_price + ($row->item_tax / $row->quantity)) . '</td><td class="text-right">' . $this->sma->formatMoney($row->subtotal) . '</td></tr>';
$r++;
}
?>
</tbody>
<tfoot>
<tr>
Try below, but probabbly the formatting will be broken:
<table class="table table-striped table-condensed">
<tbody>
<?php
$r = 1;
$tax_summary = array();
foreach ($rows as $row) {
if (isset($tax_summary[$row->tax_code])) {
$tax_summary[$row->tax_code]['items'] += $row->quantity;
$tax_summary[$row->tax_code]['tax'] += $row->item_tax;
$tax_summary[$row->tax_code]['amt'] += ($row->quantity * $row->net_unit_price) - $row->item_discount;
} else {
$tax_summary[$row->tax_code]['items'] = $row->quantity;
$tax_summary[$row->tax_code]['tax'] = $row->item_tax;
$tax_summary[$row->tax_code]['amt'] = ($row->quantity * $row->net_unit_price) - $row->item_discount;
$tax_summary[$row->tax_code]['name'] = $row->tax_name;
$tax_summary[$row->tax_code]['code'] = $row->tax_code;
$tax_summary[$row->tax_code]['rate'] = $row->tax_rate;
}
echo '<tr><td colspan="2">#' . $r . ': ' . product_name($row->product_name) . ($row->variant ? ' (' . $row->variant . ')' : '') . '<span class="pull-right">' . $row->tax_code . '</span>';
echo '' . $this->sma->formatNumber($row->quantity) . ' x ';
if ($row->item_discount != 0) {
echo '<del>' . $this->sma->formatMoney($row->net_unit_price + ($row->item_discount / $row->quantity) + ($row->item_tax / $row->quantity)) . '</del> ';
}
echo $this->sma->formatMoney($row->net_unit_price + ($row->item_tax / $row->quantity)) . '' . $this->sma->formatMoney($row->subtotal) . '</td></tr>';
$r++;
}
?>
</tbody>
I have a php leaderboard and it works great, and works well with ties. Currently it will number users from 1st to last place (whichever # that is), and if there are ties, it lists them all out with the same number.
For example:
userC 2. userG 3. userA 3. userT 3. userJ 4. userW 5. userP
What I would like is for when there are ties, for the leaderboard to display a "(t)" next to the number, like so: (t) 3. userT
Here is my code, any help is appreciated:
<table cellpadding="4" cellspacing="0" class="table1" width="100%"><caption>
<h2>Leaderboard</h2>
</caption>
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
$playerTotals = sort2d($playerTotals, 'score', 'desc');
$i = 1;
$tmpScore = 0;
//show place #
foreach($playerTotals as $playerID => $stats) {
if ($tmpScore < $stats[score]) $tmpScore = $stats[score];
//if next lowest score is reached, increase counter
if ($stats[score] < $tmpScore ) $i++;
$pickRatio = $stats[score] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($stats[score] / $possibleScoreTotal) * 100), 2) . '%';
//display users/stats
$rowclass = ((($i - 1) % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . $i . '</b>. ' . $stats[userName] . '</td><td align="center">' . $stats[wins] . '</td><td align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
$tmpScore = $stats[score];
}
}
echo ' </div>' . "\n";
?>
</table>
Try this code... hope it will resolve your issue
<table cellpadding="4" cellspacing="0" class="table1" width="100%">
<caption><h2>Leaderboard</h2></caption>
<tr><th align="left">Player</th><th align="left">Wins</th><th>Pick Ratio</th></tr>
<?php
if (isset($playerTotals)) {
$playerTotals = sort2d($playerTotals, 'score', 'desc');
$j = 1;
$tmpScore = 0;
//show place #
$tieflag=false;
for($i=0; $i<=count($playerTotals)-1; $i++) {
if(($i<count($playerTotals) && $playerTotals[$i][score]==$playerTotals[$i+1][score]) || ($i>0 && $playerTotals[$i][score]==$playerTotals[$i-1][score])) $tieflag=true;
$pickRatio = $$playerTotals[$i][score] . '/' . $possibleScoreTotal;
$pickPercentage = number_format((($playerTotals[$i][score] / $possibleScoreTotal) * 100), 2) . '%';
$rowclass = ((($j - 1) % 2 == 0) ? ' class="altrow"' : '');
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . ($tieflag?'(t)'.$j:$j) . '</b>. ' . $playerTotals[$i][userName] . '</td><td align="center">' . $playerTotals[$i][wins] . '</td><td align="center">' . $pickRatio . ' (' . $pickPercentage . ')</td></tr>';
$j++;
}
}
echo '</div>'. "\n";
?>
</table>
I'd create a new variable $placeholder. So:
if ( $i != 0 ) {
if ($tmpScore < $stats[score]) {
$tmpScore = $stats[score];
}
if ( $tmpScore == $stats[score] ) {
$placeholder = $i.'(t)';
} else if ($stats[score] < $tmpScore )
$placeholder = $++i;
}
} else {
$placeholder = $++i;
$firstScore = $stats[score];
$tmpScore = $stats[score];
}
Then instead of printing $i print $placeholder
so for the first time through you could do this in the echo:
//It makes more sense if you read it from bottom to top but I put it this way
//so you will not have to keep running through every condition when you will
//only evaluate the first condition most often
if ( $i != 0 && $i != 1 ) {
echo ;//Your normal print
} else if ( $i = 1 && $tmpScore != $firstScore ) {
echo '<b>'; //and the rest of the first line plus second line NOT a tie
} else if ( $i = 1 ) {
echo ' (t)'; //Plus the rest of your first line plus second line TIE
} else {
//This is your first time through the loop and you don't know if it's a tie yet so just
//Print placeholder and then wait to figure out the rest
echo ' <tr' . $rowclass . '><td style="height: 25px;"><b>' . $placeholder;
}
I have a script which retrieves all rows of data within a sales list (npc_sales_list) but what I am trying to do is set up a drop down menu which filters the results oand I don't know where to start as I haven't done any php in while.
The main filters I am trying to do are to see the previous month's sales only (npc_entry_date) and the sales type (npc_usertype). If someone could point me in the right direction or show me some resource links that would be great.
Im not fussed whether the filter is automatic or if you need to hit a submit button. Any suggestions welcome...
<?php
require_once ('./includes/config.inc.php');
$page_title = 'Page title';
include ('./includes/header.html');
if (!isset($_SESSION['admin_sp_id'])) {
$url = 'http://' . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1);
}
$url .= '/login.php';
ob_end_clean();
header("Location: $url");
exit();
}
require_once ('database.php');
$display = 500;
if (isset($_GET['np'])) {
$num_pages = $_GET['np'];
} else {
$query = "SELECT COUNT(*) FROM npc_sales_list ORDER BY npc_entry_date DESC";
$result = #mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];
if ($num_records > $display) {
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
$link1 = "{$_SERVER['PHP_SELF']}?sort=fna";
$link2 = "{$_SERVER['PHP_SELF']}?sort=lna";
if (isset($_GET['sort'])) {
switch ($_GET['sort']) {
case 'fna':
$order_by = 'sp_firstname ASC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=fnd";
break;
case 'fnd':
$order_by = 'sp_firstname DESC';
$link1 = "{$_SERVER['PHP_SELF']}?sort=fna";
break;
case 'lna':
$order_by = 'sp_surname ASC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=lnd";
break;
case 'lnd':
$order_by = 'sp_surname DESC';
$link2 = "{$_SERVER['PHP_SELF']}?sort=lna";
break;
default:
$order_by = 'npc_entry_date DESC';
break;
}
// $sort will be appended to the pagination links.
$sort = $_GET['sort'];
} else { // Use the default sorting order.
$order_by = 'npc_entry_date DESC';
$sort = 'drd';
}
$query = "SELECT us.sp_firstname , us.sp_surname , us.sp_amb_club_no , us.sp_position_title , us.sp_dealer_name ,
us.sp_dealer_code , us.sp_region , us.sp_department, sp_business_phone, us.sp_mobile_phone , us.sp_dealer_category, us.sp_email,
sa.npc_item_id , sa.npc_part_no, sa.npc_quantity, sa.npc_customer_name, sa.npc_registration_no , sa.npc_suo_no , sa.npc_amb_club_no , sa.npc_repair_order , sa.npc_invoice_no ,
sa.npc_entry_userdate, sa.npc_image_upload, sa.npc_usertype, sa.npc_points, sa.npc_bonus_points, sa.npc_active, sa.npc_entry_date,
DATE_FORMAT(sa.npc_entry_date, '%d-%m-%Y') AS dr , sa.sp_user_id
FROM sp_user AS us, npc_sales_list AS sa
WHERE us.sp_user_id = sa.sp_user_id
ORDER BY
$order_by LIMIT $start, $display";
$result = #mysql_query ($query);
//
// Table header.
echo '<table width="100%" cellspacing="1" cellpadding="4" style="font-size:10px;">
<tr>
<td align="center"><b>Invoice No.</b></td>
<td align="center"><b>Member ID</b></td>
<td align="center"><b>Surname</b></td>
<td align="center"><b>Part #</b></td>
<td align="center"><b>Sale Type</b></td>
<td align="center"><b>Qty</b></td>
<td align="center"><b>Invoice Date</b></td>
<td align="center"><b>Customer Rego</b></td>
<td align="center"><b>Submission Date</b></td>
<td align="center"><b>Status</b></td>
</tr>';
// Fetch and print all the records. echo '<td align="left"><strong>' . $row['sp_invoice_no'] . '</strong></td> ';
$bg = '#ffffff'; // Set the background color.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bg = ($bg=='#eaeced' ? '#ffffff' : '#eaeced');
echo '<tr bgcolor="' . $bg . '">';
echo '<td align="center"><strong>Details</strong></td> ';
echo '<td align="center"><strong>' . $row['sp_amb_club_no'] . '</strong></td> ';
echo '<td align="center"><strong>' . $row['sp_surname'] . '</strong></td> ';
echo '<td align="center"> <strong>' . $row['npc_part_no'] . '<strong></td>';
echo '<td align="center"> ' . $row['npc_usertype'] . ' </td>';
echo '<td align="center"> ' . $row['npc_quantity'] . ' </td>';
echo '<td align="center"> ' . $row['npc_entry_userdate'] . ' </td>';
echo '<td align="center"> ' . $row['npc_registration_no'] . ' </td>';
echo '<td align="center"> ' . $row['dr'] . ' </td>';
echo '<td align="center" style="color:#5a8e22; font-weight:bold;"> ' . $row['npc_active'] . ' </td>';
echo '</tr>
';
}
echo '</table>';
mysql_free_result ($result);
mysql_close();
if ($num_pages > 1) {
echo '<br /><p>';
$current_page = ($start/$display) + 1;
if ($current_page != 1) {
echo '<a href="view-all-sales.php?s=' . ($start - $display) . '&np=' .
$num_pages . '&sort=' . $sort .'">Previous</a> ';
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="view-all-sales.php?s=' . (($display * ($i - 1))) .
'&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> ';
} else {
echo $i . ' ';
}
}
if ($current_page != $num_pages) {
echo '<a href="view-all-sales.php?s=' . ($start + $display) . '&np=' .
$num_pages . '&sort=' . $sort .'">Next</a> ';
}
echo '</p>';
}
include ('./includes/footer_admin_user.html');
?>
I'm working on the php code of someone else and have a problem with the user/menu language. This is the code of the page with the dynamic price list for banner ads on this website. Depending on the selected menu language, the user can see the price of the banner ads which are for each menu language different.
Whenever the user is coming to this page the active banner ads price should be for the users menu language. Right now it's fixed on russian language and I don't know how to make it dynamicly or at least change/fix it to english.
Please have a look and let me konw if you might see a solution. Thanks!
<?php
class reklama_content
{
private $db;
private $cms;
private $valid;
private $data;
private $tools;
public function __construct()
{
$reg = Registry::getInstance();
$this->db = $reg->get('db');
$this->cms = $reg->get('cms');
$this->valid = $reg->get('Validate');
$this->data = $reg->get('methodData');
$this->tools = $reg->get('tools');
}
public function get_reklama_content()
{
$lang = language::getLang();
if ($_GET['ryb'])
$ryb = $_GET['ryb'];
else
$ryb = 'banners';
if ($ryb == 'banners')
$ret = $this->getBanner($lang);
elseif ($ryb == 'classifieds')
$ret = $this->getClassifieds($lang);
return $ret;
}
public function getClassifieds($lang)
{
$contetn = $this->db->selectArray($this->db->Select('*', 'block', "`name` = 'classifieds_content'"));
$ret = $contetn['content_' . $lang];
return $ret;
}
public function getBanner($lang)
{
$header = array();
$top = array();
$center = array();
$bottom = array();
$banners = $this->db->selectAssoc($this->db->Select('*', 'banners', false, 'page_id', false, true));
$contetn_top = $this->db->selectArray($this->db->Select('*', 'block', "`name` = 'reklams_baner_top'"));
$contetn_bottom = $this->db->selectArray($this->db->Select('*', 'block', "`name` = 'reklams_baner_bottom'"));
foreach ($banners as $x => $y) {
if ($y['position'] == 'header')
$header[$x] = $y;
elseif ($y['position'] == 'top')
$top[$x] = $y; elseif ($y['position'] == 'center')
$center[$x] = $y; elseif ($y['position'] == 'bottom')
$bottom[$x] = $y;
}
$ret = $contetn_top['content_' . $lang];
$langs = ($this->tools->getAllLang(true));
$ret .= '
<hr style="width: 100%; margin: 40px 0;" />
<div class="rek_banner_conteiner header_conteiner">
<span class="ban_title">' . l::top_banner1() . '</span>
<img src="styles/them_01/img/banner_468x60.jpg" class="header_example" />
<div class="lang_menu">' . l::menu_language1() . '<br />';
$ret .= '<span id="eng_header" >' . l::english() . '</span>';
$ret .= '<span id="de_header" >' . l::german() . '</span>';
$ret .= '<span id="rus_header" >' . l::russian() . '</span>';
$ret .= '<span id="tr_header" >' . l::turkish() . '</span>';
$ret .= '</div>';
foreach ($langs as $z => $g) {
$ret .= '
<div id="' . $g['name'] . '_header_box" class="hide">
<table>
<tr class="order_table_title">
<td class="order_table_position">' . l::location() . '</td>
<td class="order_table_size">' . l::size1() . '</td>
<td class="order_table_date">' . l::fee_per_month() . '</td>
</tr>
';
foreach ($header as $z => $f) {
$page = $this->db->selectArray($this->db->Select('title_' . $lang, 'pages', "`id` = '" . $f['page_id'] . "'"));
$ret .= '<tr>
<td>' . $page['title_' . $lang] . '</td>
<td>' . $f['size'] . '</td>
';
if ($f['price' . '_header_' . $g['name']])
$ret .= '<td>$ ' . $f['price' . '_header_' . $g['name']] . '</td>';
else
$ret .= '<td></td>';
$ret .= '
</tr>';
}
$ret .= '
</table>
</div>
';
}
$ret .= '</div>';
$ret .= $contetn_bottom['content_' . $lang];
return $ret;
}
}
?>
I have code in an answer about language detection here. It contains a cool little easily modifiable snippet I use to check who's coming from where based on their browser preferences for language. In short, you'll need to either detect the language from $_SERVER['HTTP_ACCEPT_LANGUAGE'] or detect a user preference (eg. ?lang=de ) to override their default language preference in their browser. That's if you're not using a custom URL like tr.example.com. Then you can do a switch(). Right now it looks like you're concatenating all of the language <span> tags together.
switch($lang){
case "ru":
//Russian
$ret .= '<span id="rus_header" >' . l::russian() . '</span>';
break;
case "de":
//German
$ret .= '<span id="de_header" >' . l::german() . '</span>';
break;
case "tr":
//Turkish
$ret .= '<span id="tr_header" >' . l::turkish() . '</span>';
break;
default:
//English
$ret .= '<span id="eng_header" >' . l::english() . '</span>';
}
As my other post says (there's a video from Google). Ideally it's best if you have the content all in one language on a specific URL for that language. Then all of this magical language translation stuff happens without the user having to make a selection or guess if they're clicking the correct link in a language they're not familiar with.