0

This is my code (horrible one):

<?php

include 'connect/con.php';

$result = mysqli_query($con,"SELECT id, vidTitle FROM newsvid");
$result1 = mysqli_query($con,"SELECT imgCover, vidSD FROM newsvid");
$result2 = mysqli_query($con,"SELECT published FROM newsvid");




echo "<table width=\"600\" border=\"1\"><tbody>";
while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  echo '<td width=\"10%\"><a href="details.php?id='.$row['id'].'">'.$row['id'].'</a></td>';
  echo "<td width=\"90%\">" . $row['vidTitle'] . "</td>";
  echo "</tr>";
}
echo "</tbody></table>";


echo "<table width=\"600\" border=\"1\"><tbody>";
while($row = mysqli_fetch_array($result1)) {
  echo "<tr>";
  echo "<td width=\"40%\">" . $row['imgCover'] . "</td>";
  echo "<td width=\"60%\">" . $row['vidSD'] . "</td>";
  echo "</tr>";
}
echo "</tbody></table>";




echo "<table width=\"600\" border=\"1\"><tbody>";
while($row = mysqli_fetch_array($result2)) {
  echo "<tr>";
  echo "<td >" . $row['published'] . "</td>";
  echo "</tr>";
}
echo "</tbody></table>";



mysqli_close($con);
?>



</body>
</html>

The question is how to show data from database in this layout:

--------------------------------
-id----------vidTitle-----------
--------------------------------
-imgCover------vidSD------------
--------------------------------
----------published-------------

So every time I will add more data , another block like I showed before will add up under existing one. ........................................................................................

1 Answer 1

1

There's no need to write 3 queries. You could do that with only one select, and then put all the echos inside a while. That way you're writing, it would run all the ids and titles first, then it would put a table after the table, with cover and vidSD.

Try to make a single query:

SELECT id, vidTitle, imgCover, vidSD, published FROM newsvid

That way you will have, on each row returned from database, all the information about the same row.

Now, running a while is the same as you're doing, just adapting some HTML:

echo "<table width='600' border='1'><tbody>";
while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  echo '<td width=\"10%\"><a href="details.php?id='.$row['id'].'">'.$row['id'].'</a></td>';
  echo "<td width=\"90%\">" . $row['vidTitle'] . "</td>";
  echo "</tr>";
  echo "<tr>";
  echo "<td width=\"40%\">" . $row['imgCover'] . "</td>";
  echo "<td width=\"60%\">" . $row['vidSD'] . "</td>";
  echo "</tr>";
  echo "<tr>";
  echo "<td colspan='2'>" . $row['published'] . "</td>";
  echo "</tr>";
}
echo "</tbody></table>";

You may want to order it too. Adding ORDER BY id DESC, would do that.

Sign up to request clarification or add additional context in comments.

2 Comments

EVERYTHING is looks cool BUT the main problem that in the table width 10% and in another TR where td 40% will not work(((
All table will looks like 50% by 50% and if you change is to 10% by 90% nothing changes they are still the same..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.