I have a problem after add an if statement to my PHP code. This code uses database to print data for user.
<table style='width:100%;' class='table table-striped table-hover' id="myTable">
<thead>
<tr>
<th data-field="prenom" data-filter-control="input" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_PHOTO');?></th>
<th data-field="date" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_LAST_NAME');?></th>
<th data-field="examen" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_FIRST_NAME');?></th>
<th data-field="examen" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_MAJOR');?></th>
<th data-field="examen" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_EMAIL');?></th>
<?php
// Check if user is authorized to remove content
$user = JFactory::getUser();
if ($user->authorise('core.edit', 'com_content'))
{ ?>
<th data-field="examen" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_REMOVE');?></th>
<?php
}
?>
</tr>
</thead>
<?php
// Print the content of the table with all Users
for ($i = 0; $i < $table_length; $i++) {
?>
<tr onclick="DoNav('index.php?option=com_helloworld&view=helloworld&id=<?php echo $this->id;?>&user_id=<?php echo$results[$i]->id;?>');">
<td> <img src="<?php echo $results[$i]->picture_path; ?>" class="img-rounded" alt="<?php echo JText::_('COM_HELLOWORLD_NO_PHOTO');?>" style="width:60px;height:60px;"</td>
<td><a href="index.php?option=com_helloworld&view=helloworld&id=<?php echo (int) $this->id;?>&user_id=<?php echo$results[$i]->id;?>"><?php echo $results[$i]->last_name;?></a></td>
<td><?php echo $results[$i]->first_name;?></td>
<td><?php echo $results[$i]->major;?></td>
<td><?php echo $results[$i]->mail;?></td>
<?php
// Check if user is authorized to remove content
if ($user->authorise('core.edit', 'com_content'))
{ ?>
<td><a href="index.php?option=com_helloworld&view=helloworld&q=del_prof&id=<?php echo $this->id; ?>&delete_id=<?php echo $results[$i]->id; ?>"><?php echo JText::_('COM_HELLOWORLD_REMOVE');?></a></td>
<?php
} ?>
</tr>
<?php
}
?>
</table>
I want to print data in two different languages. I've added all of required data in other language in database.
I've added this code at the beginning to detect page's language from the url:
<?php
// Detect Language from url
$url = $_SERVER['REQUEST_URI']; // gives "/en/test.php"
$urlParts = explode ('/', $url);
$language = $urlParts[1]; // first element before / (slash)
?>
I've added if statement to the code above to print data in other language. The code is:
<table style='width:100%;' class='table table-striped table-hover' id="myTable">
<thead>
<tr>
<th data-field="prenom" data-filter-control="input" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_PHOTO');?></th>
<th data-field="date" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_LAST_NAME');?></th>
<th data-field="examen" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_FIRST_NAME');?></th>
<th data-field="examen" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_MAJOR');?></th>
<th data-field="examen" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_EMAIL');?></th>
<?php
// Check if user is authorized to remove content
$user = JFactory::getUser();
if ($user->authorise('core.edit', 'com_content'))
{ ?>
<th data-field="examen" data-filter-control="select" data-sortable="true"><?php echo JText::_('COM_HELLOWORLD_REMOVE');?></th>
<?php
}
?>
</tr>
</thead>
<?php
// Print the content of the table with all User
for ($i = 0; $i < $table_length; $i++) {
?>
<?php
if (strcmp($language,"fa")==0) //if the language is farsi
{?>
<tr onclick="DoNav('index.php?option=com_helloworld&view=helloworld&id=<?php echo $this->id;?>&user_id=<?php echo$results[$i]->id;?>');">
<td> <img src="<?php echo $results[$i]->picture_path; ?>" class="img-rounded" alt="<?php echo JText::_('COM_HELLOWORLD_NO_PHOTO');?>" style="width:60px;height:60px;"</td>
<td><a href="index.php?option=com_helloworld&view=helloworld&id=<?php echo (int) $this->id;?>&user_id=<?php echo$results[$i]->id;?>"><?php echo $results[$i]->last_name;?></a></td>
<td><?php echo $results[$i]->first_name;?></td>
<td><?php echo $results[$i]->major;?></td>
<td><?php echo $results[$i]->mail;?></td>
<?php
// Check if user is authorized to remove content
if ($user->authorise('core.edit', 'com_content'))
{ ?>
<td><a href="index.php?option=com_helloworld&view=helloworld&q=del_prof&id=<?php echo $this->id; ?>&delete_id=<?php echo $results[$i]->id; ?>"><?php echo JText::_('COM_HELLOWORLD_REMOVE');?></a></td>
<?php
} ?>
</tr>
<?php}?>
<?php
else{ //if the language is other where here is english
?>
<tr onclick="DoNav('index.php?option=com_helloworld&view=helloworld&id=<?php echo $this->id;?>&user_id=<?php echo$results[$i]->id;?>');">
<td> <img src="<?php echo $results[$i]->picture_path; ?>" class="img-rounded" alt="<?php echo JText::_('COM_HELLOWORLD_NO_PHOTO');?>" style="width:60px;height:60px;"</td>
<td><a href="index.php?option=com_helloworld&view=helloworld&id=<?php echo (int) $this->id;?>&user_id=<?php echo$results[$i]->id;?>"><?php echo $results[$i]->eng_last_name;?></a></td>
<td><?php echo $results[$i]->eng_first_name;?></td>
<td><?php echo $results[$i]->eng_major;?></td>
<td><?php echo $results[$i]->mail;?></td>
<?php
// Check if user is authorized to remove content
if ($user->authorise('core.edit', 'com_content'))
{ ?>
<td><a href="index.php?option=com_helloworld&view=helloworld&q=del_prof&id=<?php echo $this->id; ?>&delete_id=<?php echo $results[$i]->id; ?>"><?php echo JText::_('COM_HELLOWORLD_REMOVE');?></a></td>
<?php
} ?>
</tr>
<?php
}
?>
<?php
}
?>
</table>
After doing this, the page can not load. I see Error 500 on my explorer with this message: "This page isn’t working"
I sure the problem is because of If statement. Because i changed the first code (without if) to print data in other language which have different variable and it worked.
what should i do?
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire