PDA

View Full Version : Simple Plug-in not Working.


req2d
10-15-2007, 12:27 AM
This is a continuation from another thread, but the content has already changed sig. from the original thread.

Trying to get the latest 6 thumbails to display under the navbar. "highlightthread" is indeed the name of the table as I forgot to add the prefix.

Here is the plugin:
$highlightthreads = $db->query_read("SELECT * FROM highlightthread ORDER BY reference DESC LIMIT 0, 6);

while ($row = mysql_fetch_array($highlightthreads)) {
echo "<img src=".$row["imageurl"]." />";
}

Screenie: http://img80.imageshack.us/img80/1023/problemlf3.jpg

Last line on the navbar, I just plucked in $highlightthreads , but to no avail. Nothing is showing up in the source either when I load forumhome so I'm sure I've gone wrong somewhere.

Any ideas? Many thanks :)

Analogpoint
10-15-2007, 07:00 PM
Instead of echoing the image tags, save them into a variable, and that's the variable you need to put in a template.

Opserty
10-15-2007, 07:58 PM
$highlightthreads = $db->query_read("SELECT * FROM highlightthread ORDER BY reference DESC LIMIT 0, 6");

while ($row = $db->fetch_array($highlightthreads))
{
$image .= '<img src='.$row['imageurl'] .' />';
}
Try that, then use $image in your template to show the images.

Analogpoint
10-15-2007, 08:05 PM
It's a good habit to initialize your variables $image = ''; before you start concatenating information onto it.

req2d
10-16-2007, 02:07 AM
Analogpoint & Opserty,

Thank you very much for your help. I've edited the code to show this now:

edited, see below:

--------------- Added 1192514327 at 1192514327 ---------------

Interesting, when I load the PHP through logicians template it displays the last 6 as the code states. However when I run it through the plugin I only get the last value (i.e. the 6th). Any thoughts on what may be causing this? Note: $highlightimage is situated at the bottom of the navbar.

New code:

$result = @mysql_query('SELECT reference, imageurl, threadurl FROM highlightthread ORDER BY reference DESC LIMIT 0, 6');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($row = mysql_fetch_array($result)) {
$highlightimage = $row['reference'];
}

Thank you :)

Marco van Herwaarden
10-16-2007, 06:43 AM
Change:
$highlightimage = $row['reference'];

To:
$highlightimage .= $row['reference'];

req2d
10-16-2007, 01:24 PM
Thank you Marco, still a lot to learn :)

Think the only issue I really have left is now "how do I seperate the data?". Currently, it's outputting <a href="url1url2url3url4url5url6"> when I'd like it to create the link for each of the url's. Code now is as follows:

$result = @mysql_query('SELECT reference, imageurl, threadurl FROM highlightthread ORDER BY reference DESC LIMIT 0, 6');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($row = mysql_fetch_array($result)) {
$threadurl .= $row['threadurl'];
$imageurl .= $row['imageurl'];
eval('$highlights = "' . fetch_template('highlights') . '";');
}

Code in template $highlights, pretty straightforward..

<a href="$threadurl"><img src="$imageurl"></a>

Thank you again for all the support, learning a lot by all means.

Marco van Herwaarden
10-16-2007, 02:04 PM
Change:
while ($row = mysql_fetch_array($result)) {
$threadurl .= $row['threadurl'];
$imageurl .= $row['imageurl'];
eval('$highlights = "' . fetch_template('highlights') . '";');
}
To:
while ($row = mysql_fetch_array($result))
{
$threadurl = $row['threadurl'];
$imageurl = $row['imageurl'];
eval('$highlights .= "' . fetch_template('highlights') . '";');
}

req2d
10-16-2007, 03:52 PM
Thank you Marco, that did the trick. I have been trying to figure out how to populate the thumbnails in 3 rows, 2 per row (total 6), i.e.:

thumb1 thumb2
thumb3 thumb4
thumb5 thumb6

Now obviously I could probably use 3 queries, but I'm thinking this is probably inefficient and there is a better solution. What function or code would I need to insert to make such possible?

Many thanks :)