Jump to content

[SOLVED] how to do it (foreach)


d22552000

Recommended Posts

Array
(
    [CLSID] => 101
    [sTDID1] => 1
    [sTDID2] => 2
    [sTDID3] => 3
    [sTDID4] => 4
    [sTDID5] => 5
    [sTDID6] => 6
    [sTDID7] => 7
    [sTDID8] => 8
    [sTDID9] => 9
    [sTDID10] => 10
    [sTDID11] => 11
    [sTDID12] => 12
    [sTDID13] => 13
    [sTDID14] => 14
    [sTDID15] => 15
    [sTDID16] => 16
    [sTDID17] => 17
    [sTDID18] => 18
    [sTDID19] => 19
    [sTDID20] => 20
    [sTDID21] => 21
    [sTDID22] => 22
    [sTDID23] => 23
    [sTDID24] => 24
    [sTDID25] => 25
    [sTDID26] => 26
    [sTDID27] => 27
    [sTDID28] => 28
    [sTDID29] => 29
    [sTDID30] => 30
    [sTDID31] => 31
    [sTDID32] => 32
    [sTDID33] => 33
    [sTDID34] => 34
    [sTDID35] => 35
)

 

as I said, lots of STDID.

 

oh im an idiot. thtas why yoru code didnt wkr cause I told yiou STDNTID but this table uses STDID -,- all my other tables use STDNTID.  omfg im a frekin moron.  m trying your code with STDID and seein if it works..

Link to comment
Share on other sites

while($row = mysql_fetch_array($res, MYSQL_ASSOC)) {

// get total items in the $row array

$items = count($row) - 1;

 

// now that we not how many items are in the $row array,

// we can use a for loop to loop through the array

for($i = 1; $i <= $items; $i++)

{

    echo $row['STDID' . $i] . '<br />';

}

}

 

works now, IM AN IDIOT. fuck -,-.

 

now im not gonna say solved yet cuase i bet thers gonna be another problem in like a second -,-.  ill rely with the new problem lol.

Link to comment
Share on other sites

but uh ya.. how would I use it I dont understnad your solution.

 

siomething about seperating by commas?

Uh ya.. maybe by reading?

If you honestly can't understand a simple solution and are to lazy to search, fine, I'm feeling really nice today, so I'll just hold your hand and walk you through it and do it all for you okay, even though it should be easy as hell for you to.

 

In your mysql query, the place where you have the columns that you want to output.. put

concat_ws(',',

In front of the rows you have in your query.. the row1,row2,row3 or whatever.. and put a

)

at the end of them

 

Now instead of all those rows being selected separately, it selects them like "Value1,Value2,Value3"

 

So now you use the PHP "explode" function to turn it into a nice little array and use foreach on it and voila.

 

In the future please look up on php.net or mysql.com if there is a function or something that you don't understand.

 

I really prefer teaching people how to fish instead of just giving fish.. so I'm doing both for you since you don't want to get this fish yourself.. have fun ^^

Link to comment
Share on other sites

Thank you AZU for explaingin that you wanted me to use a comma.  I did not understand your post and frankly, im tired -,-.  I have been working on this for a while.

 

 

except for the page size being about 2.1MB it worked out thanks solved.

 

I can stand the size since this is being used on a T1 connection by teachers in a district or by lan.

Link to comment
Share on other sites

Hm no I wasn't explaining that "I wanted you to use a comma". Where the hell did that come from?

I was solving your problem for you, and teaching you how to easily solve your problems on your own in the future.

 

Anyways, you're welcome.

Link to comment
Share on other sites

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.