how to get single value from group_concat query - php

i am getting these
but i need this
How to get seperate value for quiz name ?
query=select userquiz.id,userquiz.user_id,userss.username,quiz.quiz_name,GROUP_CONCAT(userquiz.quiz_id) as 'quiz_id',GROUP_CONCAT(quiz.quiz_name) as 'quiz_name' from userquiz join userss on userss.id=userquiz.user_id join quiz on quiz.quiz_id=userquiz.quiz_id group by user_id;
$filter_query = $query . ' ' . 'LIMIT ' . $start . ', ' . $limit
. '';
$statement = $connect->prepare($query);
// print_r($query);
$statement->execute();
$total_data = $statement->rowCount();
$statement = $connect->prepare($filter_query);
$statement->execute();
$result = $statement->fetchAll();
$total_filter_data = $statement->rowCount();
$output = '
<label> Total Records :- ' . $total_data . '</label>
<table class="table table-bordered" style="margin-top:40px";>
<tr>
<th>Username</th>
<th>Quizname</th>
<th>Action</th>
</tr>
';
if ($total_data > 0) {
foreach ($result as $row) {
$output .= '
<tr>
<td>' . $row["username"] . '</td>
<td><button type=" button" style="background-color:maroon; border: #4685A9;" class="btn btn-success"">' . $row["quiz_name"] . '</td>
<td><button type=" button" style="background-color:red; border: #4685A9;" class="btn btn-primary dltbtn" data-id="' . $row["user_id"] . '"> DELETE</button>
<button type=" button" style="background-color:orange; border: #4685A9;" class="btn btn-primary editbtn" data-eid="' . $row["user_id"] . '">Assign Quiz</button></td>
</tr>
';
}
this is how i am fetching the values
i need to make quiz as button so that can be deleted

Related

Is it possible to pass blade directive like #if into a string from laravel

Here is the code i have tried in controller
$categories = Category::where('categories.name', 'LIKE', '%' . $category_name . '%')
->where('categories.category_code', 'LIKE', '%' . $category_code . '%')->get();
$category_data = $categories->count();
if ($category_data > 0) {
$i = 1;
foreach ($categories as $category) {
$output .=
'<tr>
<td>' . $i++ . '</td>
<td><img src="' . asset($category->photo) . '" class="img-fluid" style="width: 170px; object-fit: cover;"></td>
<td>' . $category->name . '</td>
<td>' . $category->category_code . '</td>
<td><a href="' . route("category.edit", $category->id) . '" class="btn btn-warning">
<i class="icofont-ui-settings icofont-1x"></i>
</a>
#if($delete == "yes")
<form action="' . route("category.destroy", $category->id) . '" method="POST" class="d-inline-block" onsubmit="return confirm("Are you sure to delete the item?")">
#csrf
#method("DELETE")
<button class="btn btn-outline-danger" type="submit"><i class="icofont-close icofont-1x"></i></button>
</form>
#endif
</td>
</tr>';
}
return Response($output);
Code in blade file, jquery
$('#filtersearch').click(function() {
var category_name = $('#category_name').val();
var category_code = $('#category_code').val();
// alert(category_name)
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
$.get('/categorysearch', {
category_name: category_name,
category_code: category_code
},
function(data) {
$('#filter_data').html(data);
})
})
the output looks like thisall of the blade directive are showing as string
Is there a way to develop this, any solution would be very greatful.
Thanks!
I think the best way to do this is by using render() method
you can create your view file and pass your data and render the final HTML code
Example
$renderedHtml = view('your_view_file',compact('some_data'))->render();
then you can respond with your rendered HTML
return Response($renderedHtml );
I hope it's helpful
You have to use Concatenation in laravel for parsing string:
foreach ($categories as $category) {
$output .=
'<tr>
<td>' . $i++ . '</td>
<td><img src="' . asset($category->photo) . '" class="img-fluid" style="width: 170px; object-fit: cover;"></td>
<td>' . $category->name . '</td>
<td>' . $category->category_code . '</td>
<td><a href="' . route("category.edit", $category->id) . '" class="btn btn-warning">
<i class="icofont-ui-settings icofont-1x"></i>
</a>';
if($delete == "yes"){
$output .= '<form action="' . route("category.destroy", $category->id) . '" method="POST" class="d-inline-block" onsubmit="return confirm("Are you sure to delete the item?")">';
$output .= '<input type="hidden" name="_token" value="'.csrf_token().'">';
$output .= '<input type="hidden" name="_method" value="DELETE"><button class="btn btn-outline-danger" type="submit"><i class="icofont-close icofont-1x"></i></button>
</form>';
}
$output .='</td></tr>';
}
Starting from laravel 9.0, you can render blade strings on the fly
use Illuminate\Support\Facades\Blade;
//...
$categories = Category::where('categories.name', 'LIKE', '%' . $category_name . '%')
->where('categories.category_code', 'LIKE', '%' . $category_code . '%')->get();
$category_data = $categories->count();
if ($category_data > 0) {
$i = 1;
foreach ($categories as $category) {
$output .=
'<tr>
<td>' . $i++ . '</td>
<td><img src="' . asset($category->photo) . '" class="img-fluid" style="width: 170px; object-fit: cover;"></td>
<td>' . $category->name . '</td>
<td>' . $category->category_code . '</td>
<td><a href="' . route("category.edit", $category->id) . '" class="btn btn-warning">
<i class="icofont-ui-settings icofont-1x"></i>
</a>
#if($delete == "yes")
<form action="' . route("category.destroy", $category->id) . '" method="POST" class="d-inline-block" onsubmit="return confirm("Are you sure to delete the item?")">
#csrf
#method("DELETE")
<button class="btn btn-outline-danger" type="submit"><i class="icofont-close icofont-1x"></i></button>
</form>
#endif
</td>
</tr>';
}
return Blade::render($output, ['delete' => 'yes']);
If you're on laravel 8.x or lower, you can use this package felixdorn/laravel-render-blade-string or the other answers solutions

Making a table with a php function but having a few issues

So I was helped in getting the data to populate properly but when trying to get it to create a table and I cant seem to get it to work properly. I looked online and cant seem to find a solution maybe I just missed it.
This is the code I want to change
function getplayers()
{
$json = file_get_contents('http://116.203.39.175:30120/players.json');
$json_data = json_decode($json, true);
foreach ($json_data as $player_data) {
// Initialise the steam id to an empty string in case one is not found
$player_steam_id = "";
$player_lic = "";
// Find the steam id in the identifiers array
if (array_key_exists("identifiers", $player_data)) {
$steam_identifiers = [];
foreach ($player_data["identifiers"] as $identifier_str)
if (preg_match("/^steam:/i", $identifier_str, $m))
$steam_identifiers[] = $identifier_str;
if (!empty($steam_identifiers)) {
$player_steam_id = $steam_identifiers[0];
}
}
if (array_key_exists("identifiers", $player_data)) {
$steam_identifiers = [];
foreach ($player_data["identifiers"] as $identifier_str)
if (preg_match("/^license:/i", $identifier_str, $m))
$steam_identifiers[] = $identifier_str;
if (!empty($steam_identifiers)) {
$player_lic = $steam_identifiers[0];
}
}
$player_id = $player_data["id"];
$player_name = $player_data["name"];
echo '
<table id="allUsers" class="table table-striped table-bordered">
<thead>
<tr>
<th>Player ID</th>
<th>Name</th>
<th>Steam ID</th>
<th>License</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
';
echo '
<tr>
<td>' . $player_id . '</td>
<td>' . $player_name . '</td>
<td>' . $player_steam_id . '</td>
<td>' . $player_lic . '</td>
<td>
<input name="deleteBan" type="submit" class="btn btn-xs btn-link" onclick="deleteBan(' . $player_id . ')" value="Delete" />
';
echo '
<input name="bid" type="hidden" value=' . $player_id . ' />
</form>
</td>
</tr>
';
echo '
</tbody>
</table>
';
}}
New one with Json
and this is a similar code that works from SQL but im not sure how to get the same end point.
function getbans()
{
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, "mayfairg_fivem");
$site = BASE_URL;
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
$query = "SELECT id,identifier,license,targetplayername,sourceplayername,reason,added,
case
when permanent = 1 then 'Yes'
when permanent = 0 then 'No'
end
FROM banlist";
$result = mysqli_query($link, $query);
echo '
<table id="allUsers" class="table table-striped table-bordered">
<thead>
<tr>
<th>Steam ID</th>
<th>License</th>
<th>Banned Player</th>
<th>Admin</th>
<th>Reason</th>
<th>Date</th>
<th>Perm?</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
';
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH))
{
echo '
<tr>
<td>' . $row[1] . '</td>
<td>' . $row[2] . '</td>
<td>' . $row[3] . '</td>
<td>' . $row[4] . '</td>
<td>' . $row[5] . '</td>
<td>' . $row[6] . '</td>
<td>' . $row[7] . '</td>
<td>
<form action="'.$site.'/actions/adminActions.php" method="post">
<input name="deleteBan" type="submit" class="btn btn-xs btn-link" onclick="deleteBan(' . $row[0] . ')" value="Delete" />
';
echo '
<input name="bid" type="hidden" value=' . $row[0] . ' />
</form>
</td>
</tr>
';
}
echo '
</tbody>
</table>
';
}
Working with SQL
Here's some code-cleanup for you. A break in your inner loop is best practice to avoid excess iterations. Your preg_match() calls can be merged into one to generate a variable array assignment. I am using the null coalescing operator to declare an empty string as the fallback for missing ids.
Code: (Demo)
$players = json_decode($json, true);
foreach ($players as $player) {
if (!empty($player['identifiers'])) {
foreach ($player["identifiers"] as $id) {
if (preg_match("/^(steam|license):([a-f\d]+)$/", $id, $m)) { // target the two specific ids
$player[$m[1]] = $m[2];
}
if (isset($player['steam'], $player['license'])) {
break; // stop iterating, we have everything we want
}
}
}
$player['steam'] ?? ''; // fallback to empty string when not found
$player['license'] ?? ''; // fallback to empty string when not found
echo '
<tr>
<td>' . $player["id"] . '</td>
<td>' . $player["name"] . '</td>
<td>' . $player["steam"] . '</td>
<td>' . $player["license"] . '</td>
<td>
<input name="deleteBan" type="submit" class="btn btn-xs btn-link" onclick="deleteBan(' . $player["id"] . ')" value="Delete" />
</tr>
';
}
I figured it out it was a simple fix I had a "}" in the wrong location.
function getplayers()
{
echo '
<table id="allUsers" class="table table-striped table-bordered">
<thead>
<tr>
<th>Player ID</th>
<th>Name</th>
<th>Steam ID</th>
<th>License</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
';
$json = file_get_contents('http://116.203.39.175:30120/players.json');
$json_data = json_decode($json, true);
foreach ($json_data as $player_data) {
// Initialise the steam id to an empty string in case one is not found
$player_steam_id = "";
$player_lic = "";
// Find the steam id in the identifiers array
if (array_key_exists("identifiers", $player_data)) {
$steam_identifiers = [];
foreach ($player_data["identifiers"] as $identifier_str)
if (preg_match("/^steam:/i", $identifier_str, $m))
$steam_identifiers[] = $identifier_str;
if (!empty($steam_identifiers)) {
$player_steam_id = $steam_identifiers[0];
}
}
if (array_key_exists("identifiers", $player_data)) {
$steam_identifiers = [];
foreach ($player_data["identifiers"] as $identifier_str)
if (preg_match("/^license:/i", $identifier_str, $m))
$steam_identifiers[] = $identifier_str;
if (!empty($steam_identifiers)) {
$player_lic = $steam_identifiers[0];
}
}
$player_id = $player_data["id"];
$player_name = $player_data["name"];
echo '
<tr>
<td>' . $player_id . '</td>
<td>' . $player_name . '</td>
<td>' . $player_steam_id . '</td>
<td>' . $player_lic . '</td>
<td>
<input name="deleteBan" type="submit" class="btn btn-xs btn-link" onclick="deleteBan(' . $player_id . ')" value="Delete" />
';
echo '
<input name="bid" type="hidden" value=' . $player_id . ' />
</form>
</td>
</tr>
';
}
echo '
</tbody>
</table>
';
}

