Jump to content

Recommended Posts

I have a database that displays upcoming events and news stories.  I'm trying to put an if statement in the database (text column) to only display events for a carnival that are happening today or later...not yesterday.

 

Here's the code:

 

eval('<?' . if (date('Y-m-d') <= '2010-06-30') 
{echo "<strong>Wednesday, June 30th</strong><br /><strong>5pm - 11pm</strong> Bingo Tent<br /><strong>5pm - 1am</strong> Entertainment Tent<br /><strong>6pm - midnight</strong> Mirriam's Midway (armband specials 6-11)<br /><strong>7p - 9p</strong> Bar Olympics<br /><strong>9p - 1a</strong> Live music with country band Heros and Thieves<br /><br />";} else { echo ""; }

if (date('Y-m-d') <= '2010-07-01') {echo "<strong>Thursday, July 1st</strong><br /><strong>noon - 11pm</strong> Bingo Tent<br /><strong>noon - midnight</strong> Mirriam's Midway (armband specials 6-11)<br /><strong>5pm - 1am</strong> Entertainment Tent<br /><strong>9p - 1a</strong> Live music with Shirts and Skins<br /><br />";} else { echo ""; } . '?>');

 

That is also echoing the...

 

";} else { echo ""; }if (date('Y-m-d') <= '2010-07-01') {echo "Thursday, July 1st

 

part of the code.  How do I add an if statement to the database the right way?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/205643-eval-php-code-in-mysql-databse/
Share on other sites

If it makes it easier, I have the working if statement on a separate page.  I can include the other file if need be.

 

I tried 

 

<table><tr><td><img src="/shared/images/watercarnival.jpg" alt="fireworks" />
<br />The Jaycees are holding their 66th annual Water Carnival.<br /><br />
To get the Medallion Hunt clues sent to your cell phone each day, text the work HUNT to xxxx. <br /><br /> 
<?php eval("include '/home/public_html/evaltest.php';"); ?>
</td></tr></table>

 

but it didn't include the file.

I got it...I was reading that the eval went into the test of the database.  Once I figured out that "regular" php code went into the database...and you eval the output...I got it figured out.

 

Moral of the story...read things twice before starting to write the code!

I did...like I said, once I realized that the eval code went on the page to print the database info...and not INSIDE the database...I got it working.

 

<?php 
define('COMP_NAME', 'Mix 103.7');
$link = mysql_connect('localhost', 'xxxx', 'xxxx');
mysql_select_db('xxxx',$link);
$sql = "SELECT * FROM content WHERE NOW() BETWEEN startdate AND enddate AND (station = 'mix' OR station = 'all') ORDER by RAND()";
$rs = mysql_query($sql,$link);  
$matches = 0; 
while ($row = mysql_fetch_assoc($rs))  {
$matches++; 
echo "<tr><td><span class='itemheading2'>".str_replace('COMPANYNAMEHERE',COMP_NAME,stripslashes($row[headline]))."</span>";
echo "<span class='itemdetails2'><br /><br />";

$code = str_replace('COMPANYNAMEHERE',COMP_NAME,stripslashes($row[story]));

eval('?>' . $code . '<?');  ///////// the above two lines were changed to make the old code execute the new database record that includes php scripting in the db

echo "<br /><br /></span></td></tr>";

}  
if (! $matches) { 
echo (""); 
}  
echo "";  
?> 

 

The only php code inside the database is a php include

OK...here's the full story.  I work for a group of radio stations (4 of them).  Company events need to be placed on ALL 4 websites.  Station specific contests and such only go on 1 website.

 

I have the database set up like this:  station (varchar) | startdate (datetime) | enddate (datetime)| headline (varchar) | story (longtext)

 

The particular content that caused me to post today was a list of events for a 4th of July carnival.  I wanted the list to only print events for today and in the future (several if statements...one for each day).

 

Since the content of all four sites comes from one database...and I need dynamic content from that one database...how else can I do this?

OK...here's the full story.  I work for a group of radio stations (4 of them).  Company events need to be placed on ALL 4 websites.  Station specific contests and such only go on 1 website.

 

I have the database set up like this:  station (varchar) | startdate (datetime) | enddate (datetime)| headline (varchar) | story (longtext)

 

The particular content that caused me to post today was a list of events for a 4th of July carnival.  I wanted the list to only print events for today and in the future (several if statements...one for each day).

 

Since the content of all four sites comes from one database...and I need dynamic content from that one database...how else can I do this?

 

Just pull the content from the db?  I mean, it looks like you're storing whole PHP files in the db, which I doubt is necessary.  A 'story' implies text, which should be all you're storing.  If you do need to dynamically access a PHP file, simply store its path in the db and use include to access it.

 

Again, eval is hardly ever necessary.

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.