Board Logo

PHP Idiot needs code help for scroll.tpo0.php
steamngn - 10/22/2006 at 01:34 PM

Hi All! EXCELLENT piece of coding, this scroller...
now if only my php ability were this good!
I am TRYING to get scroll.tpo0.js changed over to php to connect to MySQL. I am pathetic at this, and am having trouble. Here is my code so far:

<?php
[email protected]_connect("mysql.bluedomino.com","chungmanews","kicking");
[email protected]_select_db("scroller",$db);
$query="SELECT * FROM scroller ORDER BY id ASC LIMIT 3";
$result=mysql_query($query);
$array=array();
while ($row=mysql_fetch_assoc($result)){
$id=$row['id'];
$name= $row['name'];
$posts=array("name"=>$name, "id"=>$id);
array_push($array,$posts);
}
?>
var LOOK = {
// scroller box size: [width, height]
'size': [350, 100]
},

BEHAVE = {
// autoscroll - true, on-demand - false
'auto': true,
// vertical - true, horizontal - false
'vertical': true,
// scrolling speed, pixels per 40 milliseconds;
// for auto mode use negative value to reverse scrolling direction
'speed': 5
},

// a data to build scroll window content
ITEMS = [
{ // file to get content for item from; if is set 'content' property doesn't matter
// only body of HTML document is taken to become scroller item content
// note: external files require time for loading
// it is RECOMMENDED to use content property to speed loading up
// please, DON'T forget to set ALL IMAGE SIZES
// in either external file or in 'content' string for scroller script
// to be able to estimate item sizes
'file': '',
'content': '<?php echo $array[0][id]."<br>".$array[0][name]; ?>',
'pause_b': 2,
'pause_a': 0
},
{
'file': '',
'content' : '<?php echo $array[1][id]."<br>".$array[1][name]; ?>',
'pause_b': 2,
'pause_a': 0
},
{
'file': '',
// note: image path is relative to the ts_files directory
'content' : '<?php echo $array[2][id]."<br>".$array[2][name]; ?>',
'pause_b': 2,
'pause_a': 0
}
// add as many items here as you need.
// don't forget to separate them with commas, make sure there is no comma after the last item
]

Ok, I found the post regarding dynamic data, and re wrote my PHP to the above code. This is working. I notice at this post:
http://www.softcomplex.com/forum/viewthread_2490/
that jeviridon has ASP code that will pull however many rows are returned WITHOUT hard coding it. can this be done is php, and f so, how?
Now I know that this is not quite right. Can anyone help sort this php nimrod out? :)
Andy


tigra - 10/23/2006 at 09:07 AM

now instead of static items inside the ITEMS = [...] add the loop in which you echo the data for each scroller's item. You can then request the page via http and view the resulting code by using view->source feature of your browser.


steamngn - 10/23/2006 at 01:36 PM

Well...
I've been trying my best, but not having any luck. I can't seem to get the loop syntax right to return the correct string(s) of data.
I've been tinkering around with it all day with no luck. What should the string look like?
Here is my most recent attempt:

$x = 0;
while ($x<=$numrows){
if ($x<$numrows){
$test = $test."'file':'','content':'".$x. $array[$x][id]."<br>".$array[$x][name]."','pause_b': 2,'pause_a': 0".",";
}else if ($x==$numrows){
$test = $test."'file':'','content':'".$x. $array[$x][id]."<br>".$array[$x][name]."','pause_b': 2,'pause_a': 0";
}
++$x;

This builds a string of all the records from the array, but is obviously wrong or missing something....My php is not good, still learning...
Any ideas?
Andy


tigra - 10/23/2006 at 07:01 PM

I don't see where you echo the string. Also don't use <br> in the string. It's JavaScript, not HTML. If you need endline then echo "n". I'm not a php person so there may be some more problems with the php code and the results it generate.


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/