Jump to content

Whats up with my for loop


Wildhalf

Recommended Posts

$sponsor_email is an array of 4 email addresses assigned $sponsor_email[0], $sponsor_email[1], $sponsor_email[2], $sponsor_email[3], $sponsor_email[4]

 

If i replace the i in $sponsor_email with either 1,2,3,4 it displays the right result for each mail 4 times.

 

Does anyone know why the for lop isnt working with the i in the select statement......

 

for ($i = 0; $i <= 4; $i++) {
$get_number_sales_sql = "SELECT * FROM worthatry_spon WHERE aff_email = '$sponsor_email[i]'";
$get_number_sales_res = mysql_query($get_number_sales_sql) or die("An internal error has occured!<br />Unable to run the following query:<br /><pre>" . $qry. "</pre><br /><br />" . mysql_error());
$get_number_sales = mysql_fetch_array($get_number_sales_res);	

$aff_member_sales[i] = $get_number_sales[number_sales];
$aff_member_email[i] = $get_number_sales[aff_email];

echo $aff_member_sales[i];
echo '<Br>';
echo $aff_member_email[i];
echo '<Br>';
}	

Link to comment
https://forums.phpfreaks.com/topic/189357-whats-up-with-my-for-loop/
Share on other sites

Could you not just use

 

   $get_number_sales_sql = "SELECT number_sales, aff_email FROM worthatry_spon LIMIT 4";
   $get_number_sales_res = mysql_query($get_number_sales_sql) or die("An internal error has occured!<br />Unable to run the following query:<br /><pre>" . $qry. "</pre><br /><br />" . mysql_error());
   while ($get_number_sales = mysql_fetch_row($get_number_sales_res)) {   
   
   echo $get_number_sales[0];
   echo '<br >'."\n";
   echo $get_number_sales[1];
   echo '<br >'."\n";
}   

That is of course assuming that you don't need to select specific data that can't be achieved by MySQL functions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.