php - For each result in MySQL query, push to array (complicated) -


OK, what I'm trying to do here. I am running a MySQL query for the most recent posts. For each of the returned rows, I have to push the line ID in an array, then within that ID in the array, I have to add more data than the rows. A multi-dimensional array.

Thus my code is far away.

  $ query = "SELECT * positions by ID DESC limit 10"; $ Result = mysql_query ($ query); While ($ row = mysql_fetch_array ($ result)) {$ id = $ row ["id"]; $ Post_title = $ line ["headline"]; $ Post_text = $ row ["text"]; $ Post_tags = $ row ["tags"]; $ Post_category = $ line ["category"]; $ Post_date = $ line ["date"]; }  

As you can see I have not done anything with arrays yet. Here is an ideal structure that I see, just you are confused.

Master Array I think that you can call it only we will call this array $ posts. Within this array, I have an array for each row returned in each of my MySQL queries. Those arrays have $ post_title, $ post_text, etc.

How can I do this? I am very confused. An example would be really appreciated.

- Dellan

$ master [$ id] ['post_title '] = $ Post_title; $ Master [$ id] ['post_text'] = $ post_text; // etc

Or, with a low code this one, you can get rid of setting all those variables:

  $ master [$ Row ["id"]] ['post_title'] = $ row ["title"]; $ Master [$ row ["id"]] ['post_text'] = $ line ["text"]; // etc  

Edit the answer to the comment:

  foreach ($ line as master) {echo $ row ['post_title'] ; } // or if you know the ID $ line [$ id] ['post_title'];  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -