hello,

i wanna know whats the best way to show query results from mysql onto a webpage..

some says this can only be done in form of table..
but nowadays table less design is preferred..tell me teh most demanding way if somebody knows..

Dani AI

Generated

Quick diagnosis for (and a clarifying note for ): the code stops working primarily because the old mysql_* fetch function is mixed with mysqli_* calls, and several boolean/string checks and unescaped inputs create logic and security problems. Semantically, use a <table> for true tabular data; use cards, lists or CSS Grid/Flexbox for record cards or responsive layouts — either is fine as said, but semantics and accessibility matter.

Immediate fixes and practical tips:

  • Replace mysql_fetch_array() with mysqli_fetch_assoc() (or use PDO). Always check the query result before looping.
  • Fix empty checks: use if (!empty($region[$i])) or if ($region[$i] !== '') — avoid if(!$region[$i] == "").
  • Never interpolate raw user input into SQL. Either use prepared statements or at minimum mysqli_real_escape_string() and whitelist any dynamic table/column names.
  • For distance math, prefer RADIANS() in SQL or deg2rad() in PHP; the hard-coded 0.01745 is imprecise. Consider the haversine formula or MySQL spatial functions for accuracy and performance.
  • Prevent XSS by wrapping output with htmlspecialchars() before echoing into HTML.

Short example patterns (replace column names as needed):

$result = mysqli_query($con, $s);
if (!$result) { error_log(mysqli_error($con)); echo "Query failed."; }
while ($row = mysqli_fetch_assoc($result)) {
    echo "<tr><td>" . htmlspecialchars($row['sno'], ENT_QUOTES, 'UTF-8') . "</td></tr>";
}

Or render as cards:

while ($row = mysqli_fetch_assoc($result)) {
  echo "<div class='card'><h3>" . htmlspecialchars($row['name']) . "</h3><p>"
       . htmlspecialchars($row['summary']) . "</p></div>";
}

Performance and safety: add LIMIT/pagination, index searchable columns, log DB errors (don’t show them to users), and validate/whitelist table names when they come from a form. These changes should make the query run and the output safe and presentable whether using tables or a tableless layout.

Recommended Answers

All 6 Replies

some says this can only be done in form of table.

It's all up to you, how it would best fit into your design. There is no one guaranteed best way to do this.

sir i have made design free so page load faster..tell me should i make it table less or with table and share code

should i make it table less or with table

That would be your decision. Either is just fine.

share code

Share code for what? Did you look at the code snippets in this forum?

ya i have seen but not found

i want to show results from mysql to a rtable on a web page..
how can i do this??

i have made thus code but it is not working

if($_POST["results"])
        {

             $db=$_POST["db"];

$skills = explode(",", $_POST["skills"]);
$table = explode(",", $_POST["table"]);
$city = explode(",", $_POST["city"]);
$region = explode(",", $_POST["region"]);
$country = explode(",", $_POST["country"]);

$latitude=$_POST["lat"];
$longitude=$_POST["long"];

$distance=$_POST["dist"];

$latitude*=0.01745;
$longitude*=0.01745;



$s="select sno from $table[0] where skills regexp \"$skills[0]\"";


for($i=1;$i<count($skills);$i++)
{
    $s.=" and skills regexp \"$skills[$i]\"";

    }
    $s.=" and deposit>=bid";

    for($i=0;$i<count($region);$i++)
if(!$region[$i]=="")
    {
    $s.=" and region regexp \"$region[$i]\"";

    }

    for($i=0;$i<count($city);$i++)
if(!$city[$i]=="")
    {
    $s.=" and city regexp \"$city[$i]\"";

    }


    for($i=0;$i<count($country);$i++)
if(!$country[$i]=="")
    {
    $s.=" and country regexp \"$country[$i]\"";

    }
    if(!$latitude=="")
    {

   $s.=" and acos(sin($latitude) * sin(Lati) + cos($latitude) * cos(Lati) * cos(Longi - ($longitude))) * 6371 <= $distance";
    }



    $con=mysqli_connect("localhost","root","cutiepie_100",$db);
    if (mysqli_connect_errno()) 
        {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//print_r($s);
$abc=mysqli_query($con, $s) or die('cannot show tables');
//print_r($s);
while ($row = mysql_fetch_array($abc))
{
   // print_r($s);
echo "<tr><td>{$row['sno']}</td></tr>"; 

}   
        }   
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.