Jump to content

Unwanted duplication in Array


facarroll

Recommended Posts

Hi everyone,

I don't know whether this is a PHP or MySql problem, but I think it is the former. The following code queries the database correctly, (and before you ask, there are no duplicate database entries), but the output duplicates every row. e.g.,

 

hammer (jpg image)

hammer

hammer (jpg image)

hammer

saw (jpg image)

saw

saw (jpg image)

saw

screwdriver (jpg image)

screwdriver

screwdriver (jpg image)

screwdriver

 

and so on.

I cannot see why the code causes the row to repeat.

 

<?php session_start(); 
if (isset($_SESSION['id'])) 
{
	// Put stored session variables into local php variable
    	$id   = $_SESSION['id'];
    	$userId = $_SESSION['userId'];
	$userGroup = $_SESSION['userGroup'];
	$managerId = $_SESSION['managerId'];	
}
include_once("demo_conn.php"); 
$sql = mysql_query("SELECT * FROM users WHERE id='$id'"); 
while($row = mysql_fetch_array($sql))
    { 
        // Get member data into a session variable
        $egroup = $row["egroup"];   
        session_register('egroup'); 
        $_SESSION['egroup'] = $egroup;
}				  
$query = mysql_query("SELECT topics.url_big, topics.url_small, topics.title, topics.$egroup, quiz.passState, quiz.userDate FROM topics INNER JOIN quiz ON (topics.managerId = quiz.managerId) WHERE topics.$egroup = 1 ORDER BY title ASC"); 
while ($row1 = mysql_fetch_array($query))
{
echo "<a href='../../wood/wood_tool_images/{$row1['url_big']}' target='_blank'><img src='../../wood/wood_tool_images/{$row1['url_small']}' /><br />\n"; 
echo "{$row1['title']} <br />\n";              
}
?>

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.