Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8956969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:53:02+00:00 2026-06-15T14:53:02+00:00

I’m having a problem my code. The mysql_fetch_array output repeating same value. This is

  • 0

I’m having a problem my code. The mysql_fetch_array output repeating same value. This is my code :

$sql= "SELECT client.resID AS resID, client.resName AS resName, menu.id AS mid, menu.name AS mname, facilities.name AS fname, facilities.id AS fid FROM client INNER JOIN menu ON client.resID = menu.resID INNER JOIN facilities ON client.resID = facilities.resID WHERE client.resID =".$_GET["resID"];
$rs = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());



while ($f = mysql_fetch_array($rs)) { // loop as long as there are more results
    $names[] = $f['mname'];  // push to the array

print_r($names)

}

Let’s say a restaurant have rice and potato. The print_r($names) are returning :

Array ( [0] => rice [1] => potato [2] => rice [3] => potato [4] => rice [5] => potato [6] => rice [7] => potato [8] => rice [9] => potato ) 

How could I solve this problem? Really appreciate your help 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:53:03+00:00Added an answer on June 15, 2026 at 2:53 pm

    Your query

    SELECT client.resID AS resID, client.resName AS resName,
           menu.id AS mid, menu.name AS mname,
           facilities.name AS fname, facilities.id AS fid 
    FROM client
    INNER JOIN menu ON client.resID = menu.resID
    INNER JOIN facilities ON client.resID = facilities.resID
    WHERE client.resID =".$_GET["resID"]
    

    returns as many occurences of “rice” as many times as the other two tables match. Since you are joining on the column set by WHERE, your query is effectively a cartesian product of the three joined tables (after filtering by resID).

    ex.:

    john rice fac1
    john meat fac1
    john rice fac2
    john meat fac2
    ...
    

    Perhaps you wanted to make three separate queries, one for each table

    SELECT mid, mname FROM menu WHERE resID = $resID
    

    Or maybe you wanted to join on some other column (say, one that is unique in all three tables)?

    SELECT ...
    FROM client
    INNER JOIN menu ON client.resID = menu.id
    INNER JOIN facilities ON client.resID = facilities.id
    

    also note that including unescaped get parameters in the query string is dangerous, even if you expect numbers. Use mysqli prepared statements or (at least) mysql_real_escape_string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.