我有一个welcome.php文件,我需要从mysql数据库中获取记录到页面上的html表格。
它正在提取记录,但在每个列字段后放置一个空白字段。例如如果有6列。然后它显示12个字段。每个字段后有6个实际字段和一个空白字段。所以,html表格结构enter code here也打扰了。
我已经使用mysqli_fetch_array并放置一个while循环来获取20条记录。我不知道我在取记录时出错或者在html表本身存在问题。请找到下面的代码,并让我知道我在做什么错误。 谢谢。html表取额外的空白值,同时从php中取出行使用php
//start a session
session_start();
?>
nav ul{
margin:0;padding:0;
}
table,th,td{
border: 1px solid black;
border-collapse:collapse;
text-align:left;
table-layout:auto;
}
nav ul li{
display:list-item;float:left;margin:5px;
}
a:link {color:#000000; background-color:transparent; text-decoration:underline}
a:visited {color:#000000; background-color:transparent; text-decoration:none}
a:hover {color:#ff0000; background-color:transparent; text-decoration:underline}
a:active {color:#ff0000; background-color:transparent; text-decoration:underline}
//Define variables
$company=$ModelName=$ModelNo=$productcolor=$cost=$sql1=$sql2=$IMEI=$accessories=$row="";
?>
//Check the request method and take the value in all variables
if ($_SERVER["REQUEST_METHOD"]=="POST"){
$company=$_POST['Company'];
$ModelName = $_POST['ModelName'];
$ModelNo = $_POST['ModelNo'];
$productcolor = $_POST['productcolor'];
$cost =$_POST['cost'];
$IMEI=$_POST['imei'];
$accessories=$_POST['accessories'];
}
// Connect to database and get the no of rows in $num
$con = mysqli_connect("MyWebsite.localdomain","root","pwd123","test_youtube");
$sql1 = "select M_ID,CompanyName,ModelName,ModelNo,IMEI,productcolor,cost,accessories,dt from mobile_data LIMIT 20";
//check connection
if(!$con){
echo "Failed to connect to MySQL: " . mysql_error();
}
$retval1 = mysqli_query($con,$sql1);
echo "
M_ID | Company | Model Name | Model No | IMEI | Color | Cost | Accessories | Date |
---|
//Show all records on the home page
//echo count(mysqli_fetch_array($retval1));
while($row= mysqli_fetch_array($retval1)){
echo "
".$row["M_ID"]."".$row["CompanyName"]."".$row["ModelName"]."".$row["ModelNo"]."".$row["IMEI"]."".$row["productcolor"]."".$row["cost"]."".$row["accessories"]."".$row["dt"]."";}
echo "
";// Perform the insert operation on the table when hit the submit button
if(isset($_POST['submit'])){
//$con = mysqli_connect("MyWebsite.localdomain","root","shekhar123","test_youtube");
//perform insert queries to enter the data when submit button is clicked
$sql2 = "insert into mobile_data".
"(M_ID,CompanyName,ModelName,ModelNo,IMEI,productcolor,cost,accessories)".
"VALUES".
"('$num','$company','$ModelName','$ModelNo','$IMEI','$productcolor','$cost','$accessories')";
$retval2 = mysqli_query($con,$sql2);
//if(!$retval2){
// die('Could not enter data: ' . mysql_error());
//}
}
mysqli_close($con);
?>
;
2014-11-21
Shekhar
+0
你不关闭你的行/细胞,你刚开始一个新的行/单元格 - >'echo“
”。$ row [“M_ID”]。“... [your code] ...”。$ row [“dt”]。“
“;'例如最后一个'
'应该是''。这是一个HTML问题,而不是PHP问题 –
2014-11-21 04:46:55
+0
@Shekhar,如果你从我的答案得到解决方案,请接受我的回答 –
2014-11-21 04:59:47