为什么不显示名字?

时间:2013-10-03 08:19:45

标签: php

这个网站应该在方框中显示人名,但它们不在那里。

链接到网站:http://dorkhub.tdoyle.tk/

这是代码:     

$query1 = mysqli_query($aVar, "SELECT name FROM users
    ORDER BY RAND()");
$aName1 = mysqli_fetch_row($query1);
$name1 = $aName1['name'];

$query2 = mysqli_query($aVar, "SELECT name FROM users
    ORDER BY RAND()");
$aName2 = mysqli_fetch_assoc($query2);
$name2 = $aName2['name'];

?>

<title>DorkHub. The online name-rating website.</title>
<link rel="stylesheet" type="text/css" href="style.css">
<body bgcolor='EAEAEA'>
<center>
<div id='TITLE'>
    <h2>DorkHub. The online name-rating website.</h2>
</div>
    <p>
    <br>
    <h3><?php echo $name1; ?></h3><h4> against </h4><h3><?php echo $name2; ?></h3>
    <br><br>
    <h2 style='font-family:Arial, Helvetica, sans-serif;'>Who's sounds the dorkiest?</h2>
    <br><br>
    <div id='vote'>
    <h3 id='done' style='margin-right: 10px'>VOTE FOR FIRST</h3><h3 id='done'>VOTE FOR LAST</h3>

2 个答案:

答案 0 :(得分:0)

您使用了错误的字段名称

变化:

$name1 = $aName1['name1'];

$name1 = $aName1['name'];

第二,

更改

$name1 = $aName2['name2'];

$name2 = $aName2['name'];

另外,改变

 <h3><?php echo $aName2['name2'];; ?></h3><h4> against </h4><h3><?php echo $aName1['name1'];; ?></h3>

<h3><?php echo $aName2['name']; ?></h3><h4> against </h4><h3><?php echo $aName1['name']; ?></h3>

再次

更改

$aName2 = mysqli_fetch_assoc($query1);

$aName2 = mysqli_fetch_assoc($query2);

希望这适合你。

答案 1 :(得分:0)

在您的查询中,您有名称,将其替换为name1,反之亦然,因为它在您的数据库中:

$aName2 = mysqli_fetch_assoc($query1);

$aName3 = mysqli_fetch_assoc($query2);

您还应该将$aName2更改为$ aName3,否则您必须使$aName2成为数组并使用foreach loop

来访问值