Jump to content

i need help with silly script haha


runnerjp

Recommended Posts

hey guys iv got this marquee script that takes messages from my database that is a shoutbox and posts them onto my main page
or this is what its supposed to do

[code]<?php
#################################
include("http://runnerselite.com/tag/admin/connect.php");
#################################

//mysql_connect("$host","$dbuser","$dbpass") or die(mysql_error());

mysql_connect(localhost,user,password) or die(mysql_error()); <--i changed this for this forum purpose lol
// Select the database.
mysql_select_db(runnerse_shoutbox) or die(mysql_error());
$query = "SELECT name, message FROM dawg_tag order by postid DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$marquee = "";
$i = 0;

$r=mysql_fetch_array($result);


while($r=mysql_fetch_array($result))
{
  $posts[$i] = $r[name].' - '. $r[message]. '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  ++$i;
}
$marquee = implode("<img src='http://www.runnerselite.com/image/RUNNERSMALL.jpg'>", $posts);

echo "<marquee scrolldelay='110'><font size='3'><span style='color: white'>". $marquee. "</span></font></marquee>"
[/code]

the error reads Warning: implode(): Bad arguments. in /home/runnerse/public_html/tag/maq.php on line 24


now i think its because the loop never gets a true value (mysql_fetch_array() failed) and thus $posts is never assigned a value, thus $posts isnt an array.

yet i have tried messing around with it and cant seem to fix it :(

any help guys would be very greatfull
Link to comment
https://forums.phpfreaks.com/topic/27321-i-need-help-with-silly-script-haha/
Share on other sites

You have your query limitted to one record, then your calling mysql_fetch_array outside of the loop. By the time its gets to the loop there are no records left.

Which is it? If you only want one record you dont need half this code... if you have more than one record, remove the LIMIT clause from your query and also the call to mysql_fetch_array from before the while().
Try this:

[code]<?php

include("http://runnerselite.com/tag/admin/connect.php");

mysql_connect($host,$dbuser,$dbpass) or die(mysql_error());
mysql_select_db(runnerse_shoutbox) or die(mysql_error());

$query = "SELECT name, message FROM dawg_tag order by postid DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$marquee = "";
$i = 0;

$posts = array();

while($r=mysql_fetch_array($result))
$posts[] = $r['name'].' - '. $r['message']. '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

$marquee = implode("<img src='http://www.runnerselite.com/image/RUNNERSMALL.jpg'>", $posts);

echo "<marquee scrolldelay='110'><font size='3'><span style='color: white'>". $marquee. "</span></font></marquee>"

?>[/code]

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.