I have a series of functions that was written by a previous developer and now I am trying to optimize them.
function translateAdmSection() {
$lang = $_REQUEST['lang'];
if($lang == '') {
$content = 'content';
}
if($lang == 'en') {
$content = 'content';
}
if($lang == 'es') {
$content = 'es_content';
}
if($lang == 'fr') {
$content = 'fr_content';
}
if($lang == 'ko') {
$content = 'kr_content';
}
if($lang == 'mdn') {
$content = 'mdn_content';
}
if ($lang == 'pt') {
$content = 'pt_content';
}
$title_query = ("SELECT adm_name, ".$content." as content FROM adm_sect WHERE adm_name = 'title';");
$title_result = mysql_query($title_query);
$title_row = mysql_fetch_assoc($title_result);
$sub_head_query = ("SELECT adm_name, ".$content." as content FROM adm_sect WHERE adm_name = 'Sub-headline';");
$sub_head_result = mysql_query($sub_head_query);
$sub_head_row = mysql_fetch_assoc($sub_head_result);
$content_query = ("SELECT adm_name, ".$content." as content FROM adm_sect WHERE adm_name = 'content';");
$content_result = mysql_query($content_query);
$content_row = mysql_fetch_assoc($content_result);
$section_name = $title_row['content'];
$section_sub_head = $sub_head_row['content'];
$section_content = $content_row['content'];
echo '<div class="section-title">
<h2>'.$section_name.'</h2>
<h3>'.$section_sub_head.'</h3>
</div>
<div class="row">
<div class="column column-1-2">'.$section_content.'</div><!-- .column-1-2 -->
<div class="column column-1-2">
<div class="contact-info">
<h4>Main Campus Address</h4>
<p>
Oral Roberts University<br />
Office of Admissions<br />
<span class="locality">
7777 South Lewis Avenue<br />
Tulsa, Oklahoma 74171<br />
United States of America
</span>
</p>
<h4>Call or Email Undergraduate Admissions</h4>
<p>
<span class="tel">+1 800.678.8876<br /></span>
<span class="tel">+1 918.495.6518<br /></span>
<span class="email">E: <a href="mailto:admissions@oru.edu">admissions@oru.edu</a></span>
</p>
<h4>Call or Email ORU's Coordinator of Chinese Intiatives</h4>
<p>
<span class="tel">+1 918.495.6540<br /></span>
<span class="email">E: <a href="mailto:yfang@oru.edu">yfang@oru.edu</a></span>
</p>
</div><!-- .contact-info -->
</div><!-- .column-1-2 -->
</div><!-- .row -->
<div class="row">
<div class="column column-1-2 centered">
<h3><a class="button arrow-button" href="#">Request More Information</a></h3>
</div><!-- .column-1-2 -->
<div class="column column-1-2 centered">
<h3><a class="button arrow-button" href="#">APPLY TO ORU TODAY</a></h3>
</div><!-- .column-1-2 -->
</div><!-- .row -->';
}
The table being referenced is set up as follows:
| ID | adm_name | content | es_content |
-------------------------------------------------
| 1 | title | content | translated |
| 2 | content | content | translated |
| 3 | address_info | content | translated |
| 4 | RFI Button Text | content | translated |
| 5 | RFI Link | content | translated |
| 6 | Apply Button Text | content | translated |
| 7 | Apply Link | content | translated |
| 8 | Sub-headline | content | translated |
The $lang
through top IF statements determine the page language and select the DB content column based on the language. So that if $lang == 'es'
then the $content
table header would be es_content
My question(s) are as follows:
1) How can I separate, if possible, the $lang
parameter call at the beginning of the function so that I can duplicate this function for "adm_sect", "finaid_sect" and "onl_learning_sect"
2) Can I simplify this down to 1 query since the only difference is the "adm_name" variable?
3) How can I generate the individual column values so that I can put them all in one export value? Or is this possible since they are based on individual sql queries?
The end goal is to have one query that generates the values for each translated portion from the DB. Is this possible and if so recommendations on how to accomplish this?