$con = mysql_connect(HOST_NAME,USER_NAME,PASSWORD);$sql = "SELECT * FROM users WHERE userid='$userId'";
$res = mysql_query($sql,$con);
$row = mysql_fetch_array($res);
if (is_array($row)){
$userName = $row["username"];
}
mysql_free_result($res);
echo $userName;

解决方案 »

  1.   

    <?php
    $mylink=mysql_connect("localhost","root","1234");
    $sql="SELECT id,name from 表名";
    $result_output=mysql_query($sql,$mylink);
    if(mysql_num_rows($result_output)>0){
    ?>
    <table width="75%" border="1">
    <?php
       while($array_yh=mysql_fetch_array($result_output)){
    ?>
          <tr> 
    <td><?php echo $array_yh['id'];?></td>
    <td><?php echo $array_yh['name'];?></td>
          </tr>
    <?php
      }
    ?>
    </table>
    <?php
    }
    ?>
      

  2.   

    $sql="select A_TITLE from 表名";//写查询语句
    $result = mysql_query($sql,$con);//送入数据库查询
    for ($i=0; $i<count($array); $i++){//开始循环
      $array = mysql_fetch_array($result);//读出数据
      echo "$array[A_TITLE]";//显示
    }//循环结束
      

  3.   

    首先连接好数据库$str="select A_TITLE from A";                
    $query = mysql_query($str);
    $count = myswl_num_rows($query);
    if($count > 0){
       while($title_array=mysql_fetch_array){
           echo $title_array[A_TITLE];
      }
    }else{
       echo "没有找到任何信息";
    }
      

  4.   

    <?php
    $mylink=mysql_connect("localhost","root","1234");
    $sql="SELECT id,name from 表名";
    $result_output=mysql_query($sql,$mylink);
    if(mysql_num_rows($result_output)>0){
    ?>
    <table width="75%" border="1">
    <?php
       while($array_yh=mysql_fetch_array($result_output)){
    ?>
          <tr> 
    <td><?php echo $array_yh['id'];?></td>
    <td><?php echo $array_yh['name'];?></td>
          </tr>
    <?php
      }
    ?>
    </table>
    <?php
    }
    ?>
      

  5.   

    <?
    //连接到本地MYSQL数据库
    $myconn=mysql_connect("localhost","root","");
    //选择数据库,$myconn为活动连接
    mysql_select_db("database_name",$myconn);
    //用SQL从table_name表中查询
    $strSql="select count(*) as count from table_name";
    //用mysql_query从表中读出数据
    $result=mysql_query($strSql,$myconn);while($row=mysql_fetch_array($result))
    {
    ?>
    <tr>
    <td align="center"><? echo $row["A_TITLE"]?></td>
    </tr>
      

  6.   

    <?

    //关闭对数据库的连接
    mysql_close($myconn);
    ?>//接上页
      

  7.   

    在显示记录的时候,加个循环,在需要分行的时候,再来个</tr>.
      

  8.   

    $query = "select * from table where .....";
    $rs = mysql_query($query,$connectionHandle) or die "error info ";
    while($row = mysql_fetch_array($rs))
    {
        .......$row["字段"]
    }