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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:26:51+00:00 2026-06-12T18:26:51+00:00

i want to fetch titles and title’s tags. public function titles() { $query=mysql_query(SELECT *

  • 0

i want to fetch titles and title’s tags.

public function titles()
{
     $query=mysql_query("SELECT * FROM title");
     while($row = mysql_fetch_object($query)){
          $data->title[] = $row;
          $data->tag[] = $this->tags($row->id);
     }
     return $data;
}

public function tags($title_id)
{
     $query=mysql_query("SELECT * FROM tag WHERE title_id = '$title_id'");
     while($row = mysql_fetch_object($query)){
           $tag[] = $row;
     }
     return $tag;
}

I’m trying to print in this way

$data = titles();
foreach($data->title as $title)
{
     echo $title->topic;
     foreach($data->tag as $tag)
     {
         echo $tag->name;
     }
}

but it doesnt work. How can I do?
thank you for 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-12T18:26:52+00:00Added an answer on June 12, 2026 at 6:26 pm

    You should have something like this in your titles method

    $data = new stdClass();
    $data->title = array();
    $data->tag = array();
    

    You also need to add files like this

    $data->title[$row->id][] = $row;
    $data->tag[$row->id][] = $this->tags($row->id);
    

    Then you can loop like this

    foreach($data->title as $id => $title)
    {
        echo $title->topic;
        foreach($data->tag[$id] as $tag)
        {
            echo $tag->name;
        }
    }
    

    Also Enable error so that you can see PHP Errors .. at on top of your page

    error_reporting(E_ALL);
    ini_set("display_errors","On");
    

    PHP DOC ON mysql_***

    Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include

    What i think your code should look like

    class Somthing {
        private $db;
    
        function __construct() {
            $this->db = new mysqli("localhost", "user", "password", "db");
        }
    
        function titles() {
            $data = new stdClass();
            $data->title = array();
            $data->tag = array();
    
            $result = $this->db->query("SELECT * FROM title");
            while ( $row = $result->fetch_object() ) {
                $data->title[$row->id] = $row;
                $data->tag[$row->id] = $this->tags($row->id);
            }
            return $data;
        }
    
        function tags($title_id) {
            $tag = array();
            $result = $this->db->query("SELECT * FROM tag WHERE title_id = '$title_id'");
            while ( $row = $result->fetch_object() ) {
                $tag[] = $row;
            }
            return $tag;
        }
    }
    
    $somthing = new Somthing();
    
    foreach ($somthing->titles() as $id => $title ) {
        echo $title->topic;
        foreach ( $data->tag[$id] as $tag ) {
            echo $tag->name;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fetch the title from book table and the subject name from
Hard to understand (json_encode) i'm using the code: <?php $query = mysql_query(SELECT * FROM
$result = mysql_query(SELECT blog_title,body FROM blog WHERE post_id='$id' LIMIT 1) or die (mysql_error()); while
I fetch an array with todo titles and due dates from MySQL. I want
I want to fetch website title and images from URL. as facebook.com doing. How
I want to fetch the title of a webpage which I open using urllib2.
want to fetch the value from dynamically created textfield with tag from NSMutableArray.... Txt_New_Estimated
I want to fetch the unmatching records from two table in SQL, the table
I am new to Javascript. I want to fetch lat-long from MySQL (more then
I want to fetch a YouTube video title when the video id is known,

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.