여기에 내가 4 개 개의 테이블는 MySQL의 표는
다음SELECT DISTINCT c.title as CourseTitle, t.title as TopicTitle, l.title as LessonTitle, r.title as ResourceTitle, r.location, r.type, r.duration
FROM j17_lessons l, j17_topics t, j17_courses c, j17_resources r
WHERE
CONCAT(c.title, t.title, l.title, r.title, r.type, r.location) LIKE '%Fatih%'
AND c.id = t.course_id
AND l.topic_id = t.id
AND r.lesson_id = l.id
ORDER BY c.title, t.id, l.id, r.id;
에서 MySQL의 결과를 가져 오기 위해 사용하고 내 코드입니다의 스크린 샷을 내 가져 오기 이제 http://i40.tinypic.com/2v1w0ib.png
결과 열 이름으로 결과를 필터링 가입 무엇 나는 각각의 'CourseTitle'에 대한 HTML 테이블을 데이터베이스에 생성 할 필요가있다.
내가 첫 번째 쿼리에 대한 결과를 얻을 수있는 SQL 문 및 PHP 코드를 사용하지만 난 분할 두 번째 질의를 필요로한다 테이블 foreach는 'CourseTitle'
/* connect to the db */
$connection = mysql_connect('localhost','root','123');
mysql_select_db('alhudapk',$connection);
/* show tables */
$result = mysql_query('SELECT DISTINCT c.title as CourseTitle, t.title as TopicTitle, l.title as LessonTitle, r.title as ResourceTitle, r.location, r.type, r.duration
FROM j17_lessons l, j17_topics t, j17_courses c, j17_resources r
WHERE
CONCAT(c.title, t.title, l.title, r.title, r.type, r.location) LIKE '%Taleem%'
AND c.id = t.course_id
AND l.topic_id = t.id
AND r.lesson_id = l.id
ORDER BY c.title, t.id, l.id, r.id',$connection) or die('cannot show tables');
while($tableName = mysql_fetch_row($result)) {
$table = $tableName[0];
echo '<h3>',$table,'</h3>';
$result2 = mysql_query('SELECT '.$table . 'AS' .$table);
if(mysql_num_rows($result2)) {
정확하고 더 나은 코드
디자인에 테이블/필드 이름을 다른 필드에 저장해야하는 경우 디자인을 다시 작성해야합니다. 그것은 매우 빨리 엉망이 될 것입니다. –