مشکل در دستور if در کد php
با عرض سلام و خسته نباشید.
دوستان من به یک مشکل در کد php خوردم. ممنون میشم که راهنمایام کنید.
کار این کد خواندن یک جد.ل از database و چاپ آن برای کاربر است.
قسمتی از این کد به شرح زیر است:
کد:
<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>
حال من میخواهم این کد به دو زبان چاپ شود.
تمام کارهاش رو انجام دادم. نظیر اضافه کردن ستون در database به زبان انگلیسی معادل ستونهای مورد نظر و...
در ابتدای کد هام این دستور رو برای تشخصی زبان page اضافه کردم:
کد:
<?php
// Detect Language from url
$url = $_SERVER['REQUEST_URI']; // gives "/en/test.php"
$urlParts = explode ('/', $url);
$language = $urlParts[1]; // first element before / (slash)
?>
و برای اینکه کد جدول اولی رو طبق زبان چاپ کنه، دستور if را مطابق با زیر به آن اضافه کردم:
کد:
<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>
مشکلی که دارم این است که بعد از اضافه کردن این دستور if، صفحه دچار مشکل میشود و load نمیشود.
ارور 500 هم میدهد.
مشکل از همین دستور if هست. بقیه موارد رو چک کردم درست بود. حتی کد اول رو متغیرهایی رو که چاپ میکنه و به پارامترهای اینگلیسی تغییر دادم و صفحه به راحتی و بدون هیچ مشکلی لود شد.
منتهی با اضافه کردن این دستور if، دچار مشکل میشود.
ممنون میشوم که راهنماییام کنید.
با تشکر