admin管理员组文章数量:1130349
Trying to populate a drop down element of a html form in a word press page with data from SQL query in a php file in a php directory: site/php/.
Php code is working fine:
<?php
require_once "connectPDO.php";
define('WP_USE_THEMES', false);
require('../wp-load.php');
require_once('../wp-config.php');
require_once('../wp-includes/wp-db.php');
require_once('../wp-includes/pluggable.php');
require('../wp-blog-header.php');
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
$user = $current_user->ID;
} else {
echo '<a href="'. get_bloginfo('url') .'/wp-admin" class="loginlinktop">Login</a>';
}
global $wpdb;
$results = $wpdb->get_results("SELECT my-column FROM wp_table WHERE user_id = ."'$user'".");
if($results){
foreach($results as $value){
echo serialize ($value);
}
}
?>
In a wordpress page I use execPHP plugin and this instruction:
<?php require_once(ABSPATH. '/php/phpfile.php'); ?>
I just get a blank page. 1 How can I get the result on word press?
2 A code sample to populate drop down from a serialized array?
Thanks. I've been more than a week with this.
Trying to populate a drop down element of a html form in a word press page with data from SQL query in a php file in a php directory: site/php/.
Php code is working fine:
<?php
require_once "connectPDO.php";
define('WP_USE_THEMES', false);
require('../wp-load.php');
require_once('../wp-config.php');
require_once('../wp-includes/wp-db.php');
require_once('../wp-includes/pluggable.php');
require('../wp-blog-header.php');
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
$user = $current_user->ID;
} else {
echo '<a href="'. get_bloginfo('url') .'/wp-admin" class="loginlinktop">Login</a>';
}
global $wpdb;
$results = $wpdb->get_results("SELECT my-column FROM wp_table WHERE user_id = ."'$user'".");
if($results){
foreach($results as $value){
echo serialize ($value);
}
}
?>
In a wordpress page I use execPHP plugin and this instruction:
<?php require_once(ABSPATH. '/php/phpfile.php'); ?>
I just get a blank page. 1 How can I get the result on word press?
2 A code sample to populate drop down from a serialized array?
Thanks. I've been more than a week with this.
Share Improve this question edited Dec 31, 2016 at 13:18 SNS 1731 silver badge14 bronze badges asked Dec 31, 2016 at 11:24 Joan PescadorJoan Pescador 111 gold badge1 silver badge3 bronze badges2 Answers
Reset to default 1Thanks everybody for your answers. You bring me value clues. Finally I opted to make the query directly from wordpress page with the wordpress sintax for the defaults wordpress tables, using a little trick: Including my custom tables in wp-includes/wp-db.php.
wordpress code:
<?php
global $current_user;
get_currentuserinfo();
$user = $current_user->ID;
global $wpdb;
global $result;
$courses = array();
$result = $wpdb->get_results ( "SELECT * FROM $wpdb->mytable WHERE user_id = $user" );
?>
name
<select>
<option selected="selected">name</option>
<?php
foreach( $result as $value ) { ?>
<option value="<?php echo $value->name; ?>"><?php echo $value->name; ?></option>
<?php
}
?>
</select>
I would first check that $value is not null. Also, would it make more sense to call unserialize($value); here since you are pulling the data out of the database and not storing it?
Code sample for populating dropdown:
<select class="dropdown" id="mydropdown" name="mydropdown" title="My Dropdown">
<?php
foreach ($results as $value) {
echo '<option value="' . unserialize($value) . '">' . unserialize($value) . '</option>';
}
?>
</select>
Trying to populate a drop down element of a html form in a word press page with data from SQL query in a php file in a php directory: site/php/.
Php code is working fine:
<?php
require_once "connectPDO.php";
define('WP_USE_THEMES', false);
require('../wp-load.php');
require_once('../wp-config.php');
require_once('../wp-includes/wp-db.php');
require_once('../wp-includes/pluggable.php');
require('../wp-blog-header.php');
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
$user = $current_user->ID;
} else {
echo '<a href="'. get_bloginfo('url') .'/wp-admin" class="loginlinktop">Login</a>';
}
global $wpdb;
$results = $wpdb->get_results("SELECT my-column FROM wp_table WHERE user_id = ."'$user'".");
if($results){
foreach($results as $value){
echo serialize ($value);
}
}
?>
In a wordpress page I use execPHP plugin and this instruction:
<?php require_once(ABSPATH. '/php/phpfile.php'); ?>
I just get a blank page. 1 How can I get the result on word press?
2 A code sample to populate drop down from a serialized array?
Thanks. I've been more than a week with this.
Trying to populate a drop down element of a html form in a word press page with data from SQL query in a php file in a php directory: site/php/.
Php code is working fine:
<?php
require_once "connectPDO.php";
define('WP_USE_THEMES', false);
require('../wp-load.php');
require_once('../wp-config.php');
require_once('../wp-includes/wp-db.php');
require_once('../wp-includes/pluggable.php');
require('../wp-blog-header.php');
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
$user = $current_user->ID;
} else {
echo '<a href="'. get_bloginfo('url') .'/wp-admin" class="loginlinktop">Login</a>';
}
global $wpdb;
$results = $wpdb->get_results("SELECT my-column FROM wp_table WHERE user_id = ."'$user'".");
if($results){
foreach($results as $value){
echo serialize ($value);
}
}
?>
In a wordpress page I use execPHP plugin and this instruction:
<?php require_once(ABSPATH. '/php/phpfile.php'); ?>
I just get a blank page. 1 How can I get the result on word press?
2 A code sample to populate drop down from a serialized array?
Thanks. I've been more than a week with this.
Share Improve this question edited Dec 31, 2016 at 13:18 SNS 1731 silver badge14 bronze badges asked Dec 31, 2016 at 11:24 Joan PescadorJoan Pescador 111 gold badge1 silver badge3 bronze badges2 Answers
Reset to default 1Thanks everybody for your answers. You bring me value clues. Finally I opted to make the query directly from wordpress page with the wordpress sintax for the defaults wordpress tables, using a little trick: Including my custom tables in wp-includes/wp-db.php.
wordpress code:
<?php
global $current_user;
get_currentuserinfo();
$user = $current_user->ID;
global $wpdb;
global $result;
$courses = array();
$result = $wpdb->get_results ( "SELECT * FROM $wpdb->mytable WHERE user_id = $user" );
?>
name
<select>
<option selected="selected">name</option>
<?php
foreach( $result as $value ) { ?>
<option value="<?php echo $value->name; ?>"><?php echo $value->name; ?></option>
<?php
}
?>
</select>
I would first check that $value is not null. Also, would it make more sense to call unserialize($value); here since you are pulling the data out of the database and not storing it?
Code sample for populating dropdown:
<select class="dropdown" id="mydropdown" name="mydropdown" title="My Dropdown">
<?php
foreach ($results as $value) {
echo '<option value="' . unserialize($value) . '">' . unserialize($value) . '</option>';
}
?>
</select>
本文标签: phppopulate dropdown wordpress form from database custom table
版权声明:本文标题:php - populate dropdown wordpress form from database custom table 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749054233a2309070.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论