Author |
Message |
rogue3
Regular
![Regular Regular](modules/Forums/images/ranks/2stars.gif)
![](modules/Forums/images/avatars/gallery/blank.gif)
Joined: Jul 02, 2009
Posts: 71
|
Posted:
Wed Sep 15, 2010 1:45 pm |
|
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&rop=showcontent&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! |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
spasticdonkey
RavenNuke(tm) Development Team
![](modules/Forums/images/avatars/48fb116845dfecf66294c.gif)
Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA
|
Posted:
Wed Sep 15, 2010 5:31 pm |
|
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&rop=showcontent&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.. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
Site Admin
![](modules/Forums/images/avatars/Dilbert/Dilbert_-_Dogbert_King.gif)
Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania
|
Posted:
Wed Sep 15, 2010 6:07 pm |
|
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. |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
rogue3
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Wed Sep 15, 2010 8:06 pm |
|
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&rop=showcontent&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&rop=showcontent&id=$id\"><img src=\"/images/BLANKIMAGEHERE.jpg\" align=\"center\" border=\"0\" width=\"100\" height=\"100\" alt=\"$title\" title=\"$title\"></a>";
}
?>
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|