Jump to content

Cleaning my code


onlyican

Recommended Posts

Hey

I built this little code, but I am not happy with the number of queries and loops

[code]
<?php
$query2 = "SELECT * FROM aff_sales WHERE paid = 'n' GROUP BY aff";
$result2 = mysql_query($query2);

while($row2 = mysql_fetch_assoc($result2)){
$payments = "";
$query5 = "SELECT id_num FROM aff_sales WHERE paid = 'n' and aff = '".$row2["aff"]."'";
$result5 = mysql_query($query5);
while($row5 = mysql_fetch_assoc($result5)){
$payments .= $row5["id_num"]."_";
}
$total_pay = mysql_result(mysql_query("SELECT SUM(amount) FROM aff_sales WHERE paid = 'n' AND aff = '".$row2["aff"]."'"),0);
echo "For Aff id ".$row2["aff"]."<br />\n";


$query4 = "SELECT * FROM affiliates WHERE id_num = '".$row2["aff"]."'";
$result4 = mysql_query($query4);
while($row4 = mysql_fetch_assoc($result4)){
$name = $row4["name"];
$email_to = $row4["email"];
}

echo $name." is owed \$".$total_pay." this much money, Click pay to pay them, or update if you have paid them.<br />";
echo "<form method='post' action='confirm.php'>\n"
."<input type='hidden' name='email' value='".$email_to."' />\n"
."<input type='hidden' name='amount' value='".$total_pay."' />\n"
."<input type='hidden' name='payments' value='".$payments."' />\n"
."<input type='submit' value='Pay' />\n"
."</form>\n"
."<a href='".$_SERVER['PHP_SELF']."?paid=".$row2["aff"]."'>Click here when you have Paid</a><br /><br />\n";


}
?>
[/code]

Now let me explain a little about the tables

table aff_sales:
When ever someone buys something, and there is an affiliate behind this (using cookies OR IP_add)
The info of there comission is added to the table
The table goes something like this

id_num (int50) autoincrement Primary
aff (int50)
amount (double 5,2)
sold_on (DateTime)
paid(enum 'y','n'


Table affiliates:
This is the user information basicly
id_num (int50) auto increment, primary (This is the ID number used aff_sales.aff)
name
email
url
country
pwd
reg_on
level

I am not going through info on each one, there all basic and not related.

So


The goal of the page is to show the Admin when he logs in, who is owed money, and how much.
He then clicks a button, and this will open a new page going to paypal Send money, completing the form
Then a button will show saying click her when payment is successful.

What I want to do is make the code cleaner, less mysql calls, and less loops.
I am thinking if there are 20 people who is owed money, thats a lot of MySQL calls and Loops

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.