How to execute PDO in a variable PHP

while($row =$result->fetch())
{
$output .= '
<tr>
<td>' . $row["ID_personne"] . '</td>
<td>' . $row["Nom"] . '</td>
<td>' . $row["Prenom"] . '</td>
<td>' . $row["Telephone"] . '</td>
<td>' . $row["Mail"] . '</td>
<td>' . $row["Categorie"] . '</td>
<td>' . $row["Type"] . '</td>
'.$q2 = $db->prepare("SELECT * FROM entretiens WHERE ID_entretien=:id");
$q2->bindValue(":id",$row["Entretien"]);
$q2->execute();
$entretien=$q2->fetch().'
<td>'.$entretien["Date"].'</td>
<td width=250>
<a class="btn btn-primary" href="update_personnes.php?ID_personne='.$row["ID_personne"].'"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>
<a class="btn btn-danger" href="delete_personnes.php?ID_personne='.$row["ID_personne"].'"><span class="glyphicon glyphicon-remove"></span> Supprimer</a>
</td>
</tr>';
}
$output .= '</table>';
echo $output;
I have always an Error: ( ! ) Catchable fatal error: Object of class PDOStatement could not be converted to string in C:.......... on line 61('.$q2 = $db->prepare("SELECT * FROM entretiens WHERE ID_entretien=:id");
$row["Entretien"] it's a foreign key
There was some syntax error in your code as $q2 is being concat with html string. Improved code should be:
while ($row = $result->fetch()) {
$output .= '
<tr>
<td>' . $row["ID_personne"] . '</td>
<td>' . $row["Nom"] . '</td>
<td>' . $row["Prenom"] . '</td>
<td>' . $row["Telephone"] . '</td>
<td>' . $row["Mail"] . '</td>
<td>' . $row["Categorie"] . '</td>
<td>' . $row["Type"] . '</td>';
$q2 = $db->prepare("SELECT * FROM entretiens WHERE ID_entretien=:id");
$q2->bindValue(":id", $row["Entretien"]);
$q2->execute();
$entretien = $q2->fetch();
$output .= '<td>' . $entretien["Date"] . '</td>
<td width=250>
<a class="btn btn-primary" href="update_personnes.php?ID_personne=' . $row["ID_personne"] . '"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>
<a class="btn btn-danger" href="delete_personnes.php?ID_personne=' . $row["ID_personne"] . '"><span class="glyphicon glyphicon-remove"></span> Supprimer</a>
</td>
</tr>';
}
$output .= '</table>';
echo $output;

How to put radio button inside the output table?

How to put radio button inside the status, 2 radio buttons (approved and disapproved) and the checked radio button will be save in database as well under status field.
This is my codes.. patient[6] is the status
$sql = "select patientid, firstname, lastname, gender, patienttype, philhealth, status from patients where lastname LIKE '%" . $_POST["key"] . "%' or philhealth LIKE '%" . $_POST["key"] . "%' ";
$result = mysql_query($sql, $connection);
$rownum = 0;
$bgcolor = "";
while($patient = mysql_fetch_array($result))
{
$rownum += 1;
if($rownum == 2)
{
$bgcolor = "#FFF";
$rownum = 0;
}
else
{ $bgcolor = "#f9f9f9"; }
$approved_checked = $patient[6] == 'Approved' ? 'checked' : '';
echo "
<tr id='" . $patient[0] . "' style='background: " . $bgcolor . "' onclick='openphilhealthapproval() '>
<td id='td27_cell1' style='height: 25px;'>" . $patient[5] . " </td>
<td id='td27_cell2' style='height: 25px;'>" . $patient[0] . "</td>
<td id='td27_cell3' style='height: 25px;'>" . $patient[1] . " " . $patient[2] . "</td>
<td id='td27_cell4' style='height: 25px;'>" . $patient[3] . "</td>
<td id='td27_cell5' style='height: 25px;'>" . $patient[4] . "</td>
<td id='td27_cell6' style='height: 25px;'>" . $patient[6] . "</td>
</tr>
";
}
You should put the content of this TD element into your status TD element. Also you need to replace ***patientID*** signs with the patientID when you build your HTML. You could see the working example here.
<td>
<input type="radio" name="statusradio***patientID***" value="approved" id="approvedradio***patientID***"/>
<label for="approvedradio***patientID***">approved</label>
<input type="radio" name="statusradio***patientID***" value="disapproved" id="disapprovedradio***patientID***"/>
<label for="disapprovedradio***patientID***">disapproved</label>
</td>

Add custom multi language product fields

I'm trying to add multi-language custom product fields. Please anybody help me out from this problem.
Add table
CREATE TABLE IF NOT EXISTS `product_custom` (
`product_id` int(11) NOT NULL,
`title` varchar(255) CHARACTER SET utf8 NOT NULL,
` language_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
In admin/view/template/catalog/product.tpl
<div class="tab-pane" id="tab-custom">
<div class="table-responsive">
<table id="custom" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="text-right">Title</td>
<td class="text-right">Value</td>
<td></td>
</tr>
</thead>
<tbody>
<?php $custom_row = 0; ?>
<?php foreach ($product_customs as $product_custom) { ?>
<tr id="custom-row<?php echo $custom_row; ?>">
<?php foreach ($languages as $language) { ?>
<td class="text-right">
<img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" style="margin-right:10px;padding:5px 0px"/><br/>
<input type="text" name="product_custom[<?php echo $custom_row; ?>][<?php echo $language['language_id']; ?>][title]" value="<?php echo $product_custom[$language['language_id']]['title']; ?>" placeholder="Title" class="form-control" />
</td>
<?php }?>
<td class="text-left"><button type="button" onclick="$('#custom-row<?php echo $custom_row; ?>').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
</tr>
<?php $custom_row++; ?>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td colspan="1"></td>
<td class="text-left"><button type="button" onclick="addCustom();" data-toggle="tooltip" title="Add Mediabox" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
</tr>
</tfoot>
</table>
</div>
</div>
<script type="text/javascript"><!--
var custom_row = <?php echo $custom_row; ?>;
function addCustom() {
html = '<tr id="custom-row' + custom_row + '">';
<?php foreach ($languages as $language) { ?>
html += ' <td class="text-right"><input type="text" name="product_custom[' + custom_row + '][title]" value="" placeholder="Title" class="form-control" /></td>';
<?php }?>
html += ' <td class="text-left"><button type="button" onclick="$(\'#custom-row' + custom_row + '\').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
html += '</tr>';
$('#custom tbody').append(html);
custom_row++;
}
//--></script>
In admin/controller/catalog/product.php
//Custom
if (isset($this->request->post['product_custom'])) {
$product_customs = $this->request->post['product_custom'];
} elseif (isset($this->request->get['product_id'])) {
$product_customs = $this->model_catalog_product->getProductCustoms($this->request->get['product_id']);
} else {
$product_customs = array();
}
$data['product_mediaboxs'] = array();
foreach ($product_customs as $language_id => $product_custom) {
$data['product_customs'] = $this->language->get('product_customs');
$data['product_customs'][] = array(
'title' => $product_custom['title'],
);
}
In admin/model/catalog/product.php
if (isset($data['product_custom'])) {
foreach ($data['product_custom'] as $language_id => $product_custom) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_custom SET product_id = '" . (int)$product_id . "', title = '" . $this->db->escape($product_custom['title']) . "', language_id = '" . (int)$language_id . "'");
}
}
$this->db->query("DELETE FROM " . DB_PREFIX . "product_custom WHERE product_id = '" . (int)$product_id . "'");
if (isset($data['product_custom'])) {
foreach ($data['product_custom'] as $language_id => $product_custom) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_mediabox SET product_id = '" . (int)$product_id . "', title = '" . $this->db->escape($product_custom['title']) . "', language_id = '" . (int)$language_id . "'");
}
}
$data['product_custom'] = $this->getProductCustoms($product_id);
$this->db->query("DELETE FROM " . DB_PREFIX . "product_custom WHERE product_id = '" . (int)$product_id . "'");
public function getProductCustoms($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_custom WHERE product_id = '" . (int)$product_id . "' ORDER BY title");
return $query->rows;
}
Check with following changes :
Add table
CREATE TABLE IF NOT EXISTS `oc_product_custom` (
`opc_id` int(11) NOT NULL AUTO_INCREMENT,
`product_id` int(11) NOT NULL,
PRIMARY KEY (`opc_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `oc_product_custom_desc` (
`opc_id` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`language_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
In admin/view/template/catalog/product_form.tpl
add below html
<div class="tab-pane" id="tab-custom">
<div class="table-responsive">
<table id="custom" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="text-right">Title</td>
<td></td>
</tr>
</thead>
<tbody>
<?php $custom_row = 0; ?>
<?php foreach ($product_customs as $product_custom) { ?>
<tr id="custom-row<?php echo $custom_row; ?>"><td class="text-right">
<?php foreach ($languages as $language) { ?>
<div class="input-group"><span class="input-group-addon"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /></span>
<input type="text" name="product_custom[<?php echo $custom_row; ?>][<?php echo $language['language_id']; ?>][title]" value="<?php echo $product_custom[$language['language_id']]['title']; ?>" placeholder="Title" class="form-control" />
</div>
<?php }?>
</td>
<td class="text-left"><button type="button" onclick="$('#custom-row<?php echo $custom_row; ?>').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
</tr>
<?php $custom_row++; ?>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td colspan="1"></td>
<td class="text-left"><button type="button" onclick="addCustom();" data-toggle="tooltip" title="Add Mediabox" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
</tr>
</tfoot>
</table>
</div>
</div>
Add below script
<script type="text/javascript"><!--
var custom_row = <?php echo $custom_row; ?>;
function addCustom() {
html = '<tr id="custom-row' + custom_row + '">';
html += '<td class="text-right">';
<?php foreach ($languages as $language) { ?>
html += '<div class="input-group"><span class="input-group-addon"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /></span><input type="text" name="product_custom[' + custom_row + '][<?php echo $language['language_id']; ?>][title]" value="" placeholder="Title" class="form-control" /></div>';
<?php }?>
html += '</td>';
html += ' <td class="text-left"><button type="button" onclick="$(\'#custom-row' + custom_row + '\').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
html += '</tr>';
$('#custom tbody').append(html);
custom_row++;
}
//--></script>
admin/controller/catalog/product.php
//Custom
if (isset($this->request->post['product_custom'])) {
$product_customs = $this->request->post['product_custom'];
} elseif (isset($this->request->get['product_id'])) {
$product_customs = $this->model_catalog_product->getProductCustoms($this->request->get['product_id']);
} else {
$product_customs = array();
}
$data['product_customs'] = array();
foreach ($product_customs as $key=>$product_custom) {
foreach ($data['languages'] as $language){
$customdata = $this->model_catalog_product->getProductCustom($product_custom['opc_id'],$language['language_id']);
$data['product_customs'][$key][$language['language_id']] = array(
'title' => $customdata['title'],
);
}
}
admin/model/catalog/product.php
in addProduct method add following code before $this->cache->delete('product')
if (isset($data['product_custom'])) {
foreach ($data['product_custom'] as $product_custom_data) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_custom` SET `product_id` = '" . (int) $product_id . "'");
$opc_id = $this->db->getLastId();
if (!empty($product_custom_data)) {
foreach ($product_custom_data as $language_id => $product_custom) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_custom_desc` SET `opc_id` = '" . (int) $opc_id . "', `title` = '" . $this->db->escape($product_custom['title']) . "', `language_id` = '" . (int) $language_id . "'");
}
}
}
}
In editProduct method add following code before $this->cache->delete('product')
$this->db->query("DELETE FROM " . DB_PREFIX . "product_custom WHERE product_id = '" . (int) $product_id . "'");
$this->db->query("DELETE FROM " . DB_PREFIX . "product_custom_desc WHERE product_id = '" . (int) $product_id . "'");
if (isset($data['product_custom'])) {
foreach ($data['product_custom'] as $product_custom_data) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_custom` SET `product_id` = '" . (int) $product_id . "'");
$opc_id = $this->db->getLastId();
if (!empty($product_custom_data)) {
foreach ($product_custom_data as $language_id => $product_custom) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_custom_desc` SET `opc_id` = '" . (int) $opc_id . "', `title` = '" . $this->db->escape($product_custom['title']) . "', `language_id` = '" . (int) $language_id . "'");
}
}
}
}
in copyProduct method add following code before $this->addProduct($data);
$data['product_custom'] = $this->getProductCustoms($product_id);
in deleteProduct method add below code before $this->cache->delete('product')
$this->db->query("DELETE FROM " . DB_PREFIX . "product_custom WHERE product_id = '" . (int) $product_id . "'");
$this->db->query("DELETE FROM " . DB_PREFIX . "product_custom_desc WHERE product_id = '" . (int) $product_id . "'");
add below method :
public function getProductCustoms($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_custom WHERE product_id = '" . (int) $product_id . "'");
return $query->rows;
}
public function getProductCustom($opc_id,$language_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_custom_desc WHERE opc_id = '" . (int) $opc_id . "' AND language_id='".$language_id."' ORDER BY title");
return $query->row;
}
Note : I think there is no need of product_mediabox table.

Categories