adamrg7 Posted August 28, 2009 Share Posted August 28, 2009 Hey everyone, I am new to the forum and its good to see a place to come for help.. I wouldn't say that I am a very experienced php/mysql programmer. I have more experience in c++, and I am just getting my hands dirty with php.. I need a little help retrieving some values, this is what I have so far, which it keeps giving me the same value 15 times for each userid: for ($counter=0; $counter<$totalAssets; $counter+=1) { for($counter2=0; $counter2<=15; $counter2+=1) { $longitudes_L = mysql_query("SELECT longitude FROM tbl_transactions where userid= '$assets[$counter]' ORDER BY tid DESC", $mysql_link); $theresult = mysql_fetch_row($longitudes_L); $longitudes[$counter][$counter2] = $theresult[0]; echo $longitudes[$counter][$counter2]; } } Basically what im trying to do is get 15 of the last longitudes posted to the server, and put it into a multi dimensional array where the $longitudes[//THIS IS THE USER ID][//15 LONGITUDES go in here] Thanks.. -Adam Quote Link to comment https://forums.phpfreaks.com/topic/172335-retrieve-15-of-the-last-mysql-posts-into-multi-dimensional-array-need-help/ Share on other sites More sharing options...
.josh Posted August 29, 2009 Share Posted August 29, 2009 '$assets[$counter2]' or else you are not utilizing $counter2 in your query elsewhere. Quote Link to comment https://forums.phpfreaks.com/topic/172335-retrieve-15-of-the-last-mysql-posts-into-multi-dimensional-array-need-help/#findComment-908734 Share on other sites More sharing options...
adamrg7 Posted August 31, 2009 Author Share Posted August 31, 2009 I need to store values in an multi dimensional array, I dont know which way is best suitable for this app. I want to store them like this, or any other way similar so there is an id to every 15 longitudes. for ($counter=1; $counter<$totalAssets; $counter+=1) { $longitudes_L = mysql_query("SELECT * FROM tbl_transactions where userid= '$assets[$counter]' ORDER BY tid DESC LIMIT 15", $mysql_link); while($row=mysql_fetch_row($longitudes_L)) { $counter2+=1; echo $row[5]; echo $assets[$counter]; $longitudes[$counter2] = $row[5]; //this line works $longitudes[$counter][$counter2] = $row[5]; //this line doesn't work, any suggestions? echo "Next value has been stored and being echoed"; echo $longitudes[$counter2]; //works } } //psuedo: //longitudes[id name in here][longitudes in here, 15 elements] what do you recommend? thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/172335-retrieve-15-of-the-last-mysql-posts-into-multi-dimensional-array-need-help/#findComment-909496 Share on other sites More sharing options...
Batosi Posted August 31, 2009 Share Posted August 31, 2009 Either I am tired or this looks pretty good. What you want to do though is declare $counter2 for ($counter=1; $counter<$totalAssets; $counter+=1) { $counter2 = 0; Other than that I dont see any reason it shouldnt work right, when you do this though echo $counter and $counter2 with your other variables Quote Link to comment https://forums.phpfreaks.com/topic/172335-retrieve-15-of-the-last-mysql-posts-into-multi-dimensional-array-need-help/#findComment-909509 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.