Forum Moderators: coopster
I'm just getting started with PHP, and i want to either:
have the information automatically inserted into my pre-made table via a php loop command
or
write a script which will allow me to only enter the id# and will subsequently insert the name and the date into my table, and which might display the image of the filename.
I hope this is clear enough, I've bought quite a large book on PHP and have been browsing forums in an attempt to learn, but i can't find an example that inserts it into a pre-existing table. I appreciate any help.
- nick
<?php
// Assuming that you've opened a db connection above
$qry = mysql_query("SELECT * FROM sometable ORDER BY ID");
?>
<table>
<tr><th>id</th><th>image name</th><th>file name</th><th>Date</th></tr>
<?php
while($dat = mysql_fetch_assoc($qry)) {
echo "<tr>\n";
echo '<td>' . $dat['ID'] . "</td>\n";
echo '<td>' . $dat['ImageName'] . "</td>\n";
echo '<td><a href="' . $dat['FileName'] . '">' . $dat['FileName'] . "</a></td>\n";
echo '<td>' . $dat['Date'] . "</td>\n";
echo "</tr>\n";
}// EndWhile getting data
mysql_free_result($qry);
?>
</table>
<?php while($dat = mysql_fetch_assoc($qry)) {?>
<tr>
<td><?php echo $dat['ID'];?></td>
</tr>
<?php }// EndWhile getting data?>
You may find that storing dates as timestamps (using BIG INT as data type) is a lot more versatile. The time() function is one of several that gives you this timestamp. You get it back into human readable form with the date() function.