i create custom plugin and i have table wp_customers , i try to select all things in my table but wordpress just show me Fatal error: Uncaught Error: Call to a member function get_results() on null in C:\xampp\htdocs\wordpress\wordpress\wp-content\plugins\rflredirection\public\showResult.php:4 Stack trace: #0 {main} thrown in C:\xampp\htdocs\wordpress\wordpress\wp-content\plugins\rflredirection\public\showResult.php on line 4
i see codex , i use some antoher codes for select but i just that massege , this is my codes to try
global $wpdb;
$results = $wpdb->get_results('SELECT * FROM $wpd->wp_customers DESC ');
and
$results = $wpdb->get_results('SELECT * FROM wp_customers');
and
$table_name = $wpdb->prefix . "wp_customers";
$results = $wpdb->get_results("SELECT code FROM ".$table_name");
and i try get version but nothing
$dbVersion = $wpdb->db_version();
if ($dbVersion) {
echo "Running MySQL " . $dbVersion;
} else {
echo "MySQL version unavailable.";
}
When you use The wpdb Class, there is no need to include wp_ in tables name.
should be just like this:
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM $wpdb->customers");
// ^ use without (wp_)
Edit #1:
you have an error on foreach loop:
you should write foreach($results as $rows) instead of your error : foreach($rows as $results)
and don't forget the semicolons when get values, echo $rows["id"]; and so on..
your code should like:
<?php
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM $wpdb->customers");
?>
<body>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Family</th>
<th>Numbers</th>
<th>Tell</th>
</tr>
<?php foreach($results as $rows){
?>
<tr>
<td>
<?php echo $rows["id"]; ?>
</td>
<td>
<?php echo $rows["name"]; ?>
</td>
<td>
<?php echo $rows["family"]; ?>
</td>
<td>
<?php echo $rows["numbers"]; ?>
</td>
<td>
<?php echo $rows["tell"]; ?>
</td>
<?php }?>
</tr>
</table>
Edit #2:
Copy all this lines and paste on top of your page to include wordpress package:
<?php
/**
* WordPress User Page
*
* Handles authentication, registering, resetting passwords, forgot password,
* and other user handling.
*
* #package WordPress
*/
// Make sure that the WordPress bootstrap has run before continuing.
require( dirname(__FILE__) . '/wp-load.php' );
// Now your page codes goes here ...
Related
I am getting a problem in codeigniter where i have a view file called view.php.
<?php echo form_open('');?>
<table class="table">
<thead>
<tr>
<th>Full Name</th>
<th>Username</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo form_input('fullname1',$row_data['fullname']);?> </td>
<td><?php echo form_input('username1',$row_data['username']);?></td>
<td><?php echo anchor("welcome/save/".$row_data['rid'],form_button('button',"Save"));?></td>
</tr>
</tbody
</table>
<?php echo form_close();?>
and here is my save method
public function save($rid){
$arr=array('fullname'=>$this->input->post('fullname1'),
'username'=>$this->input->post('username1')
);
var_dump($_POST);
var_dump($arr);
}
both array varable giving me NULL values while the textboxes have the values Please Help.... Thanks
you need to add the url to your form_open method. Try
echo form_open("your_url");
give the path of your save method instead of your_url.
Also check documentation here
The form_open method demands a target url.
In View
# Syntax <?php echo form_open('controllerName/MethodName');?>
<?php echo form_open('welcome/save');?>
// remove this
<td><?php echo anchor("welcome/save/".$row_data['rid'],form_button('button',"Save"));?></td>
// Add this
echo form_submit('mysubmit', 'Submit Post!');
In Controller
public function save(){
$fullname= $this->input->post('fullname1');
$username = $this->input->post('username1');
echo "MY name is ".$fullname." UserName Is : "$username;
}
Read Form Helper Codeigniter and form-validation-using-codeigniter example
I'm looking for a way to profile queries which are performed internally by Zend_Table.
For example, after you finish Quickstart course, how to profile all the queries that are performed ?
I've tried to enable profiler from application.ini like this:
resources.db.profiler.class = "Zend_Db_Profiler_Firebug"
resources.db.profiler.enabled = true
And placed next rows in a Guestbook controller:
...
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$profiler = $db->getProfiler();
echo $profiler->getTotalElapsedSecs();
Which gives me 0
I've also tried to enable profiler in a Bootstrap file like this:
protected function _initProfiler() {
$this->bootstrap("db");
$profiler = new Zend_Db_Profiler_Firebug("All DB Queries");
$profiler->setEnabled(true);
Zend_Registry::get("db")->setProfiler($profiler);
}
Whick doesn't give me any result (I've installed and tested Firebug and FirePHP, using Zend_Log_Writer_Firebug())
I will appreciate any help. Thanks !
I've not tried the Firebug profiler. But I do use a html table to output profiler info at the bottom of each page that does a query.
enable profiler in application.ini
resources.db.params.profiler = true
render the profile results in the layout:
<?php
$this->addScriptPath(APPLICATION_PATH . '/views/scripts');
echo $this->render('profiler.phtml')
?>
profiler.phtml the view to render
<?php
// get the default db adapter
$adapter = Zend_Db_Table::getDefaultAdapter();
$profiler = $adapter->getProfiler();
if ($profiler->getEnabled() && $profiler->getTotalNumQueries() > 0) :
?>
<div style='text-align:center'>
<h2>Database Profiling Report</h2>
<p>Total queries executed: <?php echo $profiler->getTotalNumQueries() ?></p>
<p>Total elapsed time: <?php echo $profiler->getTotalElapsedSecs() ?></p>
</div>
<table class='spreadsheet' cellpadding='0' cellspacing='0' style='margin:10px auto'>
<thead>
<tr>
<th>#</th>
<th>Query</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<?php foreach ($profiler->getQueryProfiles() as $queryNumber => $query) : ?>
<tr>
<td>(<?php echo $queryNumber + 1 ?>)</td>
<td><?php echo $query->getQuery(); ?></td>
<td><?php echo $query->getElapsedSecs(); ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php endif ?>
I don't imagine that using the firebug profiler is much more difficult.
The problem was in the parameters instantiation. When I've entered
resources.db.params.profiler.class = "Zend_Db_Profiler_Firebug"
resources.db.params.profiler.enabled = true
instead of previous configuration, everything went fine.
Note .params section of the parameter lines
I am creating a form with an upload element. I have created the file element with the code below
$image = new Zend_Form_Element_File('image');
$image->setAttrib('title','Listing Image:')
->addDecorator('File')
->addValidator('Size', false, 204800)
->addValidator('Extension', false, 'jpg,png,gif');
$this->addElement($image);
Which as far as I can tell works fine. It tries to add a file element to the page. I get an error which says " Warning: No file decorator found... unable to render file element in..."
As you can see I have set the decorator for the element to be the File decorator so I am unsure why I am getting this error?
It is worth noting I have removed all default decorators except for viewHelper and PrepareElements and I am using a view partial as the viewHelper to display the output. Just incase this is required I have also included that below.
<form method="<?php echo $this->element->getMethod(); ?>" action="<?php echo $this->element->getAction(); ?>">
<div class="boxmiddle-Holder">
<div class="boxmiddle-content">
<table border="0" cellspacing="2" cellpadding="3" class="dataTable">
<?php foreach($this->element->getElements() as $element): ?>
<!-- if not a button then display label -->
<tr>
<td><label for="<?php echo $element->getName(); ?>"><?php echo $element->getAttrib('title'); ?></label></td>
<td class="normal"><?php echo $element; ?></td>
<?php if($element->getMessages()) {
foreach($element->getMessages() as $message) { ?>
<td> <?php echo "<p class='elementError'>".$message."</p>"; ?></td>
<?php }
}
?>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
Any ideas?
I'd double check to make sure the File decorator isn't being cleared or reset later, that error indicates that your form's file element does not have a Zend_Form_Decorator_File decorator attached to it.
Look in Zend/Form/Element/File.php around line 859 for the function that throws this error. I suspect somehow the File decorator is being removed from the element. It could be that it has no decorators or is just lacking the File decorator.
Hope that helps.
I am NEW to ZF .i used zend paginator in my first project .its working fine that is switching b/w pages with right result but the problem is that i have other links too in that view have a look to my view
<?php include "header.phtml"; ?>
<h1><?php echo $this->escape($this->title);?></h1>
<h2><?php echo $this->escape($this->description);?></h2>
Register
<table border="1" align="center">
<tr>
<th>User Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</tr>
<?php
foreach($this->paginator as $record){?>
<tr>
<td><?php echo $record->user_name;?></td>
<td><?php echo $record->first_name;?></td>
<td><?php echo $record->last_name;?></td>
<td>
Edit
|
Delete
</td>
</tr>
<?php } ?>
</table>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>
<?php include "footer.phtml"; ?>
as i said the pagination renders and working fine but when i click on these links
<a id="edit_link" href="edit/id/<?php echo $record->id;?>">Edit</a>
or
<a id="delete_link" href="del/id/<?php echo $record->id;?>">Delete</a>
or
Register
it is not calling the required action instead it make my url like this
(initial link) http://localhost/zend_login/web_root/index.php/task/list
after clicking any of the above link its like this
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/8
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/23
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/register http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/del/id/12
note its not happening when the page renders first time but when i click on any pagination link its doing so initialy its going to the reguired action and displaying a view...any help HERE IS THE ACTION
public function listAction(){
$registry = Zend_Registry::getInstance();
$DB = $registry['DB'];
$sql = "SELECT * FROM task ORDER BY task_name ASC";
$result = $DB->fetchAll($sql);
$page=$this->_getParam('page',1);
$paginator = Zend_Paginator::factory($result);
$paginator->setItemCountPerPage(3);
$paginator->setCurrentPageNumber($page);
$this->view->assign('title','Task List');
$this->view->assign('description','Below, are the Task:');
$this->view->paginator=$paginator;
}
Try:
// controller
$this->view->controllerName = $this->getRequest()->getControllerName();
// view script
Edit
|
Delete
or
Edit
|
Delete
Second example uses baseUrl() view helper that's using front controller's baseUrl setting. If you don't set baseUrl in your frontController it's trying to guess. As you're not using bootstrap functionality to set baseUrl you may do the following in index.php (not required):
$frontController = Zend_Controller_Front::getInstance();
$frontController->setBaseUrl('/');
Third possibility using url() view helper:
<a href="<?php echo $this->url(array(
'controller' => $controllerName,
'action' => 'edit',
'id' => $record_->id
)); ?>">Edit</a>
|
<a href="<?php echo $this->url(array(
'controller' => $controllerName,
'action' => 'del',
'id' => $record_->id
));?>">Delete</a>
add this in your action
$request = $this->getRequest();
$this->view->assign('url', $request->getBaseURL());
and replace your links in view with this
Add a Task
Edit
Delete
I'd like to have a table of data coming from the DB in my form element, looking like the following :
+-----+-------------------------+-----------------------+
| | Number | Name |
+-----+-------------------------+-----------------------+
| [ ] | 123 | ABC |
+-----+-------------------------+-----------------------+
| [x] | 456 | DEF |
+-----+-------------------------+-----------------------+
| [x] | 789 | HIJ |
+-----+-------------------------+-----------------------+
It would allow to select several rows, like the MultiCheckBox element.
Here is the kind of markup I would like to have:
<table>
<thead>
<tr>
<th>Select</th>
<th>Number</th>
<th>Name</th>
</tr>
</thead>
<tr>
<td><input type="checkbox" name="subscribers[]" value="1234"></td>
<td>1234</td>
<td>ABC</td>
</tr>
<tr>
<td><input type="checkbox" name="subscribers[]" value="375950"></td>
<td>375950</td>
<td>DEF</td>
</tr>
<!-- and so on... -->
I can do it by hand but using Zend_Form would allow me to populate the form, retrieve the values easily and to have validation. I have other normal elements in my form.
Any idea on how to achieve this with Zend_Form ? Maybe a custom element and decorator ?
Thanks. Ask for more info if needed.
This question seems to be related: Zend_Form: Database records in HTML table with checkboxes
Marc
ok, so this is going to be a longer sort of answer
the Form
<?php
class Form_MyTest extends Zend_Form
{
public function init()
{
$element = $this->createElement('multiCheckbox', 'subscribers');
$element->setOptions(array('value1' => 'label1', 'value2' => 'label2'));
$this->addElement($element);
// ... other elements
}
}
Controller
<?php
class MyController extends Zend_Controller_Action
{
public function myTestAction()
{
$form = new Form_MyTest();
// ... processing logics
$this->view->assign('form', $form);
}
}
View
<form action="<?php echo $this->form->getAction(); ?>" method="<?php echo $this->form->getMethod(); ?>">
<table>
<thead>
<tr>
<th>Select</th>
<th>Number</th>
<th>Name</th>
</tr>
</thead>
<?php $values = $this->form->getElement('subscribers')->getValue(); ?>
<?php foreach($this->form->getElement('subscribers')->getMultiOptions() as $key => $value) : ?>
<tr>
<td><input type="checkbox" name="subscribers[]" id="subscribers-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php echo in_array($key, $values) ? 'checked="checked"':''; ?>/></td>
<td><label for="subscribers-<?php echo $key; ?>"><?php echo $key; ?></label></td>
<td><label for="subscribers-<?php echo $key; ?>"><?php echo $value; ?></label></td>
</tr>
<?php endforeach; ?>
</table>
<!-- rest of form -->
</form>
A couple things are happening here.
I get the prepopulated values out of the form object:
<?php $values = $this->form->getElement('subscribers')->getValue(); ?>
I mark each checkbox as checked or not based on the array above
<?php echo in_array($key, $values) ? 'checked="checked"':''; ?>
EDIT IN RESPONSE TO COMMENT B/C COMMENTS DON'T SUPPORT PRE BLOCKS
the
$element->setOptions(
or
$element->setMultiOptions(
only accepts key => value pairs, so anything you want to do outside of key value pairs is going to be a little wierd. If your program allows you could pass another variable to the view, an array that uses the same keys as the multiCheckbox so
$this->view->assign('more_datums', array('value1' => array('col_1' => 'col_1_val'[, ...])));
and then in the foreach in the view use
$this->more_datums[$key]['col_1']