带有codeigniter框架的php

带有codeigniter框架的php

本文介绍了带有codeigniter框架的php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function invitation_result()
{
    $this->load->database();
    $user_id = $_GET['user_id'];
    $qry = mysql_query("select * from sent_invitations where user_id='$user_id'");

    if (mysql_num_rows($qry) > 0)
    {
        while ($row = mysql_fetch_array($qry))
        {
           $mobile_number = $row['mobile_number'];

           $qry1 = mysql_query("select mobile_number from users where mobile_number = '$mobile_number'");
           $row1 = mysql_fetch_array($qry1);
           $mobile_number = $row1['mobile_number'];
           $users[] = array('mobile_number' => $mobile_number );
           return $users;
        }
    }
}

以上是我的编码。
send_invitation表中有3行,其中user_id = 11。
从那里,我试图根据user_id获取所有三行的mobile_number。
所有3行的mobile_number不同。从send_notification表中获取mobile_number后的

我要比较mobile_number和mobile_number of users表。
我看到用户表中有3个mobile_numbers。
我想展示所有这些。
bt问题是我的代码ID仅显示一行,并且是3的最后一个手机号码。

The above is my coding.In sent_invitation table there are 3 rows with user_id=11.from there i m trying to get mobile_number of all three rows based on user_id.the mobile_number of all 3 rows is different.after geting mobile_number from sent_notification table.i m comparing the mobile_number with mobile_number of users table.i m seeing that 3 of them mobile_numbers are there in users table.i m trying to show all of them.bt problem is that my code id showing only one row and that is of last mobile number from 3

推荐答案

您应该在内部循环中使用 while 循环时,在内部循环中获得 mobile_number

You should use while loop where you are getting mobile_number in inner loop.

function invitation_result()
{
    $this->load->database();
    $user_id = $_GET['user_id'];
    $qry = $this->db->query("select * from sent_invitations where user_id='$user_id'");

    if ($qry->num_rows() > 0)
    {
        while ($qry->result_array() as $row)
        {
           $mobile_number = $row['mobile_number'];

           $qry1 = $this->db->query("select mobile_number from users where mobile_number = '$mobile_number'");
           if($qry1->num_rows() > 0){
           while($qry1->result_array() as $row1){
              $mobile_number = $row1['mobile_number'];
              $users[] = array('mobile_number' => $mobile_number );
           }
           return $users;
           }
        }
    }
}

您应该使用codeigniter数据库查询而不是 mysql 自定义查询。因为不推荐使用 mysql 。您可以使用以下代码:

You should use codeigniter database query instead of mysql custom query. because mysql is deprecated. You can use below code:

function invitation_result()
{
    $this->load->database();
    $user_id = $_GET['user_id'];
    $qry = mysqli_query("select * from sent_invitations where user_id='$user_id'");

    if (mysql_num_rows($qry) > 0)
    {
        while ($row = mysql_fetch_array($qry))
        {
           $mobile_number = $row['mobile_number'];

           $qry1 = mysql_query("select mobile_number from users where mobile_number = '$mobile_number'");
           $row1 = mysql_fetch_array($qry1);
           $mobile_number = $row1['mobile_number'];
           $users[] = array('mobile_number' => $mobile_number );
           return $users;
        }
    }
}

这篇关于带有codeigniter框架的php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 20:11