Page 1 of 1

SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 8:40 am
by simonmlewis
We need to run a tickertape, and it needs to be from a database.
Once x amount of results have been shown, we want it to start over. So either in a loop, or from what I read, using REPEAT.

But I cannot see how to code the REPEAT statement. ie. telling it how many times, or infinite.

Can anyone please help.

Thanks.

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 8:47 am
by Celauran
I don't see where/why REPEAT would be needed for this application. Pull down the articles you want to display and hand them off to whatever is going to be handling your ticker tape. It can handle looping the content.

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 8:53 am
by simonmlewis
It would be a simple database query that echoes the <a href='#'>here</a>&nbsp;|&nbsp<a href='#'>here</a>&nbsp;|&nbsp..... but if it finds 5, it will show 5... then stop.
I want that to loop.

Unless you are suggesting I wrap the whole query in a loop? So do a :

Code: Select all

$count = 0;
while ($count < 100)
{
$result = ......
}
??

I just thought using REPEAT would be more efficient?

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 8:56 am
by Celauran
I thought you wanted the same five items to repeat. You could accomplish that with a single query.

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 8:57 am
by simonmlewis
How?
Each five items would repeat, and run over and over. How would u do it?

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 8:59 am
by Celauran
Like I said initially, pull down the items you want, stuff them in an array, hand the array off to whatever JS is going to handle your ticker tape. Repeatedly hitting the database to pull down the same set of data doesn't make any sense.

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 9:01 am
by simonmlewis
I'm not using Javascript.

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 9:06 am
by Celauran
simonmlewis wrote:I'm not using Javascript.
a. That doesn't change my answer
2. In your proposed approach, how were you planning on getting subsequent query results without AJAX?

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 9:10 am
by simonmlewis
Loop the query, around 10-20 times.
So the query finds all the rows, and executes them into a Marquee.
Once it's done that... it then does it again. and again...

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 9:23 am
by simonmlewis
Something like this:

Code: Select all

echo "<div class='marquee'><marquee behavior='scroll' direction='left' onmouseover=\"this.stop()\" onmouseout=\"this.start()\" scrollamount='3' scrolldelay='20'>";
$marqueecount = 0;
while ($marqueecount < 20)
{
$result = mysql_query ("SELECT * FROM static WHERE section = 'marquee' ORDER BY priority");
  while ($row = mysql_fetch_object($result))
    {
    echo "<a href='$row->url'>$row->freetext</a>&nbsp;|&nbsp;";
    }
$marqueecount ++;
}    
    echo "</marquee></div>";

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 9:35 am
by Celauran
So you'd be fetching the same data from the database 20 times. That doesn't make any sense. You're fetching data you already have. Take a look at the link I posted to your other thread on this topic, maybe that will help it click.

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 9:44 am
by simonmlewis
Nice design, but it only shows one at a time. We want it to be a continuous movement.
Marquee is a little jerky, I know that.
And I know I am doing the same thing over and over. So how do I put all the rows into an array, and then repeat the array over and over?

Bearing in mind, I need to store the URL and "freetext" as well.

Re: SELECT REPEAT statement - how do you do it?

Posted: Thu Oct 29, 2015 10:19 am
by simonmlewis
I think I have cracked it, unless you can see some streamlining?

Code: Select all

$marqueefreetext = array();
$marqueeurl = array();
$result = mysql_query ("SELECT * FROM static WHERE section = 'marquee' ORDER BY priority");
$num_rows = mysql_num_rows($result);
  while ($row = mysql_fetch_object($result))
    {
    $marqueefreetext[] = $row->freetext;
    $marqueeurl[] = $row->url;
    }
    
echo "<div class='marquee'><marquee behavior='scroll' direction='left' onmouseover=\"this.stop()\" onmouseout=\"this.start()\" scrollamount='3' scrolldelay='20'>";
$marqueecount = 0;
while ($marqueecount < $num_rows)
{
echo "<a href='".$marqueeurl[$marqueecount] . "'>" . $marqueefreetext[$marqueecount] . "</a>&nbsp;&nbsp;|&nbsp;&nbsp;";
$marqueecount ++;
}

    echo "</marquee></div>";