i'm still new in yii2.
so, make a simple project which use MVC in yii2 where the project is to output examination result.
what bugging me is, how to redirect to main page as no data found in database?
another one, i get Undefined offset: 0 which i googled say mismatch array and data not NULL.
anyhow, here are those code :
controller : StudentController.php
public function actionCall()
{
$result = $_POST['semester'];
$result_explode = explode('|', $result);
$sem = $result_explode[0];
$tahun = $result_explode[0]." ".$result_explode[1];
$send = array(
'id' => $_POST['id'],
'semester' => $sem ,
'tahun' => $tahun);
$model = new Student();
if(!$data['result']= $model->getDetails($send))
{
return $this->render('detail', $data);
}
else
{
return $this->render('detail');
}
}
public function actionSearch()
{
return $this->render('searchstudent2');
}
model : Student.php
public function getDetails($send)
{
$student = student::find()
->select('s.student_name,al.level_matric_no,al.level_semester,al.level_id,s.student_mykad, s.student_address,s.student_postcode,
s.student_state,ss.subject_code,ss.subject_name,ss.subject_credit_hour,c.course_name,st.taken_session,
g.Grade_symbol,g.Grade_value,sr.semester_gpa,sr.semester_cgpa,sr.total_point,
sr.total_credit, sr.semester_count')
->from('student AS s')
->leftJoin('a_level AS al', '`s`.`student_id` = `al`.`student_id`')
->leftJoin('subject_taken AS st', '`al`.`level_id` = `st`.`level_id`')
->leftJoin('semester_result AS sr', '`al`.`level_id` = `sr`.`level_id`')
->leftJoin('grade AS g', '`g`.`grade_id` = `st`.`grade_id`')
->leftJoin('course AS c', '`al`.`level_course_offered` = `c`.`course_id`')
->leftJoin('subject AS ss', '`ss`.`subject_id` = `st`.`subject_id`')
->where(['al.level_id'=>$send['id']])
->andWhere(['sr.semester_count'=>$send['semester']])
->andWhere(['st.taken_session'=>$send['tahun']])
->asArray()
->all();
return $student;
}
view : searchstudent2.php
<div class="container">
<div class="row">
<h2>Stylish Search Box</h2>
<div id="custom-search-input">
<?php $form = ActiveForm::begin(['action' => Url::to(['student/call']),'options' => ['method' => 'post']]) ?>
<div class="input-group col-md-12">
<select name="semester">
<option value="1|2012/2013">sem1</option>
<option value="2|2013/2014">sem2</option>
<option value="3|2014/2015">sem3</option>
<option value="4|2015/2016">sem4</option>
</select>
<br><br>
<input type="text" name="id" class="search-query form-control" placeholder="Search" />
<span class="input-group-btn">
<button class="btn btn-danger" type="submit">
<span class=" glyphicon glyphicon-search"></span>
</button>
</span>
</div>
<?php ActiveForm::end() ?>
</div>
</div>
detail.php
table 1 in detail.php
<table style="width:100%">
<tr>
<th class="tg-yw4l">Nama</th>
<th class="tg-baqh" colspan="7"><?php echo $result[0]['student_name']; ?></th>
</tr>
<tr>
<td class="tg-yw4l">Alamat</td>
<td class="tg-baqh"><?php echo $result[0]['student_address']; echo " ". $result[0]['student_postcode']; echo " ".$result[0]['student_state'];?></td>
<td class="tg-yw4l" rowspan="4"></td>
<td class="tg-yw4l">Kemasukan</td>
<td class="tg-baqh"></td>
<td class="tg-yw4l" rowspan="4"></td>
<td class="tg-yw4l" colspan="2"></td>
</tr>
<tr>
<td class="tg-yw4l">No. KP</td>
<td class="tg-baqh"><?php echo $result[0]['student_mykad']; ?></td>
<td class="tg-yw4l">Sesi</td>
<td class="tg-baqh"><?php echo $result[0]['taken_session']; ?></td>
<td class="tg-yw4l">Tahun Akademik</td>
<td class="tg-yw4l"><?php echo $result[0]['taken_session']; ?></td>
</tr>
<tr>
<td class="tg-yw4l">No. Matrik</td>
<td class="tg-baqh"><?php echo $result[0]['level_matric_no']; ?></td>
<td class="tg-yw4l">Fakulti</td>
<td class="tg-baqh"></td>
<td class="tg-yw4l" colspan="2" rowspan="2"></td>
</tr>
<tr>
<td class="tg-yw4l">Program</td>
<td class="tg-baqh"><?php echo $result[0]['course_name']; ?></td>
<td class="tg-yw4l">Semester</td>
<td class="tg-baqh"></td>
</tr>
<tr>
<td class="tg-yw4l">Pinjaman</td>
<td class="tg-baqh" colspan="7"></td>
</tr>
table 2 in detail.php
<tr>
<th class="tg-031e">BIL</th>
<th class="tg-031e">KOD</th>
<th class="tg-031e">SUBJEK</th>
<th class="tg-yw4l">KREDIT</th>
<th class="tg-yw4l">GRED</th>
<th class="tg-yw4l">MATA</th>
<!-- <th class="tg-yw4l">GPA/CGPA</th> -->
</tr>
<?php
$bil=0;
foreach ($result as $details) {
$bil++;
?>
<tr>
<td class="tg-031e"><?=$bil?></td>
<td class="tg-031e"><?php echo $details['subject_code']; ?></td>
<td class="tg-031e"><?php echo $details['subject_name']; ?></td>
<td class="tg-yw4l"><?php echo $details['subject_credit_hour']; ?></td>
<td class="tg-yw4l"><?php echo $details['Grade_symbol']; ?></td>
<td class="tg-yw4l"><?php echo $details['Grade_value']; ?></td>
</tr>
<?php } ?>
<tr>
<td class="tg-031e" colspan="2"></td>
<td class="tg-031e">TOTAL KREDIT</td>
<td class="tg-yw4l"><?php echo $details['total_point']; ?></td>
<td class="tg-yw4l">JUMLAH JAM KREDIT</td>
<td class="tg-yw4l" colspan="3"><?php echo $details['total_credit']; ?></td>
</tr>
Try the following steps one by one
check $_POST['semester'] and make sure it is not empty
check $model->getDetails($send) returns any result or not.
Note: find()-> ...asArray()->all() returns an empty array if no result found. so check for empty result before for render view.
if( !empty($data=$model->getDetails($send)) )
{
return $this->render('detail', ['viewData'=>$data]);
}
else
{
return $this->render('_another_view');
// or redirect to some page or do whatever
}
Note: if you send empty $data array to the view and if you use $data[0]['anything']
you will get Undefined offset: 0 error.
so if result is empty then render another view. in your case you are rendering same view 'detail' one with $data another without $data.
So there is a high chance to get Undefined offset: 0 error.
Thanks
If getDetails functions doesn't return data, redirect to main page:
if ( ($data = $model->getDetails($send)) != null ) {
return $this->render('detail', ['result' => $data]);
} else {
// redirect no data
return $this->redirect(['site/index']);
}
Related
Im trying to teach myself php.... I have created a database with 4 elements... region, details, store_name, web_address.
I have created ado-while loop that displays all the records in a 'region'... it displays 'store_name', then 'web_address', then 'details' sorted so all the records with the same 'details' are grouped together;
<table width="600" align="center" border="0" cellspacing="4" >
<tr>
<td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
<td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
</tr>
<?php do { ?>
<tr>
<td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
<td colspan="2" rowspan="2" align="center"> <?php echo '' . $row_RegionList['web_address'] . ''; ?></td>
</tr>
<tr>
<td width="14">
<td width="313"><?php echo $row_RegionList['details']; ?> </tr>
<?php } while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>
I now want to make it so every record with the same 'details' value get listed under a 'details' sub heading.
This is my attempt;
<table width="600" align="center" border="0" cellspacing="4" >
<tr>
<td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
<td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
</tr>
<?php $details = $row_RegionList['details'];
do { ?>
<tr>
<td width="313"> <h3><?php echo $row_RegionList['details']; ?> </h3></td>
</tr>
<?php do { ?>
<tr>
<td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
<td colspan="2" rowspan="2" align="center"> <?php echo '' . $row_RegionList['web_address'] . ''; ?></td>
</tr>
<?php } while ($row_RegionList['details'] == $details);
$details = $row_RegionList['details'];
} while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>
This makes a heading of 'region' with a sub heading of 'details' but then creates an eternal loop of the first record in the database. can someone show me what I have done wrong?
I am having a nested table with a while loop, I want to add one more nested table in the same row:
Now I want to add one more nested table as each cd contains more than one data like below:
My code is as follows
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td><?php echo $rowcd['well_no'] ?></td>
<td><?php echo $rowcd['well_name'] ?></td>
<td>
<table border="1" width="100%">
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
/* I want to add one more nested table here*/
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
I tried some thing like this,after my second while loop
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
<td>
<table>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<tr>
<td><?php echo $rowl['logs'] ?></td>
</tr>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
but the result was messed up. I am confused, where I want to end my while loop, I think.
Finally i got as i wish, and i am sharing the code as below
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div class="container">
<table border="1" align="center" border-collapse="collapse">
<thead>
<tr >
<th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th width="100">CD No:</th>
<th width="150">Logs</th>
<th width="100">Bottom Depth</th>
<th width="100">Top Depth</th>
<th width="100">Date of Log</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td align="center"><?php echo $rowcd['well_no'] ?></td>
<td align="center"><?php echo $rowcd['well_name'] ?></td>
<td colspan="5">
<table rules="all">
<tr>
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<td width="100" align="center"><?php echo $rowcd['cd_no'] ?></td>
<td colspan="4">
<table rules="all">
<tr>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<td width="155"><?php echo $rowl['logs'] ?></td>
<td width="105" align="center"><?php echo $rowl['bottom'] ?></td>
<td width="100" align="center"><?php echo $rowl['top'] ?></td>
<td width="100" align="right"><?php echo $rowl['date'] ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
?>
</table>
</td>
<?php
}
}
?>
</tr>
</table>
I hope this is what you meant as per your data table shown above
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<tr>
<td>id</td>
<td>well</td>
<td>name</td>
<td>
<table border="1" width="100%">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</td>
<td>
<table border="1" width="100%">
<tr>
<td>Log1</td>
</tr>
<tr>
<td>Log2</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
How to split my page into 4 sections with data from database?
I'm displaying data from the database and they appear one by one on the table. And I want to split them into 4 parts and each of them will show another result from the database. In addition, I would like to make line in the middle, which will keep them separated.
That's my code, to show results from DB:
EDIT: Ok, I edited like u said, and now page is splitted on 2 section, but I got on them the same results. How to change this, that on the left side will be shown one record, and on the right side another.
$result = $wpdb->get_results("SELECT company_wojewodztwo, company_powiat, company_miasto, company_name, telefon, company_nip, company_opis FROM test WHERE company_wojewodztwo = '$woj' AND company_powiat = '$pow' AND company_miasto = '$nazwa' ORDER BY RAND()");
foreach ( $result as $k => $v ) {
$c_name = stripslashes($v->company_name);
$c_opis = stripslashes($v->company_opis);
$c_mob_nr = stripslashes($v->telefon);
$c_nip = stripslashes($v->company_nip);
?>
<table>
<tbody>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo $c_name; ?></td>
<td style="width: 50%;"><?php echo $c_name; ?></td>
</tr>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo $c_nip ?></td>
<td style="width: 50%;"><?php echo $c_nip ?></td>
</tr>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo $c_mob_nr ?></td>
<td style="width: 50%;"><?php echo $c_mob_nr ?></td>
</tr>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo $c_opis ?></td>
<td style="width: 50%;"><?php echo $c_opis ?></td>
</tr>
</tbody>
</table>
<?php if(count($result) != $k+1){ ?>
<p>___________________________________________________</p>
<?php } ?>
<?php
}
?>
do something like this:
<table>
<tbody>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo 'data 1'; ?></td>
<td style="width: 50%;"><?php echo 'data 2'; ?></td>
</tr>
<tr style="height: 50%;">
<td style="width: 50%;"><?php echo 'data 1'; ?></td>
<td style="width: 50%;"><?php echo 'data 2'; ?></td>
</tr>
</tbody>
</table>
I put styles inline, You try to put them in a css file.
Update your code...
<?php
global $wpdb;
$result = $wpdb->get_results("SELECT company_province, company_district, company_city, company_name, telefon, company_nip, company_opis FROM test WHERE company_province = '$woj' AND company_district = '$pow' AND company_city = '$nazwa' ORDER BY RAND()");
foreach ( $result as $k => $v ) {
$c_name = stripslashes($v['company_name']);
$c_opis = stripslashes($v['company_opis']);
$c_mob_nr = stripslashes($v['telefon']);
$c_nip = stripslashes($v['company_nip']);
?>
<div class="parent">
<table>
<tr><th><p><b> Name: </b></th><td>
<?php echo $c_name;?></p></td></tr>
<tr><th><p><b> NIP: </b></th><td>
<?php echo $c_nip;?></p></td></tr>
<tr><th><b> Number tel: </b></th><td>
<?php echo '+48 '.$c_mob_nr;?><br></td></tr>
<tr><th><b> Opis Firmy: </b></th><td>
<span class="more"> <?php echo $c_opis;?></span></td></tr>
</table>
<?php if(count($result) != $k+1){ ?>
<p>___________________________________________________</p>
<?php } ?>
</div>
<?php
}
?>
I am trying to design the table but it seems coming into proper way but for some cases. In this table, that $cal_amount and $cal_amount_key part shouldbe print whole for any numbers of cars.
Code:
PHP
<?php
$TotV=array("car","bus","jeep");
$Nopkg=array(759,159,459);
$Avg=array(20,50,15);
$Qty=array(15000,58000,58922);
$rate=array(31.73,17.15,17.25);
$gro_tot=789456;
$Cex=781254;
$S_Tot=159254;
$Vat=12500;
$frieght=0;
$G_Tot=985251;
?>
CSS
table,td,th,tr {
border:1px solid black;
border-collapse: collapse;
text-align:left;
}
HTML
<table>
<tr>
<th>S.No</th><th align="center">Variety of Goods</th><th style="width:70px">No.and Description of<br/>Packages</th><th style="width:70px">Avg. Contents per Package<br/>(Pcs)</th><th style="width:70px">Total Quantity<br/>(Pcs)</th><th style="width:70px">Rate per pc.</th><th colspan="2" style="text-align:center;">Amount<br/>(Rs.)</th>
</tr>
<?php
for($i=0;$i<count($TotV);$i++)
{?>
<tr>
<td><?php echo $i+1;?></td>
<td><?php echo strtoupper($TotV[$i]);?></td>
<td><?php echo $Nopkg[$i];?></td>
<td><?php echo $Avg[$i];?></td>
<td><?php echo $Qty[$i];?></td>
<td><?php echo $rate[$i];?></td>
<?php
}?>
<td colspan="1">Total Value</td><td style="width:100px;text-align:right;"> <?php echo $gro_tot;?></td>
<tr><td></td><td></td>
<td></td><td></td><td></td><td></td><td style="width:150px;">C.Ex.Duty 12.5%</td><td style="width:150px;text-align:right;"> <?php echo $Cex;?></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td></td><td style="width:150px;">SubTotal</td><td id="num" style="width:150px;text-align:right;"> <?php echo $S_Tot;?></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td style="width:150px;">VAT/CST 2%</td><td style="width:150px;text-align:right;"> <?php echo $Vat;?></td></tr>
<tr><td style="border:none;" colspan="3"><b>qwert</b></td><td style="border:none;"></td><td style="border:none;" colspan="2"><td><b>Freight</b></td><td style="width:150px;text-align:right;"> <STRONG><?php echo $frieght;?></STRONG></td></tr>
<tr><td style="border:none;" colspan="3"><b>asdf</b></td><td style="border:none;"></td><td style="border:none;" colspan="2"><td><b>Grand Total</b></td><td style="width:150px;text-align:right;"> <STRONG><?php echo $G_Tot;?></STRONG></td></tr>
</tr>
</table>
Please suggest some changes to be done in code so that It will start from first row instead of third row. Thanks in advance.
Try this:
First make PHP array for total calculation and label.
$TotV=array("car","bus","jeep");
$Nopkg=array(759,159,459);
$Avg=array(20,50,15);
$Qty=array(15000,58000,58922);
$rate=array(31.73,17.15,17.25);
$gro_tot=789456;
$Cex=781254;
$S_Tot=159254;
$Vat=12500;
$frieght=0;
$G_Tot=985251;
$cal_amount_key = array('Total Value',
'C.Ex.Duty 12.5%',
'SubTotal',
'VAT/CST 2%',
'Freight',
'Grand Total');
$cal_amount = array($gro_tot,
$Cex,
$S_Tot,
$Vat,
$frieght,
$G_Tot);
Put the code inside loop:
<table>
<tr>
<th>S.No</th>
<th align="center">Variety of Goods</th>
<th style="width:70px">No.and Description of<br/>Packages</th>
<th style="width:70px">Avg. Contents per Package<br/>(Pcs)</th>
<th style="width:70px">Total Quantity<br/>(Pcs)</th>
<th style="width:70px">Rate per pc.</th>
<th colspan="2" style="text-align:center;">Amount<br/>(Rs.)</th>
</tr>
<?php
for($i=0;$i<count($TotV);$i++) {?>
<tr>
<td><?php echo $i+1;?></td>
<td><?php echo strtoupper($TotV[$i]);?></td>
<td><?php echo $Nopkg[$i];?></td>
<td><?php echo $Avg[$i];?></td>
<td><?php echo $Qty[$i];?></td>
<td><?php echo $rate[$i];?></td>
<td><?php echo $cal_amount_key[$i];?></td>
<td style="width:100px;text-align:right;"><?php echo $cal_amount[$i];?></td>
</tr>
<?php } ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td style="width:150px;">VAT/CST 2%</td>
<td style="width:150px;text-align:right;"> <?php echo $Vat;?></td>
</tr>
<tr>
<td style="border:none;" colspan="3"><b>qwert</b></td>
<td style="border:none;"></td>
<td style="border:none;" colspan="2">
<td><b>Freight</b></td>
<td style="width:150px;text-align:right;"> <STRONG><?php echo $frieght;?></STRONG></td>
</tr>
<tr>
<td style="border:none;" colspan="3"><b>asdf</b></td>
<td style="border:none;"></td>
<td style="border:none;" colspan="2">
<td><b>Grand Total</b></td>
<td style="width:150px;text-align:right;"> <STRONG><?php echo $G_Tot;?></STRONG></td>
</tr>
</table>
I have a problem i want to put the $message inside the table that is a equivalent as a "Search not found".
Here is my picture outside the table $message = Search not found
View:
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<?php if ( isset($message) ){
echo $message;
} else{ foreach($results as $row){
?>
<tbody>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
Option
</td>
</tr>
</tbody>
<?php }} ?>
</tbody>
</table>
</div>
You are using wrong end tags.
This will print Search not found inside the table with colspan 5 and center aligned
Note: Most of time we check where foreach value is empty ($results). But in your case you are checking some thing else ($message).
Changes
<tr> <!-- Changed -->
<td colspan="5" align="center"><?php echo $message; ?> </td>
</tr>
if ( isset($message) ){ is changed to if (!empty($message)){
Final code
<div class="z table-responsive" >
<table class=" table table-hover" >
<thead >
<tr >
<th>ID Number</th>
<th>First name</th>
<th>Middle name</th>
<th>Last name</th>
<th>Sex</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($message)) # improved
{
?>
<tr> # Changed
<td colspan="5" align="center"><?php echo $message; ?> </td>
</tr>
<?php
}
else
{
foreach($results as $row)
{
?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
<a href="<?php echo site_url('viewstudentinalpha/viewspecific/'.$row->Id) ?>" class="btn btn-info " style="font-size: 18px;" type="submit" name="submit" role="button">
Option
</a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
Edit 01
In Controller
function search_keyword()
{
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$keyword = $this->input->post('keyword');
$data['results'] = $this->model_adminlogin->search($keyword);
$this->load->view('result_view',$data);
}
In View
Alter your if like this.
Copy all codes i have added in above for your view. and only change this few lines.
<?php
if (!empty($results)) # Change
{
?>
<tr> # Change
<td colspan="5" align="center"> Search not found </td> # Change
</tr>
<?php
}
else
{
This isn't an issue with CodeIgniter so much as your code. What you are trying to do with the code is to put the message between the <thead> and <tbody>, and not in any table tags.
This is the same as trying to put it between rows in a table, and therefore gets interpreted as not being part of the table, and drawn outside of the table as a result.
If you put the message into the <tbody>, it will go in the right place, so you can do:
<?php if ( isset($message) ){
echo "<tbody><tr><td colspan='5'>" . $message . "</td></tr></tbody>";
}....
try this
<tbody>
<?php
if ( isset($result )
// or if (!isset($message)) //depend on your code
{
foreach($results as $row){
?>
<tr>
<td><?php echo $row-> Idnumber ?></td>
<td class="text-capitalize "><?php echo $row -> Firstname ?></td>
<td class="text-capitalize"><?php echo $row->Middlename ?></td>
<td class="text-capitalize"><?php echo $row-> Lastname ?></td>
<td class="text-capitalize"><?php echo $row-> Sex?></td>
<td>
Option
</td>
</tr>
<?php }}
else
//or elseif(isset($message)) //depend on your code
{
echo $message; ?>
}
</tbody>
</table>
</div>