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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:37:12+00:00 2026-05-28T02:37:12+00:00

My query outputs this in phpMyAdmin: Code: <?php if ($stmt = $mysqli->prepare("SELECT service_names.id, service_names.name

  • 0

My query outputs this in phpMyAdmin:

enter image description here

Code:

<?php
if ($stmt = $mysqli->prepare("SELECT service_names.id, service_names.name as service, 
service_titles.name as title, service_titles.id as service_title_id FROM `service_names` INNER 
JOIN service_titles ON title_id = service_titles.id WHERE service_titles.user_id = ? AND 
service_titles.slide_id = ?")) {

$stmt->bind_param('ii', $user_id, $slide_id);
$stmt->execute();
$stmt->bind_result($service_id, $service_name, $service_title, $service_title_id);
$stmt->store_result();

$result_array = array();

while ($stmt->fetch()) {
    if (!isset($result_array[$service_title])){
        $result_array[$service_title] = array();
    }
    $result_array[$service_title][] = array('service_name'=>$service_name,'service_id'=>$service_id);
}

$html = "";
foreach($result_array as $key => $value){
    $html .= "
    <div class=\"list\">
        <h3 class=\"secondary\"><span id={ GOES HERE }>$key</span></h3>
            <ul>";
        foreach($result_array[$key] as $service){
            $html .= "<li><span id=\"".$service['service_id']."\">".$service['service_name']."</span></li>\n"; 
        }
    $html .= "</ul></div>";
}

echo $html;
$stmt->close();
}

?>

What this code is producing is:

enter image description here

What I need is to grab the service_title_id and place it in the code:

<h3 class=\"secondary\"><span id={ GOES HERE }>$key</span></h3>

I am using a jQuery inline edit script, and it needs a unique ID assigned to it. I have the value in a variable $service_title_id it’s just a matter of integrating it into the array, which I am getting a little confused with all the different arrays and values.

  • 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-05-28T02:37:12+00:00Added an answer on May 28, 2026 at 2:37 am

    The first way, that requires minimum changes in your script, is to add service_title_id to every service and get it from first element of an array:

    while ($stmt->fetch()) {
        if (!isset($result_array[$service_title])){
            $result_array[$service_title] = array();
        }
        $result_array[$service_title][] = array(
            'service_name'=>$service_name,
            'service_id'=>$service_id,
            'service_title_id'=>$service_title_id
        );
    }
    
    <h3 class=\"secondary\"><span id={$result_array[$key][0]['service_title_id']}>$key</span></h3>
    

    other and cleaner way will be to change structure of array holding all services to look like this:

    while ($stmt->fetch()) {
        if (!isset($result_array[$service_title])){
            $result_array[$service_title_id] = array(
                'service_title' => $service_title
                'services' => array(),
            );
        }
        $result_array[$service_title_id]['services'][] = array(
            'service_name'=>$service_name,
            'service_id'=>$service_id
        );
    }
    
    
    $html = "";
    foreach($result_array as $service_title_id => $service_details){
        $html .= "
        <div class=\"list\">
            <h3 class=\"secondary\"><span id=\"{$service_title_id}\">{$service_details['title']}</span></h3>
                <ul>";
            foreach($service_details['services'] as $service){
                $html .= "<li><span id=\"{$service['service_id']}\">{$service['service_name']}</span></li>\n"; 
            }
        $html .= "</ul></div>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
Describe the output of the following SQL query: select custId, name from customer where
The query below outputs this results: +------------+------------+ | testID | testStatus| +------------+------------+ | 1
Here is the MYSQLi code: public function display() { $sql = SELECT title, date_posted,
I have a query that outputs address order data: SELECT ordernumber , article_description ,
I have a query that looks like this: SELECT SUM(`georder`) AS `order`, SUM(quantity) AS
I`m trying to run a nested query on MySQL (phpmyadmin) and via PHP, and
This query outputs each result 6 times: So, for one row with a body
This is a follow up on another problem i had with getting-the-last-record-inserted-into-a-select-query I am
I'm logging output with log = /var/log/mysql/query.log and this works ok, but I only

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.