I'm making a a side bar feed that will display the 10 most current things submitted into my database. I'm very new to all of this, so I am wondering.. is this an ok way of going about doing it? it works.. not automatically but when i submit something into my database, it goes there.. i submit something else and then the top goes to to the second..! i just cant shake the feeling that maybe this isnt a good way to do it.
the top 3 sections
<div class="span3 offset3">
<?php include 'feed/one.php'; ?>
<ul class="nav nav-list well">
<li class="nav-header"></li>
<li class="active"><a href="#">HIT INFO</a></li>
<?php while($row = $data->fetch_assoc()) { ?>
<li><a href="<?php print $row['link']?>"><?php
Print "<tr>";
Print "<th>Hit:</th> <td>".$row['hit'] . "</td> ";
Print "<th>Amount:</th> <td>".$row['amount'] . " </td>";
Print "<th>Category:</th> <td>".$row['category'] . "</td></tr> ";
Print "<br><br/>";
Print "</table>";?></a></li>
<?php } ?>
<li class="divider"></li>
<?php $data = $mysqli->query("SELECT * FROM hit ORDER BY hit_id DESC LIMIT 1, 1"); ?>
<?php while($row = $data->fetch_assoc()) { ?>
<li><a href="<?php print $row['link']?>"><?php
Print "<tr>";
Print "<th>Hit:</th> <td>".$row['hit'] . "</td> ";
Print "<th>Amount:</th> <td>".$row['amount'] . " </td>";
Print "<th>Category:</th> <td>".$row['category'] . "</td></tr> ";
Print "<br><br/>";
Print "</table>";?></a></li>
<?php } ?>
<li class="divider"></li>
<?php $data = $mysqli->query("SELECT * FROM hit ORDER BY hit_id DESC LIMIT 2, 1"); ?>
<?php while($row = $data->fetch_assoc()) { ?>
<li><a href="<?php print $row['link']?>"><?php
Print "<tr>";
Print "<th>Hit:</th> <td>".$row['hit'] . "</td> ";
Print "<th>Amount:</th> <td>".$row['amount'] . " </td>";
Print "<th>Category:</th> <td>".$row['category'] . "</td></tr> ";
Print "<br><br/>";
Print "</table>";?></a></li>
<?php } ?>
<li class="divider"></li>
<?php $data = $mysqli->query("SELECT * FROM hit ORDER BY hit_id DESC LIMIT 3, 1"); ?>
<?php while($row = $data->fetch_assoc()) { ?>
<li><a href="<?php print $row['link']?>"><?php
Print "<tr>";
Print "<th>Hit:</th> <td>".$row['hit'] . "</td> ";
Print "<th>Amount:</th> <td>".$row['amount'] . " </td>";
Print "<th>Category:</th> <td>".$row['category'] . "</td></tr> ";
Print "<br><br/>";
Print "</table>"; ?></a></li>
<?php } ?>
the data that gets submitted gets displayed on my main page until something else gets submitted, goes to the "feed", and also goes to another page that shows the past data.
You don't appear to have anything the user can intercept, so "safe" is a non issue.
You are querying illogically though. There's no reason to repeat the same query with multiple offsets all over the page when you can just fetch the data initially and use that object to relay the content where needed. Run a query like this at the beginning of the file, or ideally before any output is rendered.
"SELECT * FROM hit ORDER BY hit_id DESC LIMIT 4"
Now you have 4 items, so accessing those throughout the page could be something like this:
<ul class="nav nav-list well">
<li class="nav-header"></li>
<li class="active"><a href="#">HIT INFO</a></li>
<?php while($row = $data->fetch_assoc()): ?>
<li>
<a href="<?php print $row['link']?>">
<table>
<tr>
<th>Hit:</th> <td><?php echo $row['hit']; ?></td>
<th>Amount:</th> <td><?php echo $row['amount']; ?></td>
<th>Category:</th> <td><?php echo $row['category']; ?></td>
</tr>
<br><br/>
</table>
</a>
</li>
<li class="divider"></li>
<?php endwhile; ?>
</ul>
Now, you have a few markup errors there. You close a table you never open. This can only in a small way be considered tabular data, so tables are probably not the best way to do this anyhow. I myself don't understand your use of th and td in this way, but if it works for you then good.
You should break out of php to display html. echoing something like "<th>"
is totally unnecessary.