Jump to content

Display data in table without html?


SEVIZ

Recommended Posts

Is there a way to display a queries data in a table without using html?  Like some kind of php?

 

Here is my code:

<?php
$con = mysql_connect("--------","---------","----------");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("sevizcom-1", $con);

$id=$_POST['id'];
$result = mysql_query("SELECT * FROM sprint WHERE id LIKE '%$id%'");

while($row = mysql_fetch_array($result))
  {
  echo $row['id'] . " " . $row['name'] . " " . $row['num'] . " " . $row['sup'];
  }

?>
<br /><br />
<form action="techdbid.php" method="post">
Tech: <input type="text" name="id"><br />
<input type="Submit">
</form>

 

Right now the data is just one long string of the data.  How can I break it all up into a table with cells?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/157752-display-data-in-table-without-html/
Share on other sites

grab the data = the mysql_query() function

 

sort the data = include "ORDER BY 'some_field'" in your query

 

then there are numerous ways to use the returned resource and output a table, but there isn't anything automatic.

 

joke >> maybe in php7 they will implement a new hocus_pocus() function!

Why not build your table by modifying what you already have:

 

This is what you have:

while($row = mysql_fetch_array($result))
  {
  echo $row['id'] . " " . $row['name'] . " " . $row['num'] . " " . $row['sup'];
  }

 

and you could be doing this:

echo "<table>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>
               <td>" .$row['id'] . "</td>
               <td>" . $row['name'] . "</td>
               <td>" . $row['num'] . "</td>
               <td>" . $row['sup'] . "</td>
          </tr>";
  }
echo "</table>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.