doufei5315 2011-06-14 15:11
浏览 53

如何在php数组中存储从查询中检索到的值

i have retrieved a query and tried to store the id column in a array. and then i check two arrays to find the common using array_intersect func....

<?php

    $a=array(10);
    $connection = mysql_connect("localhost","root","");
    $db=mysql_select_db("data",$connection);
    $res=mysql_query("select * from usertable");
    $i=0;
    while($row=mysql_fetch_array($res))
    {
    $a[i]=$row["id"];
    $i++;
    }
    echo $a[1];
    $fb_usr_id =json_decode(  $_POST['fb_user'], true );
    $arr=array($fb_usr_id);


    $result = array_intersect($arr, $a);
    print_r($result);
    ?>

is the way in which i stored the retrieved value in array is correct...?? and output of this code is:

Array ( )

  • 写回答

2条回答 默认 最新

  • duanhui1185 2011-06-14 15:14
    关注

    I would do it this way

    <?php
    
        $a;
        $connection = mysql_connect("localhost","root","");
        $db=mysql_select_db("data",$connection);
        $res=mysql_query("select id from usertable");
        $i=0;
        while($row=mysql_fetch_array($res))
        {
        $a[]=$row["id"];    
        }
        echo $a[1];
        $fb_usr_id =json_decode(  $_POST['fb_user'], true );
        $arr=array($fb_usr_id);
    
    
        $result = array_intersect($arr, $a);
        print_r($result);
        ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析