PDA

View Full Version : Help with widget code


dsantana
08-23-2012, 10:06 PM
I have this code that is in a php widget to go and gather up to 5 random images.
But it's placing the images in the header instead of the php box.
Any ideas on why that's happening?
I did notice all this code is "msql" and my db is "mysqli" not sure if that matters?
$con = mysql_connect("*****.**.*******.hostedresource.com","*******","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("******", $con);

$result = mysql_query("SELECT * FROM vjb_ads ORDER BY RAND() LIMIT 0,5;");

while($row = mysql_fetch_array($result))
{

echo "<a href='{$row['url']}'><img src='{$row['image_path']}' /></a><br/>";

}

mysql_close($con);

kh99
08-24-2012, 11:24 AM
You can't echo your html, you have to set $output. In your code I think you just have to change "echo" to "$output .= ", like:

$output .= "<a href='{$row['url']}'><img src='{$row['image_path']}' /></a><br/>";

dsantana
08-24-2012, 03:25 PM
You can't echo your html, you have to set $output. In your code I think you just have to change "echo" to "$output .= ", like:

$output .= "<a href='{$row['url']}'><img src='{$row['image_path']}' /></a><br/>";

Thanks... That got them out of the header but they aren't appearing in the PHP Widget Box either :confused:

Nevermind!!! That worked!!! Missed the "=" when I copy and pasted...

Thanks a bunch!!!

--------------- Added 1345910120 at 1345910120 ---------------

You can't echo your html, you have to set $output. In your code I think you just have to change "echo" to "$output .= ", like:

$output .= "<a href='{$row['url']}'><img src='{$row['image_path']}' /></a><br/>";
On that same line I tried to add standard html code to open in a new window
<a href='{$row['url']}'" target="_blank">
but it didn't fly, got a syntax error.

What did I do wrong?

kh99
08-26-2012, 10:56 PM
You used double quotes in your html. Since you're putting the code in a double quoted string, you either have to escape all double quotes that occur as part ofthe html (by putting a backslash in front on each one) or else use only single quotes (probably the easier option).

dsantana
08-27-2012, 03:39 AM
You used double quotes in your html. Since you're putting the code in a double quoted string, you either have to escape all double quotes that occur as part ofthe html (by putting a backslash in front on each one) or else use only single quotes (probably the easier option).

Thanks... That worked!

dsantana
08-31-2012, 03:05 PM
Is there something in that code that might stop an animated gif in Google Chrome?
It works fine in IE and FF