Click here to Skip to main content
15,064,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day! I need help, I tried creating search for my datas but I don't how I will convert the code I made using php native into codeigniter way.

Check my code:


	$valueToSearch = $_POST['valueToSearch'];
	$query = "SELECT * FROM user where CONCAT(user_id, user_name, fname, lname) like '%".$valueToSearch."%'";
	$search_result = filterTable($query);

function filterTable($query)
	$connect = mysqli_connect("localhost", "root", "dbjireh", "exercise");
	$filter_Result = mysqli_query($connect, $query);
	return $filter_Result;



<!DOCTYPE html>
	<title>test search
		border: 1px solid black;

						<?php while ($row = mysqli_fetch_array($search_result)):?>
						<?php endwhile;?>
		<table><tbody><tr>				<th>Username</th>				<th>Firstname</th>				<th>Lastname</th>			</tr><tr><td><?php echo $row['user_name'];?></td>			<td><?php echo $row['fname'];?></td>			<td><?php echo $row['lname'];?></td>			</tr></tbody></table>

What I have tried:

And I tried to convert it into codeigniter here's my code :

<!DOCTYPE html>
	<title>test search
		border: 1px solid black;
          <!--get datas into database and display it on this page-->
    <?php foreach ($datas as $data) : ?>
            <!--edit and delete button-->
            <?php endforeach;?> 
      <table><thead><tr><th>Username</th>            <th>First Name</th><th>Last Name</th></tr></thead><tbody><tr>    <td><?php echo $data->user_name;?></td>    <td><?php echo $data->fname;?></td>    <td><?php echo $data->lname;?></td><td><a href="<?php echo $data->user_id;?>" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-pencil"></span> Edit </a></td>        <td><a href="<?php echo $data->user_id;?>" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-remove"></span> Delete </a></td>    </tr></tbody></table>
Updated 25-Apr-18 23:43pm
Peter_in_2780 25-Apr-18 22:36pm
You already asked this in the Web Dev forum. Cross-posting is considered rude.

1 solution

You have to put the table tag and the table header line before the loop, put the output of the cells into the loop, and let the closing tbody and table tags after the loop.

I provided a similar answer yesterday at Database data not display plz solve this[^]:
<th>Username</th><th>First Name</th><th>Last Name</th>
<?php foreach ( $datas as $data ):?>
    <td><?php echo $data->user_name;?></td>
    <td><?php echo $data->fname;?></td>
    <td><?php echo $data->lname;?></td>
    <!-- ... -->
<?php endforeach;?>
You have more data columns than header columns. So you should add also the missing header columns (e.g. as empty cells).

I have also not added the cells with the links because I guess that $data->user_id does not contain valid links but must be passed as parameters to an existing page.

See also Views — CodeIgniter 3.1.8 documentation[^] .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900