Hi there guys,
In my script, I have a block that people can insert into other pages, which displays a single random result. I thought that I had created it to where I could change the result to more than one, by changing the limit, but for some reason, it's not showing any more than one result, regardless of what I set limit to. Here's my code:
/* this query will get a random testimonial result */
$query = "SELECT id,postdate,author,authorweb,authorwebname,title,testtext,highlight FROM ".$prefix."testimonials WHERE active=1 ORDER BY rand() LIMIT 4"; <~~ changing limit
$result = mysql_query ($query) or die('MySQL error: ' . mysql_error() . '<hr/>' . $query);
$result_rows = mysql_num_rows($result);
$result = mysql_query ($query);while ($row = mysql_fetch_assoc ($result)) {
$id = $row['id'];
$postdate = $row['postdate'];
$author = $row['author'];
$authorweb = $row['authorweb'];
$authorwebname = $row['authorwebname'];
$title2 = $row['title'];
$testtext1 = strip_tags ($row['testtext'], '<br>');
$highlight = $row['highlight'];
function nicetrim ($s, $length) {
$str_to_count = html_entity_decode($s);
if (strlen($str_to_count) <= $length) {
return $s;
}
$s2 = substr($str_to_count, 0, $length);
$s2 = substr($str_to_count, 0, $length - 3);
$s2 .= "...";
return $s2;
}
$testtext = nicetrim($testtext1, $block_textcount);
$title = nicetrim($title2, $block_titlecount);
/* display the data */
echo("<html>
<head>
<script language=\"javascript\" type=\"text/javascript\">
<!--
/****************************************************
Author: Eric King
Url: http://redrival.com/eak/index.shtml
This script is free to use as long as this info is left in
Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
****************************************************/
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos==\"random\"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos==\"center\"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!=\"center\" && pos!=\"random\") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// -->
</script>
</head>
<body>
<div align=center>
<table width=$block_width border=1 cellpadding=1 cellspacing=1>");
if($block_showtitle == 1) {
echo("<tr>
<td bgcolor='#ffffff' width=400>
<font size=3><b>$title</b></font>
</td>
</tr>");
}
echo(" <tr>
<td bgcolor='#ffffff'>
<font size=2>");
if($use_highlight == 1){
if($highlight != ""){
echo("...".$highlight."...
<hr>
<a href=\"$siteurl/index.php?id=$id\" onclick=\"NewWindow(this.href,'submit','800','600','yes','center');return false\" onfocus=\"this.blur()\">View this testimonial</a><br>");
}else{
echo("$testtext
<hr>
<a href=\"$siteurl/index.php?id=$id\" onclick=\"NewWindow(this.href,'submit','800','600','yes','center');return false\" onfocus=\"this.blur()\">View this testimonial</a><br>");
}
}else{
echo("$testtext
<hr>
<a href=\"$siteurl/index.php?id=$id\" onclick=\"NewWindow(this.href,'submit','800','600','yes','center');return false\" onfocus=\"this.blur()\">View this testimonial</a><br>");
}
echo("</font><p>
</td>
</tr>");
if($block_showauth == 1) {
echo("<tr>
<td align='right'>
<font size='1'>$author</font>
</td>
</tr>");
}
if($authorweb != "") {
if($block_showauthweb == 1) {
echo("<tr>
<td align='right'>
<font size='1'><a href='$authorweb' target='_blank'>$authorwebname</a></font>
</td>
</tr>");
}
}
echo("<tr>
<td bgcolor='#ffffff'>
<font size=2>
<a href=\"$siteurl\" onclick=\"NewWindow(this.href,'submit','800','600','yes','center');return false\" onfocus=\"this.blur()\">View all testimonials</a><br>
<a href=\"$siteurl/form.php\" onclick=\"NewWindow(this.href,'submit','600','400','yes','center');return false\" onfocus=\"this.blur()\">Submit your own</a>
</font><p>
</td>
</tr>
</table>
</div><br>
<br>
</body>
</html>");
}
}
mysql_close($autoconn);
Could someone point out what I'm doing wrong that is not allowing it to show mulitple results?
thanks,
json