Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
Vchat20
Hangin' Around



Joined: Nov 27, 2004
Posts: 31

PostPosted: Tue Oct 11, 2005 2:24 pm Reply with quote

ok. im getting annoyed. im creating a custom block here to show some now playing info on my site. whats different from others is that im storing this info in the database rather than grabbng it from the shoutcast server itself. ive got the code to keep the info in the database up to date. that was simple. but im having trouble with the block. heres my current code:

Code:
<?php

$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
if (eregi("block-Now_Playing.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();

global $db;
$row = $db->sql_fetchrow($db->sql_query("SELECT * FROM ksim_nowplaying"));
$string1 = $row['nowplaying'];

if (preg_match("/Offline/i", $string1)) {
$np_img = "offline";
} elseif (preg_match("/This Week in Tech/i", $string1)) {
$np_img = "twit";
} elseif (preg_match("/The No Budget Show/i", $string1)) {
$np_img = "tnbs";
} elseif (preg_match("/The Country Kitchen/i", $string1)) {
$np_img = "tkc";
} else {
$np_img = "autodj"; }
//End Code

$content = "<img src=\"images/np/" . $np_img . ".png\">";
$content = $string1;
?>


but it keeps telling me there is an "unexpected $" on the last line where '?>' is located. any ideas?
 
View user's profile Send private message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Tue Oct 11, 2005 8:00 pm Reply with quote

Befor we go on, these 2 lines don't make sense. The last one overlays the first.
Code:
$content = "<img src=\"images/np/" . $np_img . ".png\">";

$content = $string1;
 
View user's profile Send private message
Vchat20







PostPosted: Tue Oct 11, 2005 8:32 pm Reply with quote

nvm. figured it out. was missing a closing bracket after the intial few essential block lines. and the second $content line was there just for debugging purposes. its no longer there now.
 
Raven







PostPosted: Tue Oct 11, 2005 8:41 pm Reply with quote

Yep. Right after the die(); Smile
 
Vchat20







PostPosted: Tue Oct 11, 2005 8:55 pm Reply with quote

just a quick question before im done with this thread: does the mysql code look ok and "correct"? just curious because it was a quick edit from another block and im also planning on using it in other areas on my site like in a few modules and whatnot.
 
Raven







PostPosted: Tue Oct 11, 2005 10:20 pm Reply with quote

Your code looks fine although technically speaking you should try to use stristr instead of preg_match for speed and efficiency [ Only registered users can see links on this board! Get registered or login! ] . However, your result set is probably so small that it's not an issue Wink
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©