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
rogue3
Regular
Regular



Joined: Jul 02, 2009
Posts: 71

PostPosted: Wed Sep 15, 2010 1:45 pm Reply with quote

I'm trying to create a block that pulls from my nuke database, but I want to embed that block in my html code (not used with the nuke blocks section). I think I'm pretty close, and had the block working in the admin area before I switched over to the 'standalone' attempt, but I'm having trouble figuring out how $db is defined. That is where the script is crashing. $db is usually globally defined so I need to define it locally for this script. Here is the code so far:

Code:
<?php 




mysql_connect("XYZ", "XYZ", "XYZ") or die(mysql_error());
mysql_select_db("XYZ") or die(mysql_error());



$db = ????
$prefix = "nuke";
$sql = "SELECT * FROM ".$prefix."_jreviews";
$query = mysql_query($query);
$numrows = $db->sql_numrows($query);
$rannum = rand(1,$numrows);

$sql = "SELECT id, title, imagethumb FROM ".$prefix."_jreviews WHERE id='$rannum'";
$result = $db->sql_query($sql);
list($id, $title, $imagethumb) = $db->sql_fetchrow($result);
$id = intval($id);
$title = stripslashes($title);
$imagethumb = stripslashes(check_html($imagethumb, "nohtml"));
if (!empty($imagethumb)) {
   $content .= "<a href=\"/content/modules.php?name=JReviews&amp;rop=showcontent&amp;id=$id\"><img src=\"$imagethumb\" align=\"center\" border=\"0\" width=\"100\" height=\"100\" alt=\"\"></a>";

 
} else {
   $content .= "<img src=\"images/reviews/defaultcover.jpg\" align=\"center\" border=\"0\" width=\"100\" height=\"100\" alt=\"\">";

}



?>


I replaced all the sensitive info (log-in info) with XYZ.

_________________
PHP Nuke Version: 7.5, patched
PHP Version: 4.3.11

Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message
spasticdonkey
RavenNuke(tm) Development Team



Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Wed Sep 15, 2010 5:31 pm Reply with quote

If it were me I would create a function and then call the function from where you want it displayed. Something like this (this is a quicky there are more efficient ways to grab a random row)

Code:
function random_reviews() {

   global $db, $prefix;
   $rresult = $db->sql_query('SELECT * FROM '.$prefix.'_jreviews');
   $numrows = $db->sql_numrows($rresult);
   $rannum = rand(1,$numrows);
   $result = $db->sql_query('SELECT * FROM '.$prefix.'_jreviews WHERE id='.$rannum.'');
   if($result) {
      $row = $db->sql_fetchrow($result);
      $rrid= intval($row['id']);
      $rrtitle = stripslashes(check_html($row['title'], 'nohtml'));
      $rrimage = stripslashes(check_html($row['imagethumb'], 'nohtml'));
      if (empty($rrimage)) {
      $rrimage = 'images/reviews/defaultcover.jpg';
      }
      echo '<div class="yourstyle1">';
      echo '   <a href="modules.php?name=JReviews&amp;rop=showcontent&amp;id='.$rrid.'"><img class="yourstyle2" src="'.$rrimage.'" width="100" height="100" border="0" alt="'.$rrtitle.'" title="'.$rrtitle.'" />';
      echo '   <span class="yourstyle3">'.$rrtitle.'</span></a>';
      echo '</div>';
   }
}


since I don't know what version of nuke you have, can't say where to put it.. but give it a try... (or tries, lol) and btw you said "embed that block in my html code", but you will need to be in php to access the function..

Where are you trying to place this? The header? more info will help if you run into problems..
 
View user's profile Send private message Visit poster's website
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Wed Sep 15, 2010 6:07 pm Reply with quote

spasticdonkey, he said something about standalone so I do not think you can be using nuke functions.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
rogue3







PostPosted: Wed Sep 15, 2010 8:06 pm Reply with quote

OK, after trial and error and scouring the net for the right php code, I've managed to strip all the nuke stuff out and do a basic php script, which is working perfectly as a standalone random script. Hopefully this will help someone else down the road!

Code:
<?php 


$host = "HOST";
$user = "USER";
$pass = "PW";
$dbname = "DBNAME";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$prefix = "nuke";
$query = mysql_query("SELECT * FROM ".$prefix."_jreviews");
$num_rows = mysql_num_rows($query);
$rannum = rand(1,$num_rows);

$sql = "SELECT id, title, imagethumb FROM ".$prefix."_jreviews WHERE id='$rannum'";
$result = mysql_query($sql);
list($id, $title, $imagethumb) = mysql_fetch_array($result);

if (!empty($imagethumb)) {
   echo "<a href=\"/content/modules.php?name=JReviews&amp;rop=showcontent&amp;id=$id\"><img src=\"$imagethumb\" align=\"center\" border=\"0\" width=\"100\" height=\"100\" alt=\"$title\" title=\"$title\"></a>";
 
} else {
   echo "<a href=\"/content/modules.php?name=JReviews&amp;rop=showcontent&amp;id=$id\"><img src=\"/images/BLANKIMAGEHERE.jpg\" align=\"center\" border=\"0\" width=\"100\" height=\"100\" alt=\"$title\" title=\"$title\"></a>";

}

?>
 
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 ©