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";              
	}
?>

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";              
	}
?>

I don't know why this works, but removing the SORT BY part of the SELECT query stopped the duplication. If anyone understands this I'd like to know why, but I'm marking the thread solved for the time being.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.