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

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.