Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created November 24, 2019 17:43
Show Gist options
  • Select an option

  • Save phpfiddle/b25ee9a791d9f2d1b422236ee640cfb9 to your computer and use it in GitHub Desktop.

Select an option

Save phpfiddle/b25ee9a791d9f2d1b422236ee640cfb9 to your computer and use it in GitHub Desktop.
[ Posted by James ] Ian test 2
<?php
function productfeatureorder($order)
{
// mysqli_real_connect
// Create connection
$url = $_SERVER['HTTP_HOST'];
if ($url == 'belchim.avalonbloom.com') {
//$conn (<<objectname)= mysqli_connect('url:string', 'User:string', 'database:string', 'port(not required if default):string', Socket(not required if default):string), ;
$conn = mysqli_connect('localhost', 'belchim', 'belchim', 'belchim');
} else {
$conn = mysqli_connect('localhost', 'mcdayadm_belchim', 'password1', 'mcdayadm_belchim');
};
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
};
echo "Connected successfully";
/*
THIS IS MY TABLE I AM ACCESSINg
CREATE TABLE `qewrer_belchimproducts_productfeatures` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`ordering` int(11) DEFAULT NULL,
`prod_id_1` int(11) DEFAULT NULL,
`feature` text,
`created_by` bigint(20) unsigned DEFAULT NULL,
`creation_date` datetime DEFAULT NULL,
`modified_by` bigint(20) unsigned DEFAULT NULL,
`modification_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=116 DEFAULT CHARSET=utf8;
UPDATE `qewrer_belchimproducts_productfeatures` SET `ordering` = '1' WHERE `id` = '2'; //<<< this is the SQL to "UPDATE existing records"
MYLIST= 115,118,113,112,114,110,111 //<<< this is the array I am anticipating
*/
$x = 0;
foreach ($order as $key => $value) {
// $query = $db->getQuery(true);
$x++;
$sql = "UPDATE qewrer_belchimproducts_productfeatures SET ordering = $x WHERE id = $value";
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
};
};
}
$listOrder = makeint($_POST['myArray']); // retrieves the data posted by the user
productfeatureorder($listOrder); // Process the request
function productfeaturedelete($item) // to delete a known record
{
// Mysqli_real_connect
// Create connection
$url = $_SERVER['HTTP_HOST'];
if ($url == 'belchim.avalonbloom.com') { // dev server access
$conn = mysqli_connect('localhost', 'belchim', 'belchim', 'belchim');
} else { // Live server access
$conn = mysqli_connect('localhost', 'mcdayadm_belchim', 'password', 'mcdayadm_belchim');
};
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
};
echo "Connected successfully";
/* THIS IS MY TABLE I AM ACCESSINg
CREATE TABLE `qewrer_belchimproducts_productfeatures` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`ordering` int(11) DEFAULT NULL,
`prod_id_1` int(11) DEFAULT NULL,
`feature` text,
`created_by` bigint(20) unsigned DEFAULT NULL,
`creation_date` datetime DEFAULT NULL,
`modified_by` bigint(20) unsigned DEFAULT NULL,
`modification_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=116 DEFAULT CHARSET=utf8;
$sql = "UPDATE qewrer_belchimproducts_productfeatures SET ordering = $x WHERE id = $value";
*/
$sql = "DELETE FROM `qewrer_belchimproducts_productfeatures` WHERE `id` = $item";
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleted record: " . mysqli_error($conn);
};
}
?>
@kicode-t

Copy link
Copy Markdown

http://192.168.1.254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment