Jump to content

[SOLVED] Displays right records, but multiplied by 10


40esp

Recommended Posts

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!

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

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.

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.

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.