adam_gardner Posted April 26, 2006 Share Posted April 26, 2006 hi guys,i've simplified my query down to make it easier to understand, but the query's working fine its just hte output.ok, selecting products, then looping to get all of them, then $main stores the values of the products.however, when I try and output to the page (within a marquee) it only picks up the first result.do i need to store the results as an array first? how do i do that?note :: when i move the "echo - marquee" statement inside the loop it display all products, but each in their own marqee.What i want to do is make all the products scroll in the marquee.Any help would be great!code is below - [code]<?$queryF = "SELECT * FROM Products";$result=mysql_query($queryF) or die (mysql_error() . "\nActual query: " . $query);$num=mysql_numrows($result);$i=0;while ($i < $num) {$ProductName=mysql_result($result,$i,"ProductName");$main = "Products-Returned-From-Result";$i++;}echo "<MARQUEE BEHAVIOUR=SCROLL>$main</MARQUEE>";?>[/code] Quote Link to comment Share on other sites More sharing options...
wisewood Posted April 26, 2006 Share Posted April 26, 2006 Put the marquee into the while loop. This way, each result will get its own marquee.[code]<?php$queryF = "SELECT * FROM Products";$result=mysql_query($queryF) or die (mysql_error() . "\nActual query: " . $query);$num=mysql_numrows($result);$i=0;while ($i < $num) {$ProductName=mysql_result($result,$i,"ProductName");$main = "Products-Returned-From-Result";echo "<MARQUEE BEHAVIOUR=SCROLL>$main</MARQUEE>";$i++;}?>[/code] Quote Link to comment Share on other sites More sharing options...
samshel Posted April 26, 2006 Share Posted April 26, 2006 [code]<?php$queryF = "SELECT * FROM Products";$result=mysql_query($queryF) or die (mysql_error() . "\nActual query: " . $query);$num=mysql_numrows($result);$main = "";$i=0;while ($i < $num) {$ProductName=mysql_result($result,$i,"ProductName");$main .= $ProductName." ";$i++;}echo "<MARQUEE BEHAVIOUR=SCROLL>$main</MARQUEE>";?>[/code]hth Quote Link to comment Share on other sites More sharing options...
adam_gardner Posted April 26, 2006 Author Share Posted April 26, 2006 ahh great!all i was missing was the . after $mainwisewood - i mentioned that i used your method, but i wanted all the results in the same marquee - so they scroll side by side.all sorted and solve3d now - thanks!Adam Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 26, 2006 Share Posted April 26, 2006 I know you said it was solved, but here's another way of doing the same thing...[code]<?php$queryF = "SELECT * FROM Products";$result=mysql_query($queryF) or die (mysql_error() . "\nActual query: " . $query);$tmp = array();while ($rw = mysql_fetch_assoc($result)) $tmp[] = $rw['ProductName'];if (!empty($tmp) echo '<MARQUEE BEHAVIOUR=SCROLL>' . implode(' ',$tmp) . '</MARQUEE>';?>[/code]You'll notice:[list][*]The code is shorter and cleaner.[*]The while loop uses the mysql_fetch_assoc() function which returns an associative array keyed by your field names.[*]I use a temporary array to store the ProductNames[*]I only echo the marquee tag if the array isn't empty. i.e. there are products to display[*]The string to display is formed with the implode() function which, in this case, puts a space between each element of the temporary array.[/list]Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.