0

my problem is i want to JSON_ENCODE the result of inner join query and the two columns i want to select have the same name so, the JSON object override one of them and carry only data for one column cause they have the same name,,this is my code till now.

 $query = "select faculty.NAME,sector.NAME from faculty inner join sector
        on faculty.SECTOR_ID=sector.ID";
$result = mysql_query($query);
while($r = mysql_fetch_assoc($result)) {
$rows[] = $r;
 }
 echo json_encode($rows);

how to do this without change the column name in the DataBase...

3 Answers 3

1

Try changing the output of your query:

select faculty.NAME AS facultyName,sector.NAME AS sectorName from faculty inner join sector
    on faculty.SECTOR_ID=sector.ID
Sign up to request clarification or add additional context in comments.

Comments

1

Using as:

select faculty.NAME as faculty_name, sector.NAME as sector_name from faculty inner join sector
    on faculty.SECTOR_ID=sector.ID

This will change your json values to something like:

{"faculty_name": "first", "sector_name": "second"}

so you will need to update your javascript.

Comments

0

You can use ALIAS In your query so you will have different names for your columns

select faculty.NAME as faculty_name ,sector.NAME as sector_name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.