My model code
function wife($a){
$sql="select person.person_id,person.new_surname,person.fname,person.father_name,person.village,marriage.wife_id from person left join marriage on person.person_id=marriage.wife_id where marriage.husband_id='$a'";
$query=$this->db->query($sql);
return $query->result();
}
My view code
<?php
foreach($result as $row){
echo "first".$row->fname;
echo $row->father_name
echo $row->new_surname;
echo $row->village;
?>
for first row i want to display above and for second row i want to display following
<?php
foreach($result as $row){
echo "Second".$row->fname;
echo $row->father_name
echo $row->new_surname;
echo $row->village;
?>
<?php
$i = 0;
foreach($result as $row){
if ($i == 0) {
echo "first" . $row->fname;
} else if ($i == 1) {
echo "Second" . $row->fname;
} else {
// Do this for third etc. rows
}
echo $row->father_name
echo $row->new_surname;
echo $row->village;
$i++;
}
?>
您可以使用变量i并使用任何无需硬编码字符串即可使用的函数将数字转换为字符串,并且适用于n个数字
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.