Records duplicating

Hey guys, I am sure there is a simple solution to this but im not seeing it.

I am trying to select values from two tables to poplulate a menubar. Im getting the correct records but one of the records is duplicated 3 times, but there are not 3 duplicate records. here is the code:

[php]<?php

connect();

$query=“SELECT * FROM navbar, users WHERE (navbar.location=‘0’) OR (navbar.location=users.location AND users.username=’$_SESSION[myusername]’)”;
$result = mysql_query($query) or die($query."

".mysql_error());

while($row = mysql_fetch_array($result))
{

echo “

<a href='http://” . $row[‘url’] . “’>

” . $row[‘name’] . “

”;

}

mysql_close();

?>[/php]

navbar.location=‘0’ is the one thats producing 3 duplicate records, the other records come out fine.

The tables look something like this

table: navbar

ID Name URL Location
1

2 | email | www.u.com | 0 |

and table: users
------------------------------------------|

ID username password location
1
2
--------------------------------------------

Im basically making 2 homepages for 2 store locations. the buttons with location 0 will be on the navigation bars at both webpages. the buttons with location 1 will be for store A’s page and the buttons for store B are location 2.

Any pointers? thanks in advance!

heres how i got around it, though it isnt pretty. 2 querys and 2 while loops…please let me know if you see a better option, otherwise ill mark as solved.

[php]<?php

connect();

$query=“SELECT * FROM navbar, users WHERE (navbar.menu_id=users.location AND users.username=’$_SESSION[myusername]’)”;
$result = mysql_query($query) or die($query."

".mysql_error());

$query2=“SELECT * FROM navbar WHERE menu_id=‘0’”;
$result2 = mysql_query($query2) or die($query2."

".mysql_error());

while($row = mysql_fetch_array($result))
{
echo “

<a href='http://” . $row[‘url’] . “’>

” . $row[‘name’] . “

”;
}

while($row = mysql_fetch_array($result2))
{
echo “

<a href='http://” . $row[‘url’] . “’>

” . $row[‘name’] . “

”;
}

mysql_close();

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service