通过php在html中显示来自mysql的数据

时间:2014-01-31 08:41:03

标签: php html mysql

// require('db.php');
mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error());
 mysql_select_db("alphaindia");
//SELECT Id, Name FROM coursetype where isDeleted=0
  $result = mysql_query("Call GetCourseTypes()");

  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("ID: %s  Name: %s", $row["Id"], $row["Name"]);


  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      //  printf("ID: %s  Name: %s", $row["Id"], $row["Name"]);

       echo  "<a href='UploadCourse/Step2.php?id=$row['Id']&name=$row['Name']'>$row['Id']</a>&nbsp;&nbsp;$row['Name']<br />";
   }

当我尝试运行上面的代码时,我得到一个空白页面。

请帮助我是php的新手

3 个答案:

答案 0 :(得分:0)

请尝试。

 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
   //  printf("ID: %s  Name: %s", $row["Id"], $row["Name"]);
   echo  "<a href='UploadCourse/Step2.php?id={$row['Id']}&name={$row['Name']}'>{$row['Id']}</a>{$row['Name']}<br />"; 
 }

答案 1 :(得分:0)

试试这个,连接问题在下面一行

 echo  "<a href='UploadCourse/Step2.php?id=".$row['Id']."&name=".$row['Name']."'>".$row['Id']."</a>&nbsp;&nbsp;".$row['Name']."<br />";

而不是

 echo  "<a href='UploadCourse/Step2.php?id=$row['Id']&name=$row['Name']'>$row['Id']</a>&nbsp;&nbsp;$row['Name']<br />";

答案 2 :(得分:0)

尝试这一点,而不用单引号“'”封装字段名称:

echo "<a href='UploadCourse/Step2.php?id=$row[Id]&name=$row[Name]'>$row[Id]</a>&nbsp;&nbsp;$row[Name]<br />";