douza19870617 2013-11-13 22:47
浏览 27
已采纳

选择Where not nothing result

I want to select one field value from a record where another value in the record matches my specified value.

The "SKU" is unique, it isn't the PK, but it is unique. I select only the one field (Code) from the table, so the variable $gemCode should only contain that 1 value. However on the echo, it either outputs nothing like the below code, or if I do specify the field "$gemCode['Code'] it just spurts "Resource id #8" which I've never seen before.

$gemCode = mysql_query("SELECT Code FROM stock WHERE SKU = 'TN-YKJI-ESWB'");

        echo "Gem Code: ".$gemCode."<br>";

This code is in a loop, for each line of a file which it'll be taking the SKU value from. Though even though the code has none of the loop in it (variables taken from the file etc) the output it does give, the "Resource id #8" number goes up each loop starting at 8:

Gem Code: Resource id #8
Gem Code: Resource id #9
Gem Code: Resource id #10
Gem Code: Resource id #11
Gem Code: Resource id #12
Gem Code: Resource id #13
Gem Code: Resource id #14
Gem Code: Resource id #15

I've had issues where before somehow data in my tables have spaces after them so "LIKE '%value%'" was needed, though I've checked and the values in question are don't have this, so its not like I'm looking from values that don't technically exist.

Should also mention I do have:

$conn = mysql_connect('localhost', 'root', '');         
mysql_select_db('amazondb', $conn);

I'm really stumped, I thought it'd just be a simple select where.

Any help is much appreciated, thanks -Tom

  • 写回答

3条回答 默认 最新

  • dongyao4419 2013-11-13 22:55
    关注

    You need to use mysql_fetch_assoc($gemCode) if you want to database result.

    $gemCode = mysql_query("SELECT Code FROM stock WHERE SKU = 'TN-YKJI-ESWB'");
    $gemArr = mysql_fetch_assoc($gemCode);
    
    print_r($gemArr);
    

    But, outsdie of "that's how you do it" you should really look into using mysqli_ instead of mysql. And if you're up to the challenge of learning PDO, you should try and use that (yes, even over mysqli_).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 processing提取音乐节奏
  • ¥15 python进程启动打包问题
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条