php mysql 单条记录显示 [英] php mysql single record show

查看:45
本文介绍了php mysql 单条记录显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉这个愚蠢的问题,但我看不到/不够好,无法解决这个问题:

Sorry about the stupid question however I can't see/ not good enough to solve this:

我有一个 MYSQL db 和一个 php 表单,一切正常,但我不能只取出一条记录 - 可能是语法错误:

I have a MYSQL db and a php form everything works but I can't get out only one record - probably syntax error:

    $SQL = "SELECT * FROM massfelh WHERE user = $uname AND pass = md5($pword)"; - this is working
    $result = mysql_query($SQL); - this is too
    $catg = $result['categ']; - help
    $num_rows = mysql_num_rows($result); - this is ok too
    echo $catg; - for test and I can't print it on screen

数据库结构:id、user、pass、categ

DB structure: id, user, pass, categ

我只需要类别(1 或 0)但它不会显示在屏幕上.

I only need the categ (either 1 or 0) but it just won't show on screen.

任何帮助将不胜感激 - 请说我也很愚蠢:)

Any help would be appreciated - and please say I am stupid too:)

更新:

谢谢大家!!!!!!帮了我很多.我为我的代码找到了最好的解决方案,但是所有的回复都是正确的.再次感谢 hop 这将有助于一些和我一样初学者的人:) 再次感谢你

thank you for everyone of you!!!!!!! Helped me a lot. I have fount the best solution for my code however all the reply was correct. Thanks again hop this will help to some one how is just as beginner as me:) thank you again

推荐答案

试试这个..

$SQL = "SELECT * FROM massfelh WHERE user = $uname AND pass = md5($pword)"; 
    $result = mysql_query($SQL);
    $result = mysql_fetch_assoc($result);
    $catg = $result['categ'];
    $num_rows = mysql_num_rows($result); 
    echo $catg;

这篇关于php mysql 单条记录显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