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!

Link to comment
Share on other sites

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.

 

email1@email1.com email2@email2.com email3@email3.com email1@email1.com email2@email2.com email3@email3.com email1@email1.com email2@email2.com email3@email3.com email1@email1.com email2@email2.com email3@email3.com email1@email1.com email2@email2.com email3@email3.com email1@email1.com email2@email2.com email3@email3.com email1@email1.com email2@email2.com email3@email3.com email1@email1.com email2@email2.com email3@email3.com email1@email1.com email2@email2.com email3@email3.com .... etc..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.