Wildhalf Posted January 21, 2010 Share Posted January 21, 2010 $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 More sharing options...
teamatomic Posted January 22, 2010 Share Posted January 22, 2010 Because your keys are numerical not alpabetical so $array['i'] means nothing. Why not try it with the 'i' as a variable, $i? HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/189357-whats-up-with-my-for-loop/#findComment-999663 Share on other sites More sharing options...
MatthewJ Posted January 22, 2010 Share Posted January 22, 2010 And you should be getting 5 results not 4 Link to comment https://forums.phpfreaks.com/topic/189357-whats-up-with-my-for-loop/#findComment-999667 Share on other sites More sharing options...
Andy-H Posted January 22, 2010 Share Posted January 22, 2010 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 https://forums.phpfreaks.com/topic/189357-whats-up-with-my-for-loop/#findComment-999680 Share on other sites More sharing options...
rajeevbharti Posted January 22, 2010 Share Posted January 22, 2010 hi friend u use $i in place of i in-- $aff_member_sales = $get_number_sales[number_sales]; $aff_member_email = $get_number_sales[aff_email]; echo $aff_member_sales; echo '<Br>'; echo $aff_member_email; echo '<Br>'; Link to comment https://forums.phpfreaks.com/topic/189357-whats-up-with-my-for-loop/#findComment-999789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.