草庐IT

php - 在 php 中获取具有相同用户 ID 的所有行值?

coder 2023-10-24 原文

我在 wordpress 网站上工作,我只是遇到了一个 sql 查询。

我需要从包含相同用户 ID 的数据库表中获取值。

这是我的 table :

当我在 mysql 中运行选择查询时,它获取的结果是正确的:

但我不知道如何在我的 php 模板中得到这个结果。

这是我在 php 中使用的查询:

$current_user = wp_get_current_user(); 
    $id=$current_user->ID;
    $skill1 =mysql_query("SELECT Skills FROM wp_candidate_skills WHERE user_id='{$id}' "); 

我不能使用 get->result 因为它显示 get->result 必须包含对象的错误。像这样的错误是。

这是我在 Mysql_query 之后使用的:

$arr = mysql_fetch_array($skill1);
  print_r($arr);

输出是:

WordPress 代码:

public static function init_fields() {
        if ( self::$fields )
            return;
$current_user = wp_get_current_user(); 
    $user = $current_user->user_login;
    $useremail =  $current_user->user_email;
    $id=$current_user->ID;
$skill1 =mysql_query("SELECT ID,user_id,Skills FROM wp_candidate_skills WHERE user_id=$id"); 
$skill_note = mysql_fetch_array($skill1);
$result = mysql_query("SELECT * FROM wp_candidate_details WHERE user_id='{$id}' LIMIT 1"); 
$expe_note = mysql_fetch_assoc($result);
$job_title = $expe_note['job-cat1'];
$user_loc = $expe_note['location_one_id'];
$row_num = mysql_query("SELECT COUNT(Skills) FROM wp_candidate_skills WHERE user_id='{$id}' " );
$row_cnt = mysql_fetch_array($row_num);
$arr = mysql_fetch_array($skill1);
print_r($arr);
mysql_free_result($skill1);
    $skill_area = $skill_note['Skills'];
        self::$fields = apply_filters( 'submit_resume_form_fields', array(
            'resume_fields' => array(
                 'candidate_name' => array(
                    'label'       => __( 'Your name', 'wp-job-manager-resumes' ),
                    'type'        => 'text',
                    'required'    => true,
                    'placeholder' => __( 'Your full name', 'wp-job-manager-resumes' ),
                    'priority'    => 1,
                    'value'       => $user
                ),
                'candidate_email' => array(
                    'label'       => __( 'Your email', 'wp-job-manager-resumes' ),
                    'type'        => 'text',
                    'required'    => true,
                    'placeholder' => __( 'you@yourdomain.com', 'wp-job-manager-resumes' ),
                    'priority'    => 2,
                    'value'       => $useremail
                ),
                'candidate_title' => array(
                    'label'       => __( 'Professional title', 'wp-job-manager-resumes' ),
                    'type'        => 'text',
                    'required'    => true,
                    'placeholder' => __( 'e.g. "Web Developer"', 'wp-job-manager-resumes' ),
                    'priority'    => 3,
                    'value'       => $job_title
                ),
                'candidate_location' => array(
                    'label'       => __( 'Location', 'wp-job-manager-resumes' ),
                    'type'        => 'text',
                    'required'    => true,
                    'placeholder' => __( 'e.g. "London, UK", "New York", "Houston, TX"', 'wp-job-manager-resumes' ),
                    'priority'    => 4,
                    'value'       => $user_loc
                ),

            'resume_skills' => array(
                'label'       => __( 'Skills', 'wp-job-manager-resumes' ),
                'type'        => 'text',
                'required'    => false,
                'placeholder' => __( 'Comma separate a list of relevant skills', 'wp-job-manager-resumes' ),
                'priority'    => 9,
                'value'      =>  $skill_area

            ),
            'links' => array(
                'label'       => __( 'URL(s)', 'wp-job-manager-resumes' ),
                'type'        => 'links',
                'required'    => false,
                'placeholder' => '',
                'description' => __( 'Optionally provide links to any of your websites or social network profiles.', 'wp-job-manager-resumes' ),
                'priority'    => 10,
                'fields'      => array(
                    'name' => array(
                        'label'       => __( 'Name', 'wp-job-manager-resumes' ),
                        'type'        => 'text',
                        'required'    => true,
                        'placeholder' => '',
                        'priority'    => 1
                    ),
                    'url' => array(
                        'label'       => __( 'URL', 'wp-job-manager-resumes' ),
                        'type'        => 'text',
                        'required'    => true,
                        'placeholder' => 'http://',
                        'priority'    => 2
                    )
                )
            ),
            'candidate_education' => array(
                'label'       => __( 'Education', 'wp-job-manager-resumes' ),
                'type'        => 'education',
                'required'    => false,
                'placeholder' => '',
                'priority'    => 11,
                'fields'      => array(
                    'location' => array(
                        'label'       => __( 'School name', 'wp-job-manager-resumes' ),
                        'type'        => 'text',
                        'required'    => true,
                        'placeholder' => ''
                    ),
                    'qualification' => array(
                        'label'       => __( 'Qualification(s)', 'wp-job-manager-resumes' ),
                        'type'        => 'text',
                        'required'    => true,
                        'placeholder' => ''
                    ),
                    'date' => array(
                        'label'       => __( 'Start/end date', 'wp-job-manager-resumes' ),
                        'type'        => 'text',
                        'required'    => true,
                        'placeholder' => ''
                    ),
                    'notes' => array(
                        'label'       => __( 'Notes', 'wp-job-manager-resumes' ),
                        'type'        => 'textarea',
                        'required'    => false,
                        'placeholder' => ''
                    )
                )
            ),
            'candidate_experience' => array(
                'label'       => __( 'Experience', 'wp-job-manager-resumes' ),
                'type'        => 'experience',
                'required'    => false,
                'placeholder' => '',
                'priority'    => 12,
                'fields'      => array(
                    'employer' => array(
                        'label'       => __( 'Employer', 'wp-job-manager-resumes' ),
                        'type'        => 'text',
                        'required'    => true,
                        'placeholder' => ''
                    ),
                    'job_title' => array(
                        'label'       => __( 'Job Title', 'wp-job-manager-resumes' ),
                        'type'        => 'text',
                        'required'    => true,
                        'placeholder' => ''
                    ),
                    'date' => array(
                        'label'       => __( 'Start/end date', 'wp-job-manager-resumes' ),
                        'type'        => 'text',
                        'required'    => true,
                        'placeholder' => ''
                    ),
                    'notes' => array(
                        'label'       => __( 'Notes', 'wp-job-manager-resumes' ),
                        'type'        => 'textarea',
                        'required'    => false,
                        'placeholder' => ''
                    )
                )
            ), 
            'resume_file' => array(
                'label'       => __( 'Resume file', 'wp-job-manager-resumes' ),
                'type'        => 'file',
                'required'    => false,
                'description' => sprintf( __( 'Optionally upload your resume for employers to view. Max. file size: %s.', 'wp-job-manager-resumes' ), size_format( wp_max_upload_size() ) ),
                'priority'    => 13,
                'placeholder' => ''
            ),
        )
    ) );
    if ( ! get_option( 'resume_manager_enable_resume_upload' ) )
        unset( self::$fields['resume_fields']['resume_file'] );

    if ( ! get_option( 'resume_manager_enable_categories' ) || wp_count_terms( 'resume_category' ) == 0 )
        unset( self::$fields['resume_fields']['resume_category'] );

    if ( ! get_option( 'resume_manager_enable_skills' ) )
        unset( self::$fields['resume_fields']['resume_skills'] );
}

