PHP Recursive Function base on single id export excel - php

I have a search page that allow user to key in the member ID and it will list out all the downline that belongs to the user.
I am using easyui treegrid to generate the downline.
Now i need to do an extra button to export out all the downline that belongs to the search id and export each line of information into excel file.
This is part of my data, and actually the real data had more column and about 4000++ of data.
Is there anyone can help me or some references? Please let me know if you need more info
+-------------+---------------+---------------------------+------------+
| MemberID | parent_id | Name | Age |
+-------------+---------------+---------------------------+------------+
| 1 | 0 | Cassy | 8 |
| 2 | 1 | Peter | 7 |
| 3 | 1 | Maide | 7 |
| 4 | 1 | Samda | 7 |
| 5 | 4 | Kinso | 7 |
| 6 | 4 | March | 7 |
| 7 | 2 | Sandy | 10 |
| 8 | 0 | Mandy | 12 |
+-------+---------------+----------------------------------------------+

Related

Create New Column In Mysql Database Row?

I have a database called form, in it a have a few columns.
+--------+----------+-----------+
| id | title | body |
+--------+----------+-----------+
| 1 | A | 10 |
+--------+----------+-----------+
| 1 | B | 3 |
+--------+----------+-----------+
| 2 | A | 9 |
+--------+----------+-----------+
| 2 | c | 40 |
Each row has an id representing a thread number. In the database when someone comments I have a php script that will pull the id from the database of the thread the user commented on and create a new column in that row within the database. Such as below:
+--------+----------+-----------+-------------+
| id | title | body | comment01 |
+--------+----------+-----------+-------------+
| 1 | A | 10 | zyx |
+--------+----------+-----------+-------------+
| 2 | B | 3 |
+--------+----------+-----------+
| 3 | A | 9 |
+--------+----------+-----------+
This way I will be able to extract the thread along with the comments and display them onto the page.
My question is how do I write the code to insert a new column in a thread id row when someone submits a new comment?

rearraging converstaions with lastest on top in php + mysql

we have building a chat application using php and mysql and our table structure looks like this
converstation_table_name
id
conversation_id
created_at
user_1
user_2
messages
sender
reciever
message
created_at
conversation_id
here are the values in both tables
conversation_table_name
id | con_id(shortname) | created_at | user_1 | user_2 |
1 | 123132 | now | 1 | 5 |
2 | 123133 | now | 1 | 3 |
3 | 123134 | now | 1 | 4 |
4 | 123135 | now | 1 | 2 |
messages
sender | reciever | message | created_at | conversation_id |
1 | 3 | abc | now | 123133 |
3 | 1 | cee | now | 123133 |
1 | 2 | 1411 | now | 123135 |
1 | 5 | 1-5 | now | 123132 |
now we want to arrange the output something like this
123132
between 1 - 5
123135
between 1 - 2
123133
between 1 - 3
how to go about it, in short we want to make the latest message in user conversation to appear on top, just like facebook does with it's messaging system, how to go about it, we are still looking for a working answer
Can be introduced new field viewed or seen with datetime field. On visiting message update the field. So can be used order by that field and you will have the viewed time.

Junction tables in MySQL

(Sorry, my english isn't very good)
Hi, I am trying to learn how to work with junction tables in MySQL and I can't figure how to do something. I know the basics of MySQL but I have never worked with "JOIN".
In this test project, I would like to be able to show on a page the app of a given category (you click on "Games", only the apps that are in the "Games" category will be displayed on the page). I would like to know what the SQL request should look like.
Second question, let's say that an App could fit 2 different categories, how can I manage to give that app 2 different Category_ID in my database ?
Here is what my Database looks like at the moment :
Table name: APPS
+------------+-------------------+
| App_ID (pk)| App_Name |
+------------+-------------------+
| 1 | Weather Network |
| 2 | Is it sunny 2.0 |
| 3 | The Weather App |
| 4 | Zelda |
| 5 | Megaman |
| 6 | Doom 3 |
+------------+-------------------+
Table name : CATEGORY
+-----------------+-----------------+
| Category_ID (pk)| Category_Name |
+-----------------+-----------------+
| 1 | Games |
| 2 | Weather |
+-----------------+-----------------+
Table name : JUNCTION_APP_CATEGORY
+----------------+--------------------+
| APP_ID (pk) | Category_ID (pk) |
+----------------+--------------------+
| 1 | 2 |
| 2 | 2 |
| 3 | 2 |
| 4 | 1 |
| 5 | 1 |
| 6 | 1 |
+----------------+--------------------+
For your first question, the answer is
SELECT a.*, c.*
FROM APPS a, CATEGORY c, JUNCTION_APP_CATEGORY ac
WHERE a.App_ID=ac.APP_ID
AND c.Category_ID=ac.Category_ID
AND ac.Category_ID=<category_id for category "Games">
For your second question, you can use both APP_ID and Categor_ID as the primary key of table JUNCTION_APP_CATEGORY(note NOT TWO pks, but use the two columns together as ONE pk). So that you can put data like this:
+----------------+--------------------+
| APP_ID (pk) | Category_ID (pk) |
+----------------+--------------------+
| 1 | 1 | <-- APP_ID=1 belongs to both cat 1 & 2
| 1 | 2 |
| 2 | 2 |
| 3 | 2 |
| 4 | 1 |
| 5 | 1 |
| 6 | 1 |
+----------------+--------------------+

how to bult N Type category tree with php?

we have this table "Categoris"
------------------------------------
| ID |parent.id | Category Name |
| 1 | 0 | php |
| 2 | 1 | Jquery |
| 3 | 2 | Java script |
| 4 | 2 | HTML |
| 5 | 4 | CSS |
| 6 | 1 | word Press |
| 7 | 3 | DOM |
Output should be
PHP->Jquery
->wordpres
Jquery->java Script
->HTML
Java Script->DOM
HTML-> CSS
Word Press
DOM
Have a look at PEAR's Tree package.

Sort through MySQL result to create multilevel dropdown menu

I am just puzzled here. Maybe because it's the end of the day, I dont know. Im using PHP to grab items from a MySQL db. I am just looking for some PHP help. I have the HTML and CSS done. Here is the basic structure of the db. Its a nested set btw. Imagine that my left and right values for the nested set have been sorted in MySQL already which leaves me with depth.
----------------------------------------
| id | title | sequence_number | depth |
----------------------------------------
| 1 | A | 1 | 1 |
| 2 | B | 2 | 1 |
| 3 | C | 1 | 2 |
| 4 | D | 3 | 1 |
| 5 | E | 4 | 1 |
| 6 | F | 2 | 2 |
| 7 | A | 1 | 3 |
| 8 | B | 5 | 1 |
| 9 | C | 3 | 2 |
| 10 | D | 2 | 3 |
| 11 | E | 6 | 1 |
| 12 | F | 4 | 2 |
----------------------------------------
Now if that's not enough to confuse you then keep reading. I am using a foreach loop to loop through each item and sort it manually like that. The problem is the menu eventually will go to 3 levels which gets me stuck as my loop is only for two levels. Can anybody help me sort this array?
you could use a recursive function
eg
loop through with depth set as 1 then re-call the function with depth set as depth + 1
does that help?
Josh

Categories