hello, i am trying to create a script to generate a downline report for a multilevel marketing system. i was capable of pulling the personally sponsored distributors, but all the other ones are processed on the fly within the program which is called Market Power. there are no distinct fields to just pull the other distributors out and i was wondering if anyone could possibly help me out with this. the other guy who was helping me work on this project just went on vacation. he gave me a basic layout of what needs to be done, but i am fairly new to php and do not understand all of his terminology.
basically he told me to run a query on all users who have the logged in distributors ID in the sponsor field. he said to store only the IDs and put it in an array called next_level. So, I am running a query(quite simple) like this:
$query1 = "SELECT dm_id FROM distributor_main
WHERE (dm_sponsor2_id) ='".$valid_user."'";
his next step is...before running a query on $next_level set $current_level to $next_level and then repeat (for...each loop) going through all $current_level WITHOUT removing $next_level values. the for...each loop must run a total of 6 times (6
levels) and stop.
after those queries are run, then pull out the ID#s from the $next_level
array and display the appropriate fields needed (name, monthly sales, etc...)
the only parts i am confused with is the array and the placement of the for each loop. i've never used a for each loop and i am not sure how it works. here is the code i was using for diplaying just the personally sponsored distributors:
<?
session_start();
// include function files for this application
require_once("candle_fns.php");
if ($username && $passwd)
// they have just tried logging in
{
if (login($username, $passwd))
{
// if they are in the database register the user id
$valid_user = $username;
session_register("valid_user");
}
else
{
// unsuccessful login
do_html_header("Problem:");
echo "You could not be logged in.
Your password was probably entered incorrectly.<BR>
(Passwords are case sensitive.) Please try again.";
do_html_url("login.php", "Login");
do_html_footer();
exit;
}
}
check_valid_user();
// get the bookmarks this user has saved
//if ($url_array = get_user_urls($valid_user));
// display_user_urls($url_array);
userdbConnect();
function display_search_results($query)
{
$result = userdbExec($query);
if(!odbc_fetch_into($result, $row))
echo "No match found!<HR>";
else
{
?>
<TABLE cellspacing="5" cellpadding="5"><tr><td><b><u>ID</u></b></TD><td><b><u>Distributor Name</u></b></TD><td><b><u>Title</u></b></TD><td><b><u>Phone</u></b></TD><td><b><u>Start Date</u></b></TD><td><b><u>Period Sales</u></b></TD></TR>
<?
do{
print("<tr><td>" . $row[0] . "</td>");
print("<td>" . $row[1] . " " . $row[2] . "</td>");
print("<td>" . $row[3] . "</td>");
print("<td>" . $row[4] . "</td>");
print("<td>" . $row[5] . "</td>");
print("<td>$".number_format($row[6],2)."</td></tr>");
}
while(odbc_fetch_into($result, $row));
}
}
function display_total($query2)
{
$result = userdbExec($query2);
if(!odbc_fetch_into($result, $row))
echo "No match found!<HR>";
else
{
do{
print("<tr><td><td><td><td><td><b>Total</b> <td>$".number_format($row[7],2)."</td></td></td></td></td></td></tr></table>");
}
while(odbc_fetch_into($result, $row));
print("</table><HR>");
}
}
do_unlinked_html_header("Downline Genealogy Report");
/* Search */
echo "Genealogy Downline Report Search for Distributor ID <b>" . $valid_user . "</b><BR>";
$query = "SELECT dm_id, dm_first_name, dm_last_name, di_pay_title, dm_phone, di_start_date, di_period_sales FROM distributor_main, distributor_sales
WHERE (dm_sponsor2_id) ='".$valid_user."' AND distributor_sales.di_id = distributor_main.dm_id";
display_search_results($query);
$query2 = "SELECT dm_id, dm_first_name, dm_last_name, di_pay_title, dm_phone, di_start_date, di_period_sales, SUM(di_period_sales) FROM distributor_main, distributor_sales
WHERE (dm_sponsor2_id) ='".$valid_user."' AND distributor_sales.di_id = distributor_main.dm_id";
display_total($query2);
do_html_URL("member.php", "Return to the Main Menu");
do_html_footer();
userdbClose();
?>
if anyway could help me out, i would greatly appreciate it.