unitedintruth Posted April 24, 2009 Share Posted April 24, 2009 I have a table in a mysql database for newsletters. The fields in the database are month, year, newsletter. The newsletters are in pdf format and in an /admin/newsletter folder on the server but the filename is in the database. How would I get a list showing the month, and year with a "Read" button linking to the newsletter? I am a little lost on how to write the table to get the thing to show so people can access the data. Thanks Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted April 24, 2009 Share Posted April 24, 2009 $sql = mysql_query("SELECT * FROM table_name WHERE Criteria");//if you just want to select every entry on the table, leave the WHERE part out. while ($row = mysql_fetch_assoc($sql)){//loop through the entries $month = $row['month'];//should be $row[month column name] $year = $row['year'];//should be $row[year column name] $link = $row['newsletter'];//should be $row[newsletter column name] echo "$month $year. <a href='$link'>Click here to view!</a>"; } Something like that should work. Just make sure to change this based on your table name, and your column names. You may also need to change the a href stuff based on if the filename is the absolute url, or just the local location. You may have to make it a href='my/folder/etc/$link' or something like that. Hope that helped Quote Link to comment Share on other sites More sharing options...
unitedintruth Posted April 24, 2009 Author Share Posted April 24, 2009 I have this added but it is not showing any data from the database. $sql = mysql_query("SELECT * FROM 'newsletter'");//if you just want to select every entry on the table, leave the WHERE part out. while ($row = mysql_fetch_assoc($sql)){//loop through the entries $month = $row['month'];//should be $row[month column name] $year = $row['year'];//should be $row[year column name] $link = $row['newsletter'];//should be $row[newsletter column name] echo "$month< >$year. <a href='admin/newsletter/$link'>Click here to view!</a>"; } Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted April 24, 2009 Share Posted April 24, 2009 I have this added but it is not showing any data from the database. $sql = mysql_query("SELECT * FROM 'newsletter'");//if you just want to select every entry on the table, leave the WHERE part out. while ($row = mysql_fetch_assoc($sql)){//loop through the entries $month = $row['month'];//should be $row[month column name] $year = $row['year'];//should be $row[year column name] $link = $row['newsletter'];//should be $row[newsletter column name] echo "$month< >$year. <a href='admin/newsletter/$link'>Click here to view!</a>"; } Well one thing comes to mind, take away the single quotes around newsletter also, for future reference, when you write queries do something like $query = mysql_query("STUFF") or die("ERROR ".mysql_error()); or something like that Quote Link to comment Share on other sites More sharing options...
unitedintruth Posted April 24, 2009 Author Share Posted April 24, 2009 Works perfectly, thank you very much for your help. I would be lost without you guys. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted April 24, 2009 Share Posted April 24, 2009 No Problem! by the way instead of using code tags you may be interested in using the php tags. it just looks prettier =) instead of writing {code} write {php}. (with normal brackets instead of curly brackets of course) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.