i have a function to show data from controller like this :
public function leaderboards()
{
if($this->ion_auth->logged_in()){
$leaderboard = $this->FrontModel->getLeaderboard();
$dataLeaderboard = ''; $no = 1;
foreach ($leaderboard as $row) {
$dataLeaderboard .='
<tr class="calculate-price-wrapper post">
<td>
<div class="mv-font-secondary mv-f-14"><strong>'.$no.'.</strong></div>
</td>
<td>
<div class="mv-font-secondary mv-f-14"><strong>'.$row['fname'].'</strong></div>
</td>
<td >
<div class="mv-font-secondary mv-f-14"><strong>'.$this->replace_character($row['email']).'</strong></div>
</td>
<td>
<div class="mv-font-secondary mv-f-14"><strong>'.$row['total_point'].'</strong></div>
</td>
</tr>
';
$no++;
}
/* pagination */
$config = array();
$config["base_url"] = base_url(). "leaderboards";
$config["total_rows"] = count($dataLeaderboard);
$config["per_page"] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['dataLeaderboard'] = $dataLeaderboard($config["per_page"], $page);
$data['pagination'] = $this->pagination->create_links();
/* data template - header footer */
$template['menuActive'] = 'leaderboard';
$template['menuLoggedIn'] = $this->menuLoggedIn;
$this->load->view('front-end/template/header', $template);
$this->load->view('front-end/leaderboard', $data);
$this->load->view('front-end/template/footer', $template);
}else{
redirect('auth', 'refresh');
}
}
And here is the my view :
<!-- .main-breadcrumb-->
<section class="mv-main-body cart-main mv-bg-gray mv-wrap">
<div class="container">
<div class="latest-blog-title mv-title-style-3 no-text-behind" style="padding-bottom:30px;">
<div class="title-3-text"><span class="main">LEADERBOARD</span></div>
<div class="title-3-line"></div>
</div>
<div class="cart-inner">
<div class="cart-block block-cart-table mv-bg-white mv-box-shadow-gray-1 mv-mb-50">
<div class="mv-table-responsive">
<table class="mv-table-style-2">
<thead>
<tr>
<th style="width:15%;">Pos.</th>
<th style="width:30%;">Name</th>
<th style="width:30%;">Email</th>
<th style="width:20%;">Point</th>
</tr>
</thead>
<tbody>
<?=$dataLeaderboard?>
</tbody>
</table>
<div class="mv-pagination-wrapper mv-mt-25 mv-mb-25">
<div class="mv-pagination-style-1 has-count-post">
<?php echo $pagination; ?>
</div>
<!-- .mv-pagination-style-1-->
</div>
</div>
</div>
</div>
</div>
</section>
but it ended up having an error like this :
Fatal error: Call to undefined function <tr class="calculate-price-wrapper post"> <td> <div class="mv-font-secondary mv-f-14"><strong>1.</strong></div> </td> <td> <div class="mv-font-secondary mv-f-14"><strong>Test Name</strong></div> </td> <td > <div class="mv-font-secondary mv-f-14"><strong>te*s*n*ame*g*ai*.c*m</strong></div> </td> <td> <div class="mv-font-secondary mv-f-14"><strong>55</strong></div> </td> </tr> <tr class="calculate-price-wrapper post"> <td> <div class="mv-font-secondary mv-f-14"><strong>2.</strong></div> </td> in C:\xampp5.6\htdocs\motogp2022\application\controllers\front-end\MainController.php on line 703
A PHP Error was encountered Severity: Error
Message: Call to undefined function
Test Name
tesnamegai.c*m 55
Filename: front-end/MainController.php
Line Number: 703
Backtrace:
And the line that cause the error was this line in my controller :
$data['dataLeaderboard'] = $dataLeaderboard($config["per_page"], $page); //Line 703
anyone know solution for this? anyhelp is really appreciated, thank you!.
In this line:
$data['dataLeaderboard'] = $dataLeaderboard($config["per_page"], $page);
You are using $dataLeaderboard as a function. You are setting it as a string of HTML, hence you're getting that the HTML does not exist as a function.
Not knowing your full code, but what I think you need to do is:
Not create the leaderboard data as a single string, but rather as an array of HTML (so not $dataLeaderboard .= ... but rather $dataLeaderboard[] = ....
Then do $data['dataLeaderboard'] = $dataLeaderboard. For brevity, you can in your loop directly set it into an array $data['dataLeaderboard']. You will not set it as $dataLeaderboard(...). The round bracket around the variable means you're trying to use the variable as a function, which it is not.
For full implementation of the pagination library in CI, check this manual page: https://codeigniter.com/userguide3/libraries/pagination.html. There is a specific set configuration options and code lines that must be present, and your pagination library must be loaded, of course.
There might be more to do after that, but start there.
Related
im trying to a update a record by getting the id of the post via $_GET then update the records through $_POST.
i already have performed the delete action through $_GET it works fine also the mysqli_fetch_assoc works fine for displaying the record for editing but the actual editing does not happens it gives a Empty error from the validation in the code in the empty check function.
i have gone through lots research but cant seem to get my head around the error , i would thank full if any one could suggest any changes in the code.
Thank you in advance!
This is the error
Notice: Undefined index: id in /then the long url etc/
Below is the code
<?php
//DB Connection
include'include/db-conn.php';
if (isset($_POST['edit'])) {
//Raw GET Inputs
$raw_c_id = $_GET['id'];
//Cleaned Inputs
$c_c_id = filter_var($raw_c_id, FILTER_SANITIZE_STRING);
//Error Mwssages
$empty = '<div class="alert alert-danger alert-dismissible">
×
<strong>Error!</strong>Field is empty please provide content!
</div>
';
$success = '<div class="alert alert-success alert-dismissible fixed-top">
×
<strong>Success!</strong> Content Added Successfully
</div>
';
$not_success = '<div class="alert alert-danger alert-dismissible">
×
<strong>Not Success!</strong> Content Not Added Successfully
</div>
';
if (empty($c_c_id)) {
echo $empty;
exit();
header("Location:index.php");
}
$update = "UPDATE `continents`
SET `continent_name`='$c_c_name', `last_edited`='date(d/m/Y)'
WHERE `id`='$c_c_id'";
$run_update = mysqli_query($conn, $update);
if (!$run_update) {
header("Location: index.php");
echo $not_success;
}
else{
header("Location: index.php");
echo $success;
}
}
?>
This is the html part
<div class="panel-body">
<form action="edit.php" method="POST">
<div class="form-group">
<label for="continent_name">Continent Name</label>
<input required type="text" placeholder="10" class="form-control" value="<?php echo $c_name ; ?>" name="continent_name">
</div>
<small>Date Added: <?php echo $c_dated_added ; ?></small> / <small>Last Edited: <?php echo $c_last_edited ; ?></small>
<div class="form-group">
<input class="form-control btn-success" type="submit" name="edit" value="Submit">
</div>
</form>
</div>
Thid the while loop
<div class="table-responsive">
<table id="example" class="table table-hover ">
<thead>
<tr class="">
<th>ID</th>
<th>Continent Name</th>
<th>Date Added</th>
<th>Status</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$all_continents = "SELECT * FROM `continents` ORDER BY `status`";
$run = mysqli_query($conn,$all_continents);
while ($row_result = mysqli_fetch_assoc($run)) {
$id = $row_result['id'];
$c_continent_name = $row_result['continent_name'];
$c_date_added = $row_result['date_added'];
$c_status = $row_result['status'];
echo "
<tr>
<td>$id</td>
<td>$c_continent_name</td>
<td>$c_date_added</td>
<td>$c_status</td>
<td>
<a class='btn btn-info' href='edit.php?id=$id'>Edit</a>
</td>
<td>
<a class='btn btn-danger' href='delete.php?id=$id'>Delete</a>
</td>
</tr>
";
}
?>
</tbody>
</table>
It looks like you're trying to use GET and POST parameters at the same time. The reason it's not working is because the GET parameter is lost when you submit your form. You need to pass it on in the form's action attribute:
<form action="edit.php?id=<?php echo $_GET['id'] ?>" method="POST">
Please also take a look at the advice in this post:
Is there a way to use GET and POST together?
Hi I have written code to delete a record (Just changing the status of the record from 1 to 0). Delete is working fine.
But the problem is, after deleting the record, it's not deleting immediately after I click on refresh button. it's removing the record from the list. This is the code which I have written for that.
Controller:
function index()
{
$data['records'] = $this->career_model->get_jobs_list();
$data['mainpage']='career';
$data['mode']='all';
$this->load->view('templates/template',$data);
}
function delete()
{
$this->career_model->delete($this->uri->segment(3));
$this->flash->success('<h2>Successfully deleted the record.<h2>');
redirect('careers');
}
Model:
function get_jobs_list()
{
$this->db->Select('jobs_list.*');
$this->db->From('jobs_list');
$this->db->where(array('jobs_list.status'=>1));
$q=$this->db->get();
if($q->num_rows()>0)
{
return $q->result();
}
else
{
return false;
}
}
function delete($jobs_id)
{
$data=array('status'=>0);
$this->db->where(array('jobs_id'=>$jobs_id));
$this->db->update('jobs_list',$data);
}
View:
<div id="mydiv">
<?php echo $this->flash->display('success', TRUE);?>
</div>
<script>
setTimeout(function() {
$('#mydiv').hide('fast');
}, 10000);
</script>
<div id="main">
<div class="full_w">
<div class="h_title">
<div class="lefttitle fl">
Categories
</div>
<div class="rightbutton fr">
<a class="button add" href="<?php echo site_url()?>/careers/add">Add </a>
<a class="button del" href="<?php echo site_url()?>/careers/deactivated">Deactivated </a>
</div>
</div>
<table>
<thead>
<tr>
<th scope="col">S.No</th>
<th scope="col">Job List</th>
<th scope="col" style="width: 65px;">Modify</th>
</tr>
</thead>
<tbody>
<?php if(isset($records) && is_array($records) && count($records)>0): ?>
<?php $i=0;foreach($records as $r):$i++;?>
<tr>
<td class="align-center"><?php echo $i;?></td>
<td><?php echo $r->job_name;?></td>
<td>
</td>
</tr>
<?php endforeach ;endif;?>
</tbody>
</table>
</div>
</div>
<div class="clear"></div>
try redirect('/careers', 'refresh');
from the docs
The optional second parameter allows you to force a particular
redirection method. The available methods are auto, location and
refresh, with location being faster but less reliable on IIS servers.
The default is auto, which will attempt to intelligently choose the
method based on the server environment.
Try with adding single quote in the model get_jobs_list() function.
change $this->db->where(array('jobs_list.status'=>1)); to $this->db->where(array('jobs_list.status'=>'1'));
I am working on php using codeigniter framework as a beginner. My program is running perfectly on my localhost. But after uploading to the web server, it is showing an error for some pages. I have searched about this problem and most of the solutions show that my program is right. But for the live server, it is showing PHP fatal error. First one is, whenever I want to see data in datatable it is showing HTTP 500 error. My server administrator told me this is because of my model whenever I am returning data as result_array(). Here is my model,
public function get_pages()
{
$this->db->select('*');
$this->db->from('page');
$this->db->join('NavigationMenu', 'NavigationMenu.MenuID = page.MenuID', 'left');
$this->db->join('SubMenu', 'SubMenu.SubMenuID = Page.SubMenuID', 'left');
$query = $this->db->get();
return $query->result_array();
}
Here is my controller for that,
public function pages()
{
$data['page'] = $this->Pages_Model->get_pages();
$tempString = $this->load->view('admin_panel/content/pages', $data, true);
$page_data = array(
'fileHere' => $tempString
);
$this->load->view('admin_panel/shared/admin_layout',$page_data);
}
And this is my View page,
<!-- Main content -->
<div class="box">
<div class="box-header">
<h3 class="box-title">Page Lists</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="page_table" class="table table-bordered table-striped">
<thead>
<tr>
<th>Title</th>
<th>Main Menu</th>
<th>Sub-Menu</th>
<th>Edit/Remove</th>
</tr>
</thead>
<tbody>
<?php foreach ($page as $page_item): ?>
<tr>
<td><?php echo $page_item['PageTitle']; ?></td>
<td><?php echo $page_item['MenuName']; ?></td>
<td><?php echo $page_item['SubMenuName']; ?></td>
<td><button type="submit" class="btn btn-primary" onClick="javascipt:window.location.href='<?php echo base_url('content/edit_page_content')?>/<?php echo $page_item['PageID']; ?>'">Edit</button>
<button type="submit" class="btn btn-danger delete_page" id="<?php echo $page_item['PageID']; ?>">Remove</button></td></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.content -->
This is one of my problem. I beleive if I get a solution I can solve others. The result_array() function is working perfectly in other places like where I need to fetch data. Thank you in advance.
Try This as controller,
public function pages()
{
$data['page'] = $this->Pages_Model->get_pages();
$this->load->view('admin_panel/content/pages',$data);
$this->load->view('admin_panel/shared/admin_layout',$data);
}
</pre>
My database is case-sensitive. This is the reason it is showing that error. I have modified my model and it works now.
public function get_pages()
{
$this->db->select('*');
$this->db->from('Page');
$this->db->join('NavigationMenu', 'NavigationMenu.MenuID = Page.MenuID', 'left');
$this->db->join('SubMenu', 'SubMenu.SubMenuID = Page.SubMenuID', 'left');
$query = $this->db->get();
return $query->result_array();
}
I'm running into a strange scenario involving a widget and the lay-out. I've created a layout that overrides the original column 2 lay-out. It calls a widget in the file and in that widget display a table on the side-bar of some information that I would like to show the user. The layout sidetable.php looks like this
<?php $this->beginContent('//layouts/main'); ?>
<div class="row-fluid">
<div class="span3">
<?php
$this->widget('ListSummaryWidget', array('totaldue'=>$totaldue));
?>
<table class="table">
</table>
</div><!-- sidebar span3 -->
<div class="span9">
<div class="main">
<?php echo $content; ?>
</div><!-- content -->
</div>
</div>
<?php $this->endContent(); ?>
Now all this works - displaying a datatable on the left hand column of the screen. However, something strange happens. Whenever I git rid of
<table class="table">
</table>
The whole view breaks - showing a ridiculous structure/layout that doesn't look much at all like the original. This is confusing/intriguing. In my widget I declare the exact same table and yet it does not seem to matter that I declare this table. Here is the code for my widget's view
<table class="table list_summary table-bordered">
<form action="<?php echo Yii::app()->createUrl('recipient/processpayment', array('id'=>$id)) ?>" method="post" >
<tr class="primary"><td> <h4>List Summary </h4> </td></tr>
<tr ><td>
<?php echo $numpeople; ?> Recipient(s)
</td></tr>
<tr ><td>
Total Due: <?php echo $totaldue ?> Rwf
</td></tr>
<tr> <td>
<h4> Mobile Money Accounts: </h4>
<?php
/*
foreach($accounts as $account)
{
echo $account->name; ?>: <?php echo $account->balance; ?> Rwf<br> <?php
}
*/
?>
</td> </tr>
<tr> <td>
<button class="btn btn-block btn-primary " type="submit">Pay Now</button> </td> </tr>
</td></tr>
</form>
Could anyone explain why this is happening? Though it's not the worst thing in the world - I'm really intrigued as to why I'm required to have some html when I have the same html in the widget's view.
Resolved:
I didn't end the table in my widget. I should have added at the end
</table>
I have a wysiwyg on a site. The problem is that the users are copy pasting a lot of data in to it leaving a lot of unclosed and improperly formatted div tags that are breaking the site layout.
Is there an easy an easy way to strip all occurrences of <div> and </div>?
str_replace won't work because some of the divs have styling and other things in them so it would need to account for <div style="some styling"> <div align="center"> etc.
I'm guessing this could be done with a regular expression but I am total a total beginner when it comes to those.
Better to use DOM for HTML parser but if you have no choice but to use RegEx then you can use it like this:
$patterns = array();
$patterns[0] = '/<div[^>]*>/';
$patterns[1] = '/<\/div>/';
$replacements = array();
$replacements[2] = '';
$replacements[1] = '';
echo preg_replace($patterns, $replacements, $html);
No. You do NOT ever parse/manipulate HTML with regexes.
Regexes cannot be bargained with. They can't be reasoned with. They don't understand html, they don't grok xml. And they absolute will NOT stop until your DOM tree is dead.
You use htmlpurifier and/or DOM to manipulate the tree.
Here's a simplified example of how you could do it with PHP
<?php
/**
* Removes the divs because why not
*/
function strip_divs(&$text, $id = 'html') {
$replacements = array();
worker($text, $replacements, $id);
foreach ($replacements as $key => $val) {
$text = mb_str_replace($key, $val, $text);
}
return $text;
}
function worker(&$body, &$replacements, $id) {
static $call_count;
if (empty($call_count)) {
$call_count = array();
}
if (empty($call_count[$id])) {
$call_count[$id] = 0;
}
if (mb_strpos($body, '</div>')) {
$body = mb_str_replace('</div>', '', $body);
}
if (mb_strpos($body, '<di') !== FALSE) {
$call_count[$id] ++;
// Gets the important junk
$rm = '<di' . xml_get($body, '<di', '>') . '>';
// Builds the replacements HTML
$replacement_html = '';
$next_id = count($replacements);
$replacement_id = "[[div-$next_id]]";
$replacements[$replacement_id] = $replacement_html;
$body = mb_str_replace($rm, $replacement_id, $body);
if (mb_strpos($body, '<di') !== FALSE && $call_count[$id] < 200) {
worker($body, $replacements, $id);
}
}
}
/**
* Returns text by specifying a start and end point
*
* #param str $str
* The text to search
* #param str $start
* The beginning identifier
* #param str $end
* The ending identifier
*/
function xml_get($str, $start, $end) {
$str = "|" . $str . "|";
$len = mb_strlen($start);
if (mb_strpos($str, $start) > 0) {
$int_start = mb_strpos($str, $start) + $len;
$temp = right($str, (mb_strlen($str) - $int_start));
$int_end = mb_strpos($temp, $end);
$return = trim(left($temp, $int_end));
return $return;
}
else {
return FALSE;
}
}
function right($str, $count) {
return mb_substr($str, ($count * -1));
}
function left($str, $count) {
return mb_substr($str, 0, $count);
}
/**
* Multibyte str replace
*/
if (!function_exists('mb_str_replace')) {
function mb_str_replace($search, $replace, $subject, &$count = 0) {
if (!is_array($subject)) {
$searches = is_array($search) ? array_values($search) : array($search);
$replacements = is_array($replace) ? array_values($replace) : array($replace);
$replacements = array_pad($replacements, count($searches), '');
foreach ($searches as $key => $search) {
$parts = mb_split(preg_quote($search), $subject);
$count += count($parts) - 1;
$subject = implode($replacements[$key], $parts);
}
}
else {
foreach ($subject as $key => $value) {
$subject[$key] = mb_str_replace($search, $replace, $value, $count);
}
}
return $subject;
}
}
$html = <<<HTML
<table>
<tbody>
<tr>
<td class="votecell">
<div class="vote">
<input type="hidden" name="_id_" value="9607101">
<a class="vote-up-off" title="This question shows research effort; it is useful and clear">up vote</a>
<span itemprop="upvoteCount" class="vote-count-post ">0</span>
<a class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful">down vote</a>
<a class="star-off" href="#">favorite</a>
<div class="favoritecount"><b></b></div>
</div>
</td>
<td class="postcell">
<div>
<div class="post-text" itemprop="text">
<p>I have a wysiwyg on a site. The problem is that the users are copy pasting a lot of data in to it leaving a lot of unclosed and improperly formatted div tags that are breaking the site layout. </p>
<p>Is there an easy an easy way to strip all occurrences of <code><div></code> and <code></div></code>?</p>
<p>str_replace won't work because some of the divs have styling and other things in them so it would need to account for <code><div style="some styling"> <div align="center"></code> etc</p>
<p>I'm guessing this could be done with a regular expression but I am total a total beginner when it comes to those. </p>
<p>Thanks a lot,
Martin
</p>
</div>
<div class="post-taglist">
php regex replace str-replace strip-tags
</div>
<table class="fw">
<tbody>
<tr>
<td class="vt">
<div class="post-menu">share<span class="lsep">|</span>improve this question</div>
</td>
<td align="right" class="post-signature">
<div class="user-info ">
<div class="user-action-time">
edited <span title="2012-03-07 18:32:29Z" class="relativetime">Mar 7 '12 at 18:32</span>
</div>
<div class="user-gravatar32">
</div>
<div class="user-details">
<div class="-flair">
</div>
</div>
</div>
</td>
<td class="post-signature owner">
<div class="user-info ">
<div class="user-action-time">
asked <span title="2012-03-07 18:31:11Z" class="relativetime">Mar 7 '12 at 18:31</span>
</div>
<div class="user-gravatar32">
<a href="/users/702826/martin-hunt">
<div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/a578c3eae229c86dbe46d4b1603e071b?s=32&d=identicon&r=PG" alt="" width="32" height="32"></div>
</a>
</div>
<div class="user-details">
Martin Hunt
<div class="-flair">
<span class="reputation-score" title="reputation score " dir="ltr">313</span><span title="7 silver badges"><span class="badge2"></span><span class="badgecount">7</span></span><span title="20 bronze badges"><span class="badge3"></span><span class="badgecount">20</span></span>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<td class="votecell"></td>
<td>
<div id="comments-9607101" class="comments ">
<table>
<tbody data-remaining-comments-count="0" data-canpost="false" data-cansee="true" data-comments-unavailable="false" data-addlink-disabled="true">
<tr id="comment-12187969" class="comment ">
<td class="comment-actions">
<table>
<tbody>
<tr>
<td class=" comment-score">
<span title="number of 'useful comment' votes received" class="cool">1</span>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</td>
<td class="comment-text">
<div style="display: block;" class="comment-body">
<span class="comment-copy">So you need to remove all the div tags but not the content between the div. Am I right?</span>
– Siva Charan
<span class="comment-date" dir="ltr"><a class="comment-link" href="#comment12187969_9607101"><span title="2012-03-07 18:34:11Z" class="relativetime-clean">Mar 7 '12 at 18:34</span></a></span>
</div>
</td>
</tr>
<tr id="comment-12189778" class="comment ">
<td>
<table>
<tbody>
<tr>
<td class=" comment-score">
</td>
<td>
</td>
</tr>
</tbody>
</table>
</td>
<td class="comment-text">
<div style="display: block;" class="comment-body">
<span class="comment-copy">Replace the XPath with <code>//div[not[#*]]</code> to remove all div elements (incl. content) without attributes.</span>
– Gordon
<span class="comment-date" dir="ltr"><a class="comment-link" href="#comment12189778_9607101"><span title="2012-03-07 19:58:21Z" class="relativetime-clean">Mar 7 '12 at 19:58</span></a></span>
<span class="edited-yes" title="this comment was edited 2 times"></span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="comments-link-9607101" data-rep="50" data-anon="true">
<a class="js-add-link comments-link disabled-link " title="Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.">add a comment</a><span class="js-link-separator dno"> | </span>
<a class="js-show-link comments-link dno" title="expand to show all comments on this post" href="#" onclick=""></a>
</div>
</td>
</tr>
</tbody>
</table>
HTML;
echo strip_divs($html);