Use PHP to Display MySQL Results in HTML Table

前端 未结 3 1839
滥情空心
滥情空心 2020-12-09 07:13

Update for CodingBiz:

I\'m putting this in my code:

for($i=1;$i<=$numRows;$i++) {
    $output .= \'\';
    $row = $this         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 07:54

    1. Never mix your database handling code with HTML output code. These are 2 totally different matters. Make your allResults function only return array with data, and then you can make another function to print in fancy way (and not in the database handler class).
    2. You don't need information schema to get column name - you already have it in the returned array keys.
    3. You don't need numRows either - use while() and foreach()
    4. NEVER insert anything into query directly like you do with $cols - eventually it will lead to errors and injections.
    5. Such a function, without accepting some parameters for the query, makes absolutely no sense especially in the context of migrating from mysql to mysqli - you are going yo use it as an old school mysql query inserting variables, not placeholders. So, it makes migration totally useless.
    6. To know "Is there anything wrong with code", one have to run it, not watch. Run and debug your code, outputting key variables and making sure you can see errors occurred.

提交回复
热议问题