tartou2 Posted December 29, 2010 Share Posted December 29, 2010 Hello again I have now this code and for some reason it is only showing the first 2 user ids. It echo this 1 2 <?php session_start(); require '../include/connect.php'; $today_date=gmstrftime("%b %d, %Y"); $check=mysql_query("select * from members where status='active'"); while($row=mysql_fetch_array($check)) { echo $member_id=$row['member_id']." "; $username=$row['username']; $balance=$row['balance']; $email=$row['member_email']; $first_name=$row['member_name']; $last_name=$row['lastname']; function report($member_id,$username,$balance,$email,$first_name,$last_name) { $check=mysql_query("select sum(amount) as amount from deposit where member_id=$member_id and status!='not_paid'"); $row=mysql_fetch_array($check); $total_amount_invested=$row['amount']; $total_account_balance=$balance+$total_amount_invested; $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='intrest_earned'"); $row=mysql_fetch_array($check); $total_interests_earned=$row['amount']; $total_interests_earned=round($total_interests_earned,2); $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='withdrawal'"); $row=mysql_fetch_array($check); $total_withdrawl_amount=$row['amount']; $total_withdrawl_amount=round($total_withdrawl_amount,2); $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='commissions'"); $row=mysql_fetch_array($check); $total_commission=$row['amount']; $total_commission=round($total_commission,2); $subject = "Weekly report"; $headers="From: Test<noreply@test.com> \r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "MIME-Version: 1.0\r\n"; $mmessage = "Dear $first_name $last_name, <p /> Below, please find your current account data and interest earned for the last week. <p /> You account name: <font color=blue>$username</font> <br /> Current account balance: <font color=blue>$balance</font> <br /> Invested account balance: <font color=blue>$total_amount_invested</font> <br /> Total account balance: <font color=blue>$total_account_balance</font> <br /> Total profit: <font color=blue>$total_interests_earned</font> <br /> Total withdrawn: <font color=blue>$total_withdrawl_amount</font> <br /> Total referral commision: <font color=blue>$total_commission</font> <p /> This report was generated on $today_date <p /> Sincerely Yours, <p /> ----------------------------- <br /> - This is an automated message. Please do not reply for any reason."; //mail($email, $subject, $mmessage, $headers); } report($member_id,$username,$balance,$email,$first_name,$last_name); } ?> This is the whole code, how to fix this problem and make all activated accounts id to show Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/ Share on other sites More sharing options...
Maq Posted December 29, 2010 Share Posted December 29, 2010 Your code should be producing a fatal error. You have a while block wrapped around a function definition. Are you sure there are more accounts in your db with status='active'? Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152719 Share on other sites More sharing options...
litebearer Posted December 29, 2010 Share Posted December 29, 2010 simple test of content <?php session_start(); require '../include/connect.php'; $result=mysql_query("select * from members"); while($row = mysql_fetch_array($result) { echo $row['member_id'] . " - " $row['status'] . "<br>"; } exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152722 Share on other sites More sharing options...
tartou2 Posted December 30, 2010 Author Share Posted December 30, 2010 simple test of content <?php session_start(); require '../include/connect.php'; $result=mysql_query("select * from members"); while($row = mysql_fetch_array($result) { echo $row['member_id'] . " - " $row['status'] . "<br>"; } exit(); ?> you forgot to put a ")" at the end of the while but anyway this is what was echoed 1 - active 2 - active 3 - active 4 - active 5 - active 6 - active 7 - active 8 - active 9 - new 10 - active 122 - active 123 - active 124 - new 125 - active 126 - active 127 - active 128 - active 129 - active 130 - active 131 - active 132 - active 133 - active 134 - active 135 - active 136 - active 137 - active 138 - active 139 - active 140 - active 141 - new 142 - active 143 - active 144 - new Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152931 Share on other sites More sharing options...
tartou2 Posted December 30, 2010 Author Share Posted December 30, 2010 Your code should be producing a fatal error. You have a while block wrapped around a function definition. Are you sure there are more accounts in your db with status='active'? yes i have look at the previous post Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152932 Share on other sites More sharing options...
trq Posted December 30, 2010 Share Posted December 30, 2010 Did you read the.... You have a while block wrapped around a function definition. part? Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152934 Share on other sites More sharing options...
tartou2 Posted December 30, 2010 Author Share Posted December 30, 2010 yes i did but even if i remove the function, the script will only echo the first id. so the problem exist in both cases. Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152937 Share on other sites More sharing options...
litebearer Posted December 30, 2010 Share Posted December 30, 2010 just moved things around, try this... <?php session_start(); require '../include/connect.php'; $today_date=gmstrftime("%b %d, %Y"); /* define function here */ function report($member_id,$username,$balance,$email,$first_name,$last_name) { $check=mysql_query("select sum(amount) as amount from deposit where member_id=$member_id and status!='not_paid'"); $row=mysql_fetch_array($check); $total_amount_invested=$row['amount']; $total_account_balance=$balance+$total_amount_invested; $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='intrest_earned'"); $row=mysql_fetch_array($check); $total_interests_earned=$row['amount']; $total_interests_earned=round($total_interests_earned,2); $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='withdrawal'"); $row=mysql_fetch_array($check); $total_withdrawl_amount=$row['amount']; $total_withdrawl_amount=round($total_withdrawl_amount,2); $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='commissions'"); $row=mysql_fetch_array($check); $total_commission=$row['amount']; $total_commission=round($total_commission,2); $subject = "Weekly report"; $headers="From: Test<noreply@test.com> \r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "MIME-Version: 1.0\r\n"; $mmessage = "Dear $first_name $last_name, <p /> Below, please find your current account data and interest earned for the last week. <p /> You account name: <font color=blue>$username</font> <br /> Current account balance: <font color=blue>$balance</font> <br /> Invested account balance: <font color=blue>$total_amount_invested</font> <br /> Total account balance: <font color=blue>$total_account_balance</font> <br /> Total profit: <font color=blue>$total_interests_earned</font> <br /> Total withdrawn: <font color=blue>$total_withdrawl_amount</font> <br /> Total referral commision: <font color=blue>$total_commission</font> <p /> This report was generated on $today_date <p /> Sincerely Yours, <p /> ----------------------------- <br /> - This is an automated message. Please do not reply for any reason."; //mail($email, $subject, $mmessage, $headers); } /* END OF FUNCTION DEFINITION */ $check=mysql_query("select * from members where status='active'"); while($row=mysql_fetch_array($check)) { $member_id=$row['member_id']; echo $member_id . "<br>"; $username=$row['username']; $balance=$row['balance']; $email=$row['member_email']; $first_name=$row['member_name']; $last_name=$row['lastname']; report($member_id,$username,$balance,$email,$first_name,$last_name); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152941 Share on other sites More sharing options...
tartou2 Posted December 30, 2010 Author Share Posted December 30, 2010 just moved things around, try this... <?php session_start(); require '../include/connect.php'; $today_date=gmstrftime("%b %d, %Y"); /* define function here */ function report($member_id,$username,$balance,$email,$first_name,$last_name) { $check=mysql_query("select sum(amount) as amount from deposit where member_id=$member_id and status!='not_paid'"); $row=mysql_fetch_array($check); $total_amount_invested=$row['amount']; $total_account_balance=$balance+$total_amount_invested; $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='intrest_earned'"); $row=mysql_fetch_array($check); $total_interests_earned=$row['amount']; $total_interests_earned=round($total_interests_earned,2); $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='withdrawal'"); $row=mysql_fetch_array($check); $total_withdrawl_amount=$row['amount']; $total_withdrawl_amount=round($total_withdrawl_amount,2); $check=mysql_query("select sum(amount) as amount from history where user_id=$member_id and type='commissions'"); $row=mysql_fetch_array($check); $total_commission=$row['amount']; $total_commission=round($total_commission,2); $subject = "Weekly report"; $headers="From: Test<noreply@test.com> \r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "MIME-Version: 1.0\r\n"; $mmessage = "Dear $first_name $last_name, <p /> Below, please find your current account data and interest earned for the last week. <p /> You account name: <font color=blue>$username</font> <br /> Current account balance: <font color=blue>$balance</font> <br /> Invested account balance: <font color=blue>$total_amount_invested</font> <br /> Total account balance: <font color=blue>$total_account_balance</font> <br /> Total profit: <font color=blue>$total_interests_earned</font> <br /> Total withdrawn: <font color=blue>$total_withdrawl_amount</font> <br /> Total referral commision: <font color=blue>$total_commission</font> <p /> This report was generated on $today_date <p /> Sincerely Yours, <p /> ----------------------------- <br /> - This is an automated message. Please do not reply for any reason."; //mail($email, $subject, $mmessage, $headers); } /* END OF FUNCTION DEFINITION */ $check=mysql_query("select * from members where status='active'"); while($row=mysql_fetch_array($check)) { $member_id=$row['member_id']; echo $member_id . "<br>"; $username=$row['username']; $balance=$row['balance']; $email=$row['member_email']; $first_name=$row['member_name']; $last_name=$row['lastname']; report($member_id,$username,$balance,$email,$first_name,$last_name); } ?> yeahhhh you're the man bro The code works perfectly Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152945 Share on other sites More sharing options...
tartou2 Posted December 30, 2010 Author Share Posted December 30, 2010 but the messages are sent to the spambox. Any idea on how to make it goes to the inbox ? Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152947 Share on other sites More sharing options...
trq Posted December 30, 2010 Share Posted December 30, 2010 You really should look at moving allot of those queries into one. Your code is ridiculously inefficient. Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152949 Share on other sites More sharing options...
tartou2 Posted December 30, 2010 Author Share Posted December 30, 2010 You really should look at moving allot of those queries into one. Your code is ridiculously inefficient. yes i know i am not a professional with php coding but i am doing my best. Would you mind helping me with making one queries for all those queries ? because I don't know how to do it Quote Link to comment https://forums.phpfreaks.com/topic/222938-need-help-with-this/#findComment-1152952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.