40esp Posted June 8, 2008 Share Posted June 8, 2008 Im using this code to retrieve values from mysql: <?php $n = 4; mysql_select_db($database_sw, $sw); $query_Recordset1 = "SELECT * FROM newsletters INNER JOIN practice_groups ON newsletters.practice_groups LIKE '%[".$n."]%'"; $Recordset1 = mysql_query($query_Recordset1, $sw) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); while($signups = mysql_fetch_assoc($Recordset1)) { echo $signups['email']; } ?> but it repeates the right records like 10 times. I think its my sql. how would i fix it? Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/109321-solved-displays-right-records-but-multiplied-by-10/ Share on other sites More sharing options...
pocobueno1388 Posted June 8, 2008 Share Posted June 8, 2008 Take this line out $row_Recordset1 = mysql_fetch_assoc($Recordset1); Are there multiple rows with the same emails in that table? If so, you can use DISTINCT. Quote Link to comment https://forums.phpfreaks.com/topic/109321-solved-displays-right-records-but-multiplied-by-10/#findComment-560754 Share on other sites More sharing options...
40esp Posted June 8, 2008 Author Share Posted June 8, 2008 That wouldn't do it though. The $row_Recordset1 is just a variable, its not displaying any data, The While statement is displaying the data. I have 5 records, and only 3 will be displayed based on the variable, but instead of showing three: and it does something like this: it picks the right records I want, but displays it 10 times. [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] .... etc.. Quote Link to comment https://forums.phpfreaks.com/topic/109321-solved-displays-right-records-but-multiplied-by-10/#findComment-560767 Share on other sites More sharing options...
.josh Posted June 8, 2008 Share Posted June 8, 2008 Take this line out $row_Recordset1 = mysql_fetch_assoc($Recordset1); Are there multiple rows with the same emails in that table? If so, you can use DISTINCT. I believe he was telling you two different things. 1) take that line out. while it's just a variable, it calls mysql_fetch_assoc, which will push the internal pointer up a notch in your result source, making you miss the first one in your while loop. 2) the problem is in your query string, as your loop is fine. I'd look into that DISTINCT. Quote Link to comment https://forums.phpfreaks.com/topic/109321-solved-displays-right-records-but-multiplied-by-10/#findComment-560782 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 The distinct does not change anything, it still multi displays. I think the problem is the INNER JOIN and LIKE together in my statement. It might return the same number of rows as the joined column, but with multiple data. But I dont know how to fix it. Quote Link to comment https://forums.phpfreaks.com/topic/109321-solved-displays-right-records-but-multiplied-by-10/#findComment-560787 Share on other sites More sharing options...
.josh Posted June 9, 2008 Share Posted June 9, 2008 how about trying a group by? I suck at sql I'll forward your thread to the sql forum they'd be able to help out better. Quote Link to comment https://forums.phpfreaks.com/topic/109321-solved-displays-right-records-but-multiplied-by-10/#findComment-560791 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 Thank you =] Quote Link to comment https://forums.phpfreaks.com/topic/109321-solved-displays-right-records-but-multiplied-by-10/#findComment-560792 Share on other sites More sharing options...
40esp Posted June 9, 2008 Author Share Posted June 9, 2008 I got it!! I put some parenthesis in to diferentiate. Thanks to everyone! Quote Link to comment https://forums.phpfreaks.com/topic/109321-solved-displays-right-records-but-multiplied-by-10/#findComment-560795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.