当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Query to find member name and score

问题描述:

I have two tables one for members having fields as id , name

Second table as results with fields as rid , mid (member id foreign key), pid , score

I need to show name of member and their score where pid=$id

My query is :

$sel = mysql_query("SELECT m.name,r.score FROM member m, score r WHERE m.id=r.mid and r.pid='$id'");

<?php $i=0; while( $sql = mysql_fetch_assoc( $sel )) { ?>

<tr>

<td align="center"><?php $i++; echo $i; ?> </td>

<td align="center"><?php echo ucfirst( $sql['name'] ); ?></td>

<td align="center"><?php echo $sql['score']; ?></td>

</tr>

<?php } ?>

But no records are getting output.

There are matching records but it is not entering in while loop.

网友答案:

Use as:

$sel = mysql_query("SELECT m.name as name, r.score as score FROM member m, score r WHERE m.id=r.mid and r.pid='$id'");

Or so, if you do not want to use as:

<?php echo ucfirst( $sql['m.name'] ); ?>

分享给朋友:
您可能感兴趣的文章:
随机阅读: