Read one column from one row from a MySQL database

前端 未结 8 1923
没有蜡笔的小新
没有蜡笔的小新 2021-01-15 03:30

Is there a quick and dirty way to get the value of one column from one row? Right now I use something like this:

$result = mysql_query(\"SELECT value FROM ta         


        
相关标签:
8条回答
  • 2021-01-15 04:06

    Do u want this?

    $output = array();
    while($row = mysql_fetch_array($result)){
        $output[] = $row['value'];
    }
    return $output;
    
    0 讨论(0)
  • 2021-01-15 04:08

    use this hacker)

    $result = mysql_result(mysql_query("SELECT value FROM table WHERE row_id='1'"), 0);
    
    0 讨论(0)
  • 2021-01-15 04:12

    if you want it to return only one value use the limit keyword

    /* Limits Results to 1 */
    $result = mysql_query("SELECT value FROM table WHERE row_id='1' LIMIT 1;");
    $row = mysqli_fetch_assoc($result)
    echo $row['value'];
    
    0 讨论(0)
  • 2021-01-15 04:14

    use this:

    $result = mysql_query("SELECT value FROM table WHERE row_id='1'");
    return mysql_result($result, 0);
    
    0 讨论(0)
  • 2021-01-15 04:15

    You can use GROUP_CONCAT ( http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat ) function to make them into one field.

    0 讨论(0)
  • 2021-01-15 04:15

    What you should look for is an encapsulation mecanism. For example you could create a classe User that would correspond to a rows of SQL table "user". Then you could get his id just with a single line:

    $user->getID();
    

    You could also create a class that would aggregate all the user and then use something like this:

    $collection->getUserID("3435563");
    

    But really there isn't a simpler way to do it in my knowledge.

    0 讨论(0)
提交回复
热议问题