My query outputs this in phpMyAdmin:
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:
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.
service_title_id
as an id because it is not unique. What are you actually trying to do? What do you want to achieve?<span>
or an<input>
, depending on what you are actually need to do with the data at the client side.