帮帮我,伙计们!谢谢

最佳答案

试试这个代码,`$skill1 = $wpdb->get_results("SELECT ID,user_id,Skills FROM wp_candidate_skills WHERE user_id='$id'");

        $count = count($skill1);
        $array = array();
        foreach ($skill1 as $key => $value) {
            $sk = $value->Skills;
            $array[] = $sk;
        }

        $fixId =array();
        $fixId[0] ='';
        for($i=0;$i<=$count-1;$i++)
        {
            $temp = $array[$i];
            $fixId[0] = $fixId[0].$temp.',';
        }
        $data = $fixId[0] ;
        $words = array_filter(preg_split('/\s*,\s*/', $data));
        $temp = implode(', ', $words);`

它将获取数据作为数组,并在两个值之间插入逗号。

关于php - 在 php 中获取具有相同用户 ID 的所有行值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32605757/

有关php - 在 php 中获取具有相同用户 ID 的所有行值?的更多相关文章

  1. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  2. ruby - 如何以所有可能的方式将字符串拆分为长度最多为 3 的连续子字符串? - 2

    我试图获取一个长度在1到10之间的字符串,并输出将字符串分解为大小为1、2或3的连续子字符串的所有可能方式。例如:输入:123456将整数分割成单个字符,然后继续查找组合。该代码将返回以下所有数组。[1,2,3,4,5,6][12,3,4,5,6][1,23,4,5,6][1,2,34,5,6][1,2,3,45,6][1,2,3,4,56][12,34,5,6][12,3,45,6][12,3,4,56][1,23,45,6][1,2,34,56][1,23,4,56][12,34,56][123,4,5,6][1,234,5,6][1,2,345,6][1,2,3,456][123

  3. ruby-on-rails - 使用 rails 4 设计而不更新用户 - 2

    我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它​​不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数

  4. ruby-on-rails - 跳过状态机方法的所有验证 - 2

    当我的预订模型通过rake任务在状态机上转换时,我试图找出如何跳过对ActiveRecord对象的特定实例的验证。我想在reservation.close时跳过所有验证!叫做。希望调用reservation.close!(:validate=>false)之类的东西。仅供引用,我们正在使用https://github.com/pluginaweek/state_machine用于状态机。这是我的预订模型的示例。classReservation["requested","negotiating","approved"])}state_machine:initial=>'requested

  5. ruby - 如果指定键的值在数组中相同,如何合并哈希 - 2

    我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat

  6. ruby - Nokogiri 剥离所有属性 - 2

    我有这个html标记:我想得到这个:我如何使用Nokogiri做到这一点? 最佳答案 require'nokogiri'doc=Nokogiri::HTML('')您可以通过xpath删除所有属性:doc.xpath('//@*').remove或者,如果您需要做一些更复杂的事情,有时使用以下方法遍历所有元素会更容易:doc.traversedo|node|node.keys.eachdo|attribute|node.deleteattributeendend 关于ruby-Nokog

  7. ruby - 简单获取法拉第超时 - 2

    有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url

  8. ruby - 从 Ruby 中的主机名获取 IP 地址 - 2

    我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge

  9. ruby - 获取模块中定义的所有常量的值 - 2

    我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c

  10. ruby-on-rails - 获取 inf-ruby 以使用 ruby​​ 版本管理器 (rvm) - 2

    我安装了ruby​​版本管理器,并将RVM安装的ruby​​实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby​​。有没有办法让emacs像shell一样尊重ruby​​的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el

随机推荐