SELECT REPEAT statement - how do you do it?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
SELECT REPEAT statement - how do you do it?
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.
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: SELECT REPEAT statement - how do you do it?
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.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: SELECT REPEAT statement - how do you do it?
It would be a simple database query that echoes the <a href='#'>here</a> | <a href='#'>here</a> | ..... 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 :
??
I just thought using REPEAT would be more efficient?
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?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: SELECT REPEAT statement - how do you do it?
I thought you wanted the same five items to repeat. You could accomplish that with a single query.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: SELECT REPEAT statement - how do you do it?
How?
Each five items would repeat, and run over and over. How would u do it?
Each five items would repeat, and run over and over. How would u do it?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: SELECT REPEAT statement - how do you do it?
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.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: SELECT REPEAT statement - how do you do it?
I'm not using Javascript.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: SELECT REPEAT statement - how do you do it?
a. That doesn't change my answersimonmlewis wrote:I'm not using Javascript.
2. In your proposed approach, how were you planning on getting subsequent query results without AJAX?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: SELECT REPEAT statement - how do you do it?
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...
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...
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: SELECT REPEAT statement - how do you do it?
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> | ";
}
$marqueecount ++;
}
echo "</marquee></div>";Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: SELECT REPEAT statement - how do you do it?
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.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: SELECT REPEAT statement - how do you do it?
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.
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: SELECT REPEAT statement - how do you do it?
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> | ";
$marqueecount ++;
}
echo "</marquee></div>";Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.