PHP - Build A Multilevel Table
So, I need to build a table based on this table:
Code: [Select] create temporary table downline ( depth int, member_id int, full_name varchar(50), level int, referrer_id int, country char(2) ); I need to make a table to show each members downline (the people they referred to the site), it needs to be unlimited levels deep, and we have some members that have 25+ levels in their downline, where level 20 has 15,000+ people. Level 1 = your downline Level 2 = your donwline's downline Level 3 = your downline's downline's downline ect. I have this loop (after the temp table is built) which needs to build a table on the page. So, I can not get this table display right for the members downline, any suggestions? // Build the current users downline and add it to the temporary table $downline = mysql_query("select * from downline order by depth"); while($row = mysql_fetch_assoc($downline)){ if($row['depth'] != $depth){ $depth_id = $row['depth']; $content .= "<tr id='main_lvl_$depth_id' class='hiddenInfo' onclick='showHide(this);'><td style='text-align: center;color:#4d53c1;font-weight: bold;' class='w_border'><span class='signs_s'>".$this->dict['mLevels_Level']." $depth_id : </span><span class='signs'>".count($down)." ".$this->dict['mLevels_Members']." </span></td></tr><tr id='lvl_$depth_id' style='display:none;'><td class='w_border' style='text-align: center;'><table style='width:100%;'>"; $i = 0; $content .= "<tr> <th>Member ID (Sponsor ID)</th> <th>Member Name</th> <th>Country</th> <th>Member Level</th> </tr>"; } $class = ($i%2) ? 'color1NL' : 'color2NL'; $content .= "<tr id='_{$key}_' class='$class'><td class='width33'><a name='_".$row['member_id']."'></a><a href='?mid={$row['member_id']}'>#{$row['member_id']}</a> (<a href='?mid=".$row['referrer_id']."'>#".$row['referrer_id']."</a>)</td><td class='width33'>".$row['full_name']."</td><td>".$row['country']."</td><td class='width33'>".$row['level']."</td></tr>"; $i++; if($row['depth'] != $depth){ $content .= "</table></td></tr>"; } $depth = $row['depth']; } The following attachment has a working copy. The reason we don't stay with this is because it doesn't work with members who have large downlines, we run out of memory in php, and this hopefully will solve this problem. Similar TutorialsI have an array which can contain nth number of arrays. These arrays contain data from a query joining three tables and a where clause Code: [Select] array 0 => array 'account_num' => string '1' (length=1) 'icd9_code' => string '1' (length=1) 'dob' => string '12-12-1955' (length=10) 'sex' => string 'Male' (length=4) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 1' (length=8) 1 => array 'account_num' => string '1' (length=1) 'icd9_code' => string '1' (length=1) 'dob' => string '12-12-1955' (length=10) 'sex' => string 'Male' (length=4) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 2' (length=8) 2 => array 'account_num' => string '1' (length=1) 'icd9_code' => string '1' (length=1) 'dob' => string '12-12-1955' (length=10) 'sex' => string 'Male' (length=4) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 3' (length=8) 3 => array 'account_num' => string '1' (length=1) 'icd9_code' => string '1' (length=1) 'dob' => string '12-12-1955' (length=10) 'sex' => string 'Male' (length=4) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 4' (length=8) 4 => array 'account_num' => string '2' (length=1) 'icd9_code' => string '2' (length=1) 'dob' => string '11-11-1958' (length=10) 'sex' => string 'Female' (length=6) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 1' (length=8) 5 => array 'account_num' => string '2' (length=1) 'icd9_code' => string '2' (length=1) 'dob' => string '11-11-1958' (length=10) 'sex' => string 'Female' (length=6) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 3' (length=8) 6 => array 'account_num' => string '2' (length=1) 'icd9_code' => string '2' (length=1) 'dob' => string '11-11-1958' (length=10) 'sex' => string 'Female' (length=6) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 4' (length=8) 7 => array 'account_num' => string '3' (length=1) 'icd9_code' => string '3' (length=1) 'dob' => string '03-11-1958' (length=10) 'sex' => string 'Female' (length=6) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 3' (length=8) 8 => array 'account_num' => string '3' (length=1) 'icd9_code' => string '3' (length=1) 'dob' => string '03-11-1958' (length=10) 'sex' => string 'Female' (length=6) 'study' => string 'study 2' (length=7) 'prescription' => string 'script 4' (length=8) As you can see most of the information is repeated. How would I loop thru each array and consolidate the data so i could output it as follows account num 1 icd9 code 1 dob 12-12-1955 sex Male study study 2 prescriptions script 1, script 2, script 3, script 4 account num 2 icd9 code 2 dob 11-11-1958Femsex Male study study 2 prescriptions script 1, script 3, script 4 and so on. I tried using array_unique but all I cant figure out how to consolidate the data. Hi! I need a "very simple" PHP script which can compress a directory and all its multi-(infinite)level sub-directories using with .tar and .gz I have tried many complex scripts so far which don't work as most of them use ZIP and I don't have access to ZIP And a few of the simple ones, just don't function. Please help! Thank you ! - Xeirus. Instead of breaking down and actually learning how to use ajax, I'm thinking about trying to do something so I don't need a page refresh every time, and the filtered data is nearly instant. I just use the session array var, and build a new array from the rows that meet the conditions. I'm thinking of loading a two dimensional array into a session var, then use some input buttons, and use the post vars to filter the array based on a set of predefined conditions. ie status = 0, status = 1. It's a fairly small number of conditions applied to two different fields. So, I need to access specific fields within a row, and essentially create a new array either including or excluding that row depending on whether it met the condition. I'm struggling on several parts. 1. not sure how to build the array so that I can access specific fields, then not sure how to access those fields. Do I do this..... to build the array? .... Code: [Select] while($row = mysql_fetch_assoc($result)){ $array[] = array($row['field1'], $row['field2']); } I was thinking about using a foreach and is_array() to get to each row... Code: [Select] foreach($array as $key => $value){ if(is_array){ foreach($value as $k => $v){ if($v[0] == 1){ //stuck here $v[0] is not a field, it's the first char of the string. not sure how to access a field $new_array[] = $value; //stuck here. I need to put the whole row back into the array if the condition was true. seems like I would have to use the field selectors and rebuild the array. } } } } What would you do? Open to any ideas. Hi there, i have a problem regarding a editor that I am building, I am fairly new to php, but this is what i have so far: Code: [Select] <?php $dirname = "."; $dir = opendir($dirname); ?> <form action="editor.php" method="POST"> <select> <?php while(false != ($file = readdir($dir))) if (strpos($file, '.php',1)||strpos($file, '.html',1)||strpos($file, '.css',1) ) { { if(($file != ".") and ($file != "..")) { echo("<option><a href='$file'>$file</a></option>"); } }} ?> </select> <input type="submit" value="Submit" /> </form> <br /> <center> <form > <textarea rows="80" cols="130"> <?php include $_POST["$file"]; ?> </textarea> </center> The code produces a drop down list of any html, php or css files in the current directory and I want it to be able to show the selected file from the drop down list in the textarea so that I can edit it, I also am not sure how to save the file, would this be a file write method? any help would really be appreciated as I've been stuck on this issue for hours an its doing my nut in!!! Thanks SF I have two questions, I was wondering what would be the best method to go about building client side API functions on top of a already built API eg. http://docs.whmcs.com/API:Functions
We would like to provide our clients access to API functions related to their accounts without giving them access to the whole Admin API where they can see a lot of our other client information.
The other question we have an API built using Basic HTTP Auth for API authenication (HTTPS). eg curl username:password http://api.etc.com) If so what would be the best way to secure this method?
Thank you Hi, I have to build some reports based on mysql queries. Nothing fancy, just text, columns... There are a lot of paid softwares but I can't (and don't want to) spend any $$ right now... So, considering that I want very simple reports almost like a table with heading and subtotals, I should write it myself. But I don't know how (still...). I'm looking for tips, tutorials, ebooks... anything that explains how to make a very simply report. Regards, Pedro. Hello again, guys! I'm trying to do this: Get $user_ID -> SELECT FROM favorites WHERE user="$user_ID" -> Now I should create an array with the ID of all the results of the previous command -> SELECT FROM books WHERE genre="$favorites_ID" -> populate a html table. The part I've no idea about how to do is building an array with the results and then using the SELECT command, find in the other tables the match. Could you please give me a hand - one more time? HI, coming from a .net background and picking up php as I go along, I was wondering what the best way of designing the following task is in php. It's part of an appointmnet reminder app and the admin can amend the message that is sent out. The default message is currently stored in a db table and displayed in a multi line box on the admin web page. for example, "This is a an appointment reminder for *patient name*. You have an appointment on *date* with *customer name*." There's two parts relating to the message process. 1. Allowing the admin to amend the message (but ensuring the *variable markers* are left in tact, so I know where to stick the variables for part 2) 2. When the messages are being sent out (for each loop), inserting the *variables* into the message. I have no problem getting hold of the *name*, *date*, *customer* for each iteration in the for each loop. I'm sure people have done stuff like this before and in .net I would use a stringbuilder object but like i say, I'm not all that groovy on php at the mo. I was thinking of maybe a function that accepts thats passed the message, name, date, customer or something.. thanks Is it overkill to use PHP/MySQL to query my database, retrieve the universe of Questions, and then dynamically build a Form? I have a "Q&A Form" with a whopping 10 Questions. I suppose dynamically building the Form has the advantage that I always have the most up-to-date Questions and Question Text, but them again, if there is a database issue, I have a larger issue... Thoughts? Debbie Hello. I would like to build a survey that I can use on an iPad so that I can go out in the field and gather data from people. What would be the best way to accomplish this? I'm not sure what limitations even exist on an iPad - like can you have a webserver like MAMP? It seems to me that using something like Angular or whatever might make sense since you can build a working app all in one, but then I don't even know traditional Javascript. Just looking for a quick way to build something to allow me to survey people without making this a major project.\ Thanks. OK here is what I have going on right now. Currently I'm trying to build a excel spread sheet into a dynamic form via php. The results are basically questions and are stored each week so for one section they may be asking how many visitors, employee's , etc.. now some of these values that are being entered are going to be used in another question per-say but the result may come from other values that were already submitted so these questions would not be shown in the form that needs to be made later on. The form I'm having trouble with is the initial form to help generate the formula's for these different questions. So what I was going to start doing was have it list all the questions with a check box next to the question if the formula for said question was something like add these two questions and the divide by this set of questions or a whole number then it would display a list of questions for adding together and the get the total from that set and then do a expression afterwards like adding, subtracting, multiplying or dividing. So I was thinking I should list like a set of buttons I think in the beginning. What is the first task at hand Totaling, Adding, Subtracting, Dividing, Multiplying and then when they click on this it would refresh the page and bring up a box that lists all the different questions for them. Then saving the values as which ever button they clicked and once they do this. Then they could either click on say a more button which would pass the values as a array back to the page and continue on or they could click submit and pass the values into a db field as a formula but this is my first concept and would like to know if there may be a better way of doing it. Hiya peeps! I can't seem to build a preg_match pattern that works. This is what I need to do. "[" . $errorID . "]='HERE IS WHAT I NEED TO DISPLAY';" Does anyone have any ideas on how I would build this regex string? Many thanks, James. Hey PF. I'm trying to build some better coding habits, so what tips do you guys have? Of course there are obvious things such as well-commented code, neat structure, etc... But I'm looking for some more "TECHNICAL" tips that might be unspoken. For example, when is a good time to use a variable, opposed to a constant? I notice that a lot of programmers define their database settings with define(), while others just use a $variable. Is this personal preference or maybe its something I'm missing? I'm looking for ALL tips. Any information that you have, please share it. It will help make me (And anyone else reading this), a better coder. Thanks in advance. and if this is not the proper forum, please move it! =] How could I build an interactive text system? It should work like this: Text is displayed. 1-3 options (a situational amount of them) to answer displayed. Example: Are you male? Yes No You choose yes or no and it leads you to another questions based from your previous answer. Example: (a follow up to the 1st one) So you're male. Do you like cars then? Answers. And it goes on and on. The thing I need help with is the answers. I need to show them based by the previous answer but don't know how, any help? Ok so I'll try to explain what I'm trying to do the best I can. I want to build an array that allows me to add/remove/modify the variables used at any point in time without having to rebuild or rewrite a ton of new code. For example, below is an example list of variables I'd like to use in the array, followed by the code I would like to be automatically repeated. Example Variables: $materialName1, $materialName2, $materialName3, $materialName4, $materialName5, $materialName6 etc etc etc Example Code to repeat: Code: [Select] echo "<tr><td>Material: $materialName1</td><td>Rate: $materialName1Rate</td><td>Weight: $materialName1Weight</td></tr>"; Hopefully that makes sense. As always, very appreciated. This topic has been moved to Installation in Windows. http://www.phpfreaks.com/forums/index.php?topic=358758.0 Ok I basically want to build a simple php shopping cart. I already have a database with products and product IDs, and each product page has their product ID associated with it by asking the database for it's ID. Now how would I go about building a shopping cart? I already researched sessions and cookies and came to the conclusion that a session would be best since not all browsers use cookies or have them turned on. I how ever don't understand how to use sessions for a shopping cart. I know the first line the code in my php document has to have session_start(); How do I go about adding values to the session? I'm having an issue with building a multidimensional array via a for (....) the array should look like the example any help would be much, much appreciated thanks siouxx array ["username"] = "steve" array ["item"] = "12345" array "model" = "some model" "quantity" = "36.2" "details" array 0 = "detail 1" 1 = "detail 2" 2 = "detail 3" ["username"] = "steve" array ["item"] = "000257" array "model" = "some other model" "quantity" = "77.8" "details" array 0 = "detail 1" 1 = "detail 2" ["username"] = "bob" array ["item"] = "45678" array "model" = "other model" "quantity" = "99.5" "details" array 0 = "detail 1" 1 = "detail 2" 2 = "detail 3" 3 = "detail 3" the array return by sql looks like this Array ( => Array ( [id_prod] => 6 [id_tipo] => CPT [marca] => HP [modello] => Pavilion p6-200 [prezzo] => 599.00 [desc] => Computer da Tavolo [chiave] => 32 [utente] => steve [qta] => 1 [indata] => 2011-10-10 16:32:20 [dettaglio] => HD 320GB - RAM 4GB - Scheda audio 5.1 ) [1] => Array ( [id_prod] => 6 [id_tipo] => CPT [marca] => HP [modello] => Pavilion p6-200 [prezzo] => 599.00 [desc] => Computer da Tavolo [chiave] => 31 [utente] => steve [qta] => 1 [indata] => 2011-10-10 16:32:20 [dettaglio] => Intel Core i3-550 (3.20GHz, 4MB L3) This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=346015.0 I'm confused how to get the chat object to work with the pushes/pulls, and don't know where I'm going wrong. Here's the basics of what I need to know without reloading the page:
how do I push new data to the server
how do I push new data to the client
how do I not rebuild the data client has every time
I may need to know more, but that's what I know I need to be able to do so far.
|