简体   繁体   English

来自 MYSQLI 查询的文本格式

[英]Text formatting from MYSQLI-query

I basically have been forced to learn SQL-programming from scratch to be able to complete a project I have been developing.我基本上被迫从头开始学习 SQL 编程,以便能够完成我一直在开发的项目。 With the help of the internet, and especially this site, I have been able to create a php-routine where I can choose data from my DB using drop downs.在互联网的帮助下,尤其是这个网站,我已经能够创建一个 php 例程,我可以使用下拉菜单从我的数据库中选择数据。 The results are then stored into a new table and what really bugs me is that I can`t wrap my head around how to display the results properly.然后将结果存储到一个新表中,真正让我烦恼的是我无法解决如何正确显示结果。 What I am asking is how can I easily format the table so that the text is alligned as looks better on the eye?我要问的是如何轻松地设置表格的格式,以便文本对齐看起来更好看?

I uploaded the file to this URL to show what my problem is: http://fantasysoccerpro.com/99.php我将文件上传到此 URL 以显示我的问题是什么: http : //fantasysoccerpro.com/99.php

I want all four categories: POSITION, PLAYER, SALARY and PROJECTION to be alligned under each other on each line.我希望所有四个类别:位置、球员、薪水和预测在每一行上相互对齐。

<?php
session_start();

$con = mysqli_connect("localhost",".....",".....",".....");
//or die ('unable to connect');

// Check connection
if (mysqli_connect_errno())
{
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

//SHOW TEAM//

$sql = "SELECT * FROM 1dzzdp";

mysqli_select_db($con,'.....');
$retval = mysqli_query( $con, $sql );
if(! $retval )
{
die('Could not get data: ' . mysqli_error($con));
}
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC))
{
echo "{$row['POSITION']}  ".
"{$row['PLAYER']}  ".
"{$row['SALARY']}  ".
"{$row['PROJECTION']}".
"{$row['SUM']} <br> ";

} 

The simple answer is to wrap all that in a HTML table简单的答案是将所有内容包装在一个 HTML 表格中

echo '<table>';
while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC))
{
    echo '<tr>';

    echo '<td>' . $row['POSITION'] . '</td>';
    echo '<td>' . $row['PLAYER'] . '</td>';
    echo '<td>' . $row['SALARY'] . '</td>';
    echo '<td>' . $row['PROJECTION'] . '</td>';
    echo '<td>' . $row['SUM'] . '</td>';

    echo '</tr>';
} 
echo '</table>';

Of course you may then need to do some formatting using some CSS.当然,您可能需要使用一些 CSS 进行一些格式化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM