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

  • Home
  • SEARCH
  • 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 8670169
In Process

The Archive Base Latest Questions

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

I have this query: $query = SELECT ads.*, trafficsource.name AS trafficsource, placement.name AS placement,

  • 0

I have this query:

$query = "SELECT ads.*,
       trafficsource.name AS trafficsource,
       placement.name AS placement,
       advertiser.name AS advertiser,
       country.name AS country
       FROM ads
           JOIN trafficsource ON ads.trafficsourceId = trafficsource.id
           JOIN placement ON ads.placementId = placement.id
           JOIN advertiser ON ads.advertiserId = advertiser.id
           JOIN country ON ads.countryId = country.id
       WHERE advertiserId = '$advertiser_id'";

and ads table

ads Table
      ad_id PK
      size
      price
      trafficsourceId FK
      placementId FK
      advertiserId FK
      countryId FK

For getting data I’m using

$result = mysql_query($query) or die('Invalid query: ' . mysql_error());
    while ($row = mysql_fetch_assoc($result)) {

}

I cant figure out how I need to print page so that it’s not looking like rows but also need id’s of for example trafficsource name. I want to make something like that:

EDITED:

<div id="adscontent">
    <h1>Advertiser:</h1> Advertiser name
    <h2>Traffic Sources:</h2> Company1, Company2, Company 3
    <h2>Placements:</h2> Like: Newspaper, radio, website, bla bla
</div>

Thanks

  • 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:39:01+00:00Added an answer on June 12, 2026 at 6:39 pm

    You will need to play around with the printout but I think something like this will work:

    $results = array();
    while ($row = mysql_fetch_assoc($result)) {
        $results[$row['advertiser']]['countries'][]      = $row['country'];
        $results[$row['advertiser']]['trafficsources'][] = $row['trafficsource'];
        $results[$row['advertiser']]['placements'][]     = $row['placement'];
    }
    
    // And now print the data
    foreach ($results as $arvertiser => $data)
    {
        echo "<h1>{$advertiser}</h1>";
    
        // Print Placements
        echo "Placements: " . implode(", ", $data['placements']) . '<br />;
    
        // Print Countries
        echo "Countries: " . implode(", ", $data['countries']) . '<br />;
    
        // Print Placements
        echo "Traffic Sources: " . implode(", ", $data['trafficsources']) . '<br />;
    
    }
    

    EDIT: If you need to add the IDs you will need to change your select to:

    $query = "SELECT ads.*,
           trafficsource.name AS trafficsource,
           trafficsource.id AS trafficsourse_id,
           placement.name AS placement,
           placement.id AS placement_id,
           advertiser.name AS advertiser,
           advertiser.id AS advertiser_id,
           country.name AS country
           country.id AS country_id
           FROM ads
               JOIN trafficsource ON ads.trafficsourceId = trafficsource.id
               JOIN placement ON ads.placementId = placement.id
               JOIN advertiser ON ads.advertiserId = advertiser.id
               JOIN country ON ads.countryId = country.id
           WHERE advertiserId = '$advertiser_id'";
    

    From then on you can include this information in the $results array like so:

    $results[$row['advertiser']['countries'] = array(
                                                   'id'    => $row['country_id'], 
                                                   'value' => $row['country')
                                               );
    

    and print out whatever you need from there.

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

Sidebar

Related Questions

I have this query: Select (Country.Name + ', ' + City.Name) as Location ...
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
I have this query: SELECT Auctions.ID FROM Auctions INNER JOIN Products ON Auctions.ProductID =
I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
I have this query: SELECT g.title, g.asin, g.platform_id, r.rank FROM games g INNER JOIN
I have this query: select id from mytable where contains(all_text,'('||?||' within name)*2, ('||?||' within
I have this query select ts.name as my_name, ss.step_number, p.specs, p.price, ssp.class_id from optional_system_step
I have this query SELECT t1.Trans_ID FROM (SELECT * FROM Prune WHERE [Name]=I1) AS
I have this query SELECT W.NUMBER,B.NAME,Br.NAME,W.WDATE,W.REPAIRSTATUS,W.REPAIRCOST,W.REMARK FROM Work_Order AS W,Brands AS B,Branches AS Br
I have this query: SELECT p.id, r.status, r.title FROM page AS p INNER JOIN

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.