businessman332211@hotmail.com Posted September 7, 2006 Share Posted September 7, 2006 I was wondering, with javascript arrays, I can access the value, but never the name. I need to get the name/value pairslikename namevalue valueI need to get those on the banner. How do I access the name, as well as the value pair. Link to comment Share on other sites More sharing options...
aspnetguy Posted September 7, 2006 Share Posted September 7, 2006 I don't follow what you mean...what is the name in the array? Can you give an example of what you are trying to do?Do you mean like associative arrays in PHP?this should helphttp://persistent.info/archives/2004/08/27...ociative-arrays Link to comment Share on other sites More sharing options...
businessman332211@hotmail.com Posted September 7, 2006 Author Share Posted September 7, 2006 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 More sharing options...
Webworldx Posted September 10, 2006 Share Posted September 10, 2006 I'm probably a bit lost here, but what's wrong with:my_array[0] = [ "Name" , "Value" ]my_array[1] = [ "Name" , "Value" ]?? Link to comment Share on other sites More sharing options...
WilMead Posted September 14, 2006 Share Posted September 14, 2006 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 More sharing options...
businessman332211@hotmail.com Posted September 14, 2006 Author Share Posted September 14, 2006 I had actually totally dropped this for lack of time, but I will do what I can to get this working, I like the advice, when I have time to go back and try that again, I think that will help a lot I am saving hte post. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now