Jump to content

Retrieve 15 of the last mysql posts into multi dimensional array, need help..


Recommended Posts

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

 

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

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  :shrug:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.