I've not found any MYSQL many-to-many associations good examples here as well as in google. Things I am searching would be to see a simple example with php+mysql showing database's results. Can anybody write a simple example?

Example scenario: students and courses in a college. Confirmed student may be on several courses, not to mention a training course will often have numerous students.

Example tables, simple design:

CREATE TABLE `Student` (
    `StudentID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `FirstName` VARCHAR(25),
    `LastName` VARCHAR(25) NOT NULL,
    PRIMARY KEY (`StudentID`)
) ENGINE=INNODB CHARACTER SET utf8 COLLATE utf8_general_ci

CREATE TABLE `Course` (
    `CourseID` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `Code` VARCHAR(10) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
    `Name` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`CourseID`)
) ENGINE=INNODB CHARACTER SET utf8 COLLATE utf8_general_ci

CREATE TABLE `CourseMembership` (
    `Student` INT UNSIGNED NOT NULL,
    `Course` SMALLINT UNSIGNED NOT NULL,
    PRIMARY KEY (`Student`, `Course`),
    CONSTRAINT `Constr_CourseMembership_Student_fk`
        FOREIGN KEY `Student_fk` (`Student`) REFERENCES `Student` (`StudentID`)
        ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT `Constr_CourseMembership_Course_fk`
        FOREIGN KEY `Course_fk` (`Course`) REFERENCES `Course` (`CourseID`)
        ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=INNODB CHARACTER SET ascii COLLATE ascii_general_ci

Find a lot of students registered for any course:

SELECT
    `Student`.*
FROM
    `Student`
    JOIN `CourseMembership` ON `Student`.`StudentID` = `CourseMembership`.`Student`
WHERE
    `CourseMembership`.`Course` = 1234

Find all courses taken with a given student:

SELECT
    `Course`.*
FROM
    `Course`
    JOIN `CourseMembership` ON `Course`.`CourseID` = `CourseMembership`.`Course`
WHERE
    `CourseMembership`.`Student` = 5678

Here is a fast and dirty illustration of the SQL involved. I do not use whatever have to muddy in the concept with php. Just retrieve the set as if you would every other.

Within this example, you will find many names, and several colors. Individuals are permitted to possess several favorite color, and several people can have a similar favorite color. Hence many to a lot of.


***** Tables **********

person
--------
id - int 
name - varchar

favColor
-------------
id - int 
color - varchar

person_color
------------
person_id - int (matches an id from person)
color_id - int (matches an id from favColor)



****** Sample Query ******

SELECT name, color 
FROM person 
    LEFT JOIN person_color ON (person.id=person_id)
    LEFT JOIN favColor ON (favColor.id=color_id)


****** Results From Sample Query *******

Name - Color
---------------
John - Blue
John - Red
Mary - Yellow
Timmy - Yellow
Suzie - Green
Suzie - Blue
etc...

Does which help?