Lets say i fill in the form with the following values:
1
1
32
When i hit the submit button it will then take me to a page and will run the following MySQL query.
$query="INSERT INTO affleads VALUES ('$AffID','$ProID')";
But how would i run the MySQL query a number of times depending on what was entered in the NumberOfLeads field, for example i enter 32 then that Query will be ran 32 times.
Thanks for your comment, i know about that already, but the problem is i dont understand how to do it so if 32 is entered it adds the data in 32 times or if i enter 15 in then it only enters the data in 15 times.
Something like this should do it - off top of my head so untested:
$numberOfLeads = (int)$_POST['numberOfLeads']; // pickup from the form data and clean it
// I don't know if these are ints so change if they are strings - use mysql_real_escape_string()
$affId = (int)$_POST['affId'];
$proId = (int)$_POST['proId'];
// begin the SQL str build
$sql = 'INSERT INTO affleads VALUES';
$first = true; // needed to know when to use the comma in query
// loop x number of times
for($i=0; $i<$numberOfLoads; $i++)
{
$comma = $first ? ',' : ''; // use the comma or not? on first time, don't use it
$sql .= "$comma ('$affId', '$proId')";
$first = false;
}
// you now have the query in $sql ready to use with mysql_query()
We need it to be like this, I’m creating an affiliate tracking platform and each 1 is classed as a lead. Its how i have coded everything and how everything works. That is the reason why i need to add the same records as each 1 is classed as a lead.
Rewriting so you do this the ‘right’ way will be a lot easier at this earlier stage than it will be when your application starts to get some serious usage. I would really recommend biting the bullet and doing your rewriting now. Otherwise, you’ll end up with a system which becomes increasingly difficult to manage.
How does the 32 come into play? Does someone say I want 32 leads, then these leads are made available to the publishers? Wouldn’t only qualified leads reduce the 32? You could have loads of incomplete records, taking up space/processing, until these have been completed.
I know we’re going a bit off-topic here, and you’re not necessarily after addressing this.
No this is the Admin side of things im in the middle of creating, for example let say for some strange reason leads where not tracked (because the cookies where deleted) we will still be able to see from our clients how many leads affiliates have brought in and if we see in our system there are less leads then we add more leads to the affiliates account (earning them more cash).
You understand how affiliate networks work right? AffiliateWindow, TradeDoubler, CJ etc…
So you’ll add the extra details to each of the 32 rows you added at some point later in the admin system? In which case, my 12:10 should do what you want