如何获得" SELECT"显示数据库中的信息

时间:2017-01-29 02:47:22

标签: php sql

//试图拉出"用户名"从数据库到显示其他结果。 //在工作中显示用户名,但使用" SELECT"没有出现。

<?php

    require_once 'DBq/DBq.php';

    if(!$username = Input::get('user')) {
    Redirect::to('index.php');
     } else {
    $user = new User($username);
    if(!$user->exists()) {
       Redirect::to(404); 
    } else {
        $data = $user->data();
    }
    $qname = escape($user->data()->username);
?>

<p>First name: <?php echo escape($data->fname); ?></p>
<p>Last name: <?php echo escape($data->lname); ?></p>

<?php

//trying to display the results page user data. the "SELECT" is not working, but //not generating an error. IF i use just text "username = 'username';", then it //works.


    $sname = strval($qname);
    echo $sname. "</br>";
//$query = 'SELECT test_name, score, test_date_time FROM add_results WHERE       username = "` .$sname. `"';

    $result = mysql_query($query);


    if(!$result) die("Database access failed: ".mysql_error());
    $rows = mysql_num_rows($result);

    for ($j=0; $j<$rows; ++$j);{
    $row = mysql_fetch_row($result);

   for ($k=0; $k<$j; ++$k)
   echo "$row[$k]  ";

}

?>

0 个答案:

没有答案