Jump to content

arrays


Recommended Posts

I never had to use php with javascript, I also never messed with arrays much, I always did basic stuff.The thing is, I have tried creating 2 dimensional arrays, associative arrays, and nothing is working, I think I need a stepping stone if someone can help, after cutting up about 3-4 different scripts(I am trying to get a grounding point for the rest of the program), here is what I have at the moment.I am trying to figure out

<?php// send header so browser knows how to treat the pageHeader("content-type: application/x-javascript"); mysql_connect("localhost", "elostand_west", "apex");mysql_select_db("elostand_general");// run query's$select = "SELECT * FROM businesses;";$query = mysql_query($select);// check for number of rows for later use$numrows = mysql_num_rows($query);if ($numrows) {// creates array's dynamically using php?>var name = new Array(<?php echo $numrows; ?>);var url = new Array(<?php echo $numrows; ?>); <?php}// set some parameters to help control my script further down?>var inc = 0;var x<?phpwhile ($row = mysql_fetch_array($query)) {?>name[inc++] = '<?php echo $row['name']; ?>';url[inc++] = '<?php echo $row['url']; ?>';<?php}// end while?>for (var i in name){document.getElementById('scrollboxtime').innerHTML = name[x] + "<br />" + url[x];}

Also I have a div on the homepage, like

<div id="scrollboxtime"></div>

Here are the things I have been trying to accomplish with this script, that I have encountered problems with1. I want it to pull data from a database, somehow trap information on 2 different values. I need the name and associated url of each entry. 2. Once i have successfully recorded the information so I can work with the data I need to get them to display on the div like soname name name name url url url urlSomething similar to that but enough space in between them, to not look messed up when a longer url, is put into the banner.3. I need to get this div, to be populated automatically, as I said, the database pulls information, creates a js array, and uses that array as the information.I need this div, to take the text, as it looks formatted above, and scroll it from the right wall of the div, all the way to the left wall of the div, and disappear off the page(at the end of the div), but it needs to keep scrolling across, when the final database entry(which there all recorded into an array when someone opens the homepage), comes, then it resets back at the first, and keeps going forever. As for the scrolling, I was using scrollTo, scrollBy, scroll, and then I finally realized these aren't used to get the scroll affect I wanted, they are used to set up scroll bars on the page, or on elements, now I have to figure out how to get it to scroll as well.Any advice, any guidance, any stepping stones will be greatly appreciated.

Link to comment
Share on other sites

Are you sure about this snippit?name[inc++] = '<?php echo $row['name']; ?>';url[inc++] = '<?php echo $row['url']; ?>';inc is incremented twice so it doesn't track the relationship between name and url. Drop the ++ on the first use name[inc] = '<?php echo $row['name']; ?>';url[inc++] = '<?php echo $row['url']; ?>';Your final loop uses x as an index to your arrays, but the variable i is being manipulated by the loop itself. for (var i in name){document.getElementById('scrollboxtime').innerHTML = name[x] + "<br />" + url[x];Would work better codedfor (var i in name){document.getElementById('scrollboxtime').innerHTML = name + "<br />" + url;Hope this helps.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...