doudou8081 2012-02-07 02:38
浏览 40

带MySQL的PHP​​仅为Table的第一行返回正确的结果

I've recently gotten a PHP script i've written to return data back to my android java code, Unfortunately the script will only return data when I make a call to the first row of my table.

My Table is formatted as such:

1 Jared Jones
2 Karla Cross
3 Jasmine Smith
4 Vince Stevens

The numbers correspond to a UserId and the other 2 attributes are FName and LName.

My php script to execute the MySQL script is as follows:

    <?php 
mysql_connect("my database credentials go here");
mysql_select_db("a2275354_gtchose");
$sql=mysql_query("select FName,LName from Test where UserId ='".$_REQUEST['userId']."' ");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>

I'm unsure why the only time i receive a result is when i pass 1 as the userId to the query. Any ideas?

Thanks

  • 写回答

3条回答 默认 最新

  • duanbi1983 2012-02-07 02:41
    关注

    try removing the quotes around userId. Its a numeric field

    $sql=mysql_query("select FName,LName from Test where UserId =".$_REQUEST['userId']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题