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 7745203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:57:17+00:00 2026-06-01T09:57:17+00:00

here is my code i am using to fetch mysql result from 4 different

  • 0

here is my code i am using to fetch mysql result from 4 different tables

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;

Here is screen shot of my fetch result
http://i40.tinypic.com/2v1w0ib.png

Now what i need is to create a HTML Tables for each ‘CourseTitle’ in database.

Using SQL statement and PHP Code i can get result for first query but i need a second query to split table 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)) {

Please guide me to build a correct and better code

  • 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-01T09:57:18+00:00Added an answer on June 1, 2026 at 9:57 am

    What I would do is put the database results into a big array structure with the data arranged in the same sort of order it should be printed out. This makes maintaining the code a bit easier.

    // run the query as you did in the question
    
    $courses = array();
    
    // use mysql_fetch_assoc as it makes the code clearer
    while($row = mysql_fetch_assoc($result)) {
        $ct = $row['CourseTitle'];
        // Found a new Course Title? If so create an array to put the data rows in
        if(!isset($courses[$ct]))
            $courses[$ct] = array();
    
        // add this row to the end of its course array
        $courses[$ct][] = $row;
    }
    
    // now print the results out
    foreach($courses as $title =>$course) {
        echo "<h3>$title</h3>";
        echo "<table>";
        foreach($course as $line) {
            echo "<tr><td>" . $line['TopicTitle'] . "</td><td>" 
                 . $line['LessonTitle'] . "</td></tr>";
        echo "</table>";
    }
    

    The code above is only printing out the first 2 columns
    , but if you can get it to work you should be able to add the rest quite easily.

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

Sidebar

Related Questions

I'm using some code from here to determine when determining when the last finger
here is a code : using System; using Nemerle.Collections; using Nemerle.Text; //using Nemerle.Utility; using
Here is the my python code using BeautifulSoup. The main issue is with the
I am using pseudo-code here, but this is in JavaScript. With the most efficient
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I'm looking for something like break for loops. Here's some example code (using Symfony's
Here's the code I'm using to make a custom AlertDialog. public void onButtonClicked(View v)
Here's the code I'm using: // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
Here is my code i am using for custom search, <div id=cse-search-form style=width: 100%;>Loading</div>
On my page, I have a table (content from MySQL) and a footer (using

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.