Php 查询数据并在html表中显示

Php 查询数据并在html表中显示,php,mysql,Php,Mysql,我喜欢将链接放入html表中,这些链接是从mysql表查询的 ------------------------------ item Number | Item purchased ------------------------------ 1 | a vase 2 | a candle etc..... 10 ------------------------------ <<1,2,...100|next>

我喜欢将链接放入html表中,这些链接是从mysql表查询的

------------------------------
item Number |  Item purchased
------------------------------
1           |  a vase
2           |  a candle

etc.....
10
------------------------------
           <<1,2,...100|next>>
------------------------------
项目编号|购买的项目
------------------------------
1 |花瓶
2 |蜡烛
等
10
------------------------------
这对我来说很难。有人能给我一个想法或图书馆让我开始吗?
非常感谢您

如果这对您来说太难了,我建议您使用CMS,直到您的脚湿了为止。外面有很多,举几个例子

如果你像AlientWebguy建议的那样使用CMS,你永远也学不会。。。我想你是来学习的。你应该从一个教程开始,因为这是非常基本的东西

但要完成你想做的事情——如果我是新手——我会这么做。我不会给你你的代码,但它绝对是足够接近,你应该能够找出它

我将创建一个名为functions.php的文件,其中包括以下内容:

<?PHP
// these are freebies.  You don't need to understand them yet.
function sqlarr($sql, $numass=MYSQL_BOTH) {
    // MYSQL_NUM  MYSQL_ASSOC  MYSQL_BOTH
    $got = array();
    $result=mysql_query($sql) or die("$sql: " . mysql_error());                             

    if(mysql_num_rows($result) == 0)
        return $got;
    mysql_data_seek($result, 0);
    while ($row = mysql_fetch_array($result, $numass)) {
        array_push($got, $row);
    }
    return $got;
} 

// Sql fetch assoc
function sqlassoc($sql){
    $query = mysql_query($sql) or die("$sql:". mysql_error());
    $row = mysql_fetch_assoc($query);
    return $row;
}

function sqlrow($sql){
    $query = mysql_query($sql) or die("$sql:". mysql_error());
    $row = mysql_fetch_row($query);
    return $row;
}

function sqlquery($sql){
    $query = mysql_query($sql) or die("$sql:". mysql_error());
    return $row;
}

?>
    <?PHP  include('./functions.php'); 
    // It sounds like you are already connected to your database, so I'm going to skip that.  If you need it, add a comment.
    $sql = "SELECT `colNames`, `colName2` FROm `tableName` WHERE `col` = 'condition' ";
    // obviously change this to your names, such as `itemNumber`
    $results = sqlarr( $sql ); // Now results is going to automatically contain a 2D array.  
    echo '<pre>'; print_r( $results ); echo '</pre>';
    /* this is just to show you what is happening so far.  You should get in the habit of using things like this to debug.  A lot of people prefer var_dump instead of print_r.  I use both because var_dump is harder to read.
    // Result should be returning something like this:
    // array(
            [0] => array(
                    [0] => 'ABC123',
                    ["itemNumber"] => 'ABC123',
                    [1] => 'http://www.abc.com',
                    ["link"] => 'http://www.abc.com' ),
            [1] => array( ... )
            )
    // the first level - the [0] => array(  or the [1] => array( part - corresponds to a row in your database
    // so now we need a way to filter through those rows.  Look up php.net/for or php.net/foreach to see how to accomplish that.  A lot of people use php.net/while too, but I don't prefer that personally. */
    ?>
    <html>
    <body>
    <table>
    <?PHP
    foreach( $results as $row ){  // this is turning $result[0] => array(  into $row.  So now we can access $result[0]['linkName'] as $row['linkName']
       echo '<tr><td>'.$row['linkName'].'</td></tr>';
    }  // foreach $row - dont forget to close your curly bracket.  Good practice is to always close it as soon as you open it, and to put a comment after it like I just did letting you know what it goes to
    ?>
    </table>
    </body>
    </html>

欢迎来到堆栈溢出。如果一个答案对你有帮助,请投票表决。如果某个特定答案解决了您的问题,请单击旁边的小复选标记接受它。这给了我们声誉。捞取选票会让你看起来很傻。而且,很有可能,OP不知道如何处理你的意大利面代码。@AlienWebguy我只会“钓到”某人的处女博客,更多的是为了让他们加入社区,然后专门投票给我。我很快就学会了不在乎声誉,正如有17.9k声誉的人所说,他们往往会因为最愚蠢的事情而投票否决你。至少我在试图帮助他回答问题。谢谢,我只能接受答案。我不能投赞成票[我的声誉只有1]如果我想投你反对票,我早就投了——不用担心:)