Jump to content

Recommended Posts

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

$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

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<&nbsp>$year. <a href='admin/newsletter/$link'>Click here to view!</a>";
}

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<&nbsp>$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

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.