Last active
July 17, 2017 10:16
-
-
Save xlanor/5e0095f859bbd621a7f895c7275ef552 to your computer and use it in GitHub Desktop.
Display from mySQL using Morris
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'connection.php'; | |
include 'productmodel.php'; | |
$desc = $rn['proDesc_text']; | |
echo $desc; | |
//short and simple :3 | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: tanji | |
* Date: 7/17/2017 | |
* Time: 3:49 PM | |
*/ | |
include ('connection.php'); | |
include ('productmodel.php'); | |
$string = ""; | |
if($marid == 2) | |
{ | |
$listingurl = $rn['proURL']; | |
$listingtitle = $rn['proShop_Title']; | |
$string .= 'Shop Title: ' . $listingtitle . '<br> Shop URL: .' . $listingurl . '<br><br>'; | |
foreach ($ddlqfetch as $row) { | |
$prodprice = $row['proPrice']; | |
$prodttl = $row['proTitle']; | |
$string .= 'Product Title: ' . $prodttl . '<br> Product Price: $' . $prodprice . '<br><br>'; | |
} | |
} | |
else | |
{ | |
$listingurl = $rn['proURL']; | |
$listingtitle = $rn['proShop_Title']; | |
$prodprice = $rn['proPrice']; | |
$seller = $rn['proSeller']; | |
$brand = $rn['proBrand']; | |
$sku = $rn['proSKU']; | |
$string .= 'Shop Title: ' . $listingtitle . '<br> Shop URL: ' . $listingurl . '<br>Price: $' . $prodprice . '<br> SKU:' . $sku . '<br>'; | |
} | |
echo $string; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('connection.php'); | |
include('productmodel.php'); | |
$string = ''; | |
$att = $attributesx->fetchAll(); | |
if (empty($att)) | |
{ | |
$string.= "No attributes avaliable for this product"; | |
} | |
else | |
{ | |
foreach ($att as $row) | |
{ | |
$attr = $row['attProdAttribute']; | |
$string .= $attr.'<br>'; | |
} | |
} | |
echo $string; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('connection.php'); | |
include('productmodel.php'); | |
$string=''; | |
$key = $keywordsx->fetchAll(); | |
if (empty($key)) | |
{ | |
$string.= "No keywords avaliable for this product"; | |
} | |
else | |
{ | |
foreach ($key as $row) | |
{ | |
$keyr = $row['Keywords']; | |
$string.= $keyr.'<br>'; | |
} | |
} | |
echo $string; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: tanji | |
* Date: 7/17/2017 | |
* Time: 9:40 AM | |
*/ | |
include('connection.php'); | |
$prodname = $_GET['prodname']; | |
$startdate = $_GET['startdate']; | |
$enddate = $_GET['enddate']; | |
$def = array(); | |
$result = array(); | |
$arr = array(); | |
$fubar = array(); | |
$l1 = array(); | |
$combined = array(); | |
foreach ($prodname as $row) | |
{ | |
$searchq = "SELECT proTitle, proFetch_Time, proPrice FROM products WHERE proTitle LIKE :prodname AND proFetch_Time BETWEEN :sd AND :ed"; | |
$searchx = $dbh->prepare($searchq); | |
$searchx->bindParam(':prodname',$row); | |
$searchx->bindParam(':sd',$startdate); | |
$searchx->bindParam(':ed',$enddate); | |
$searchx->execute(); | |
$string = $searchx->fetchAll(); | |
foreach ($string as $item) | |
{ | |
if (!isset($def[$item['proTitle']])) | |
{ | |
$def[$item['proTitle']] = "a" . count($def); | |
} | |
} | |
foreach ($string as $item) | |
{ | |
$result[$item['proFetch_Time']][$def[$item['proTitle']]] = $item['proPrice']; | |
} | |
} | |
foreach ($result as $k => $r) { | |
$lol = $r; | |
$lol['y'] = $k; | |
//array_push($lol,array('y' => $k)); | |
$arr[] = $lol; | |
} | |
//echo json_encode($arr); | |
$defcounter = 0; | |
$t = count($def); | |
while ($defcounter < $t) | |
{ | |
$fubar[] = "a" . $defcounter; | |
$defcounter++; | |
} | |
$l1 = array_keys($def); | |
$combined = array('lab' => $l1, 'def' => $fubar, 'morris' => $arr); | |
echo json_encode($combined); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: tanji | |
* Date: 7/14/2017 | |
* Time: 2:42 PM | |
*/ | |
include ('connection.php'); | |
if(!isset($_GET['q'])) | |
{ | |
//it is important that you do this - not just check or define $search as empty or blank to clean up code | |
//because it will work fine for english chars but not for chinese chars | |
$id = $_GET['troll']; | |
$query = "SELECT proTitle from products WHERE proMkt_Item_ID = :id GROUP BY proTitle"; | |
$queryx = $dbh->prepare($query); | |
$queryx->bindValue(':id',$id,PDO::PARAM_STR); | |
$queryx->execute(); | |
$list = $queryx->fetchAll(PDO::FETCH_ASSOC); | |
} | |
else | |
{ | |
$search = '%' .$_GET['q']. '%'; | |
$id = $_GET['troll']; | |
$query = "SELECT proTitle from products WHERE proTitle LIKE :pname AND proMkt_Item_ID = :id GROUP BY proTitle"; | |
$queryx = $dbh->prepare($query); | |
$queryx->bindValue(':pname',$search,PDO::PARAM_STR); | |
$queryx->bindValue(':id',$id,PDO::PARAM_STR); | |
$queryx->execute(); | |
$list = $queryx->fetchAll(PDO::FETCH_ASSOC); | |
} | |
if(count($list) > 0) | |
{ | |
foreach ($list as $key => $value) | |
{ | |
$data[] = array('id'=>$value['proTitle'], 'title' => $value['proTitle']); | |
} | |
} | |
else | |
{ | |
$data[] = array('id' => '0', 'title' => 'This product does not exist!'); | |
} | |
echo json_encode(['items' => $data]); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
</head> | |
<style type="text/css"> | |
.gallery img { | |
width: 20%; | |
height: auto; | |
border-radius: 5px; | |
cursor: pointer; | |
transition: .3s; | |
object-fit: cover; | |
height: 20%; | |
} | |
.select2 | |
{ | |
width: 100%!important; | |
} | |
#chart{ | |
width: 100%; | |
height:400px; | |
} | |
#price-graph { width: 700px; height: 400px;} | |
</style> | |
<body> | |
<form id="product" method="POST" action="javascript:alert('FORM SUBMITTED')"> | |
<div class = "container"> | |
<div class = "row"> | |
<a href="#images-collapse" data-toggle="collapse">Product & description images</a> | |
<div id = "images-collapse" class = "collapse"> | |
<div class="gallery"></div> | |
</div> | |
</div> | |
<!-- end collaspe img--> | |
<div class = "row"> | |
<a href="#prod-collapse" data-toggle="collapse">Product Details</a> | |
<div id = "prod-collapse" class = "collapse"> | |
<div id = "proddetails"></div> | |
</div> | |
</div> | |
<!-- end collaspe prod--> | |
<div class = "row"> | |
<a href="#desc-collapse" data-toggle="collapse">Description</a> | |
<div id = "desc-collapse" class = "collapse"> | |
<div id = "proddesc"></div> | |
</div> | |
</div> | |
<!--end description--> | |
<div class = "row"> | |
<a href="#rev-collapse" data-toggle="collapse">Review</a> | |
<div id = "rev-collapse" class = "collapse"> | |
<div id="reviews"></div> | |
</div> | |
</div> | |
<!-- end collaspe review--> | |
<div class = "row"> | |
<a href="#attribute-collapse" data-toggle="collapse">Attributes</a> | |
<div id = "attribute-collapse" class = "collapse"> | |
<div id = "att"></div> | |
</div> | |
</div> | |
<!-- end attribute review--> | |
<div class = "row"> | |
<a href="#keyword-collapse" data-toggle="collapse">Keywords</a> | |
<div id = "keyword-collapse" class = "collapse"> | |
<div id="keywords"></div> | |
</div> | |
</div> | |
<!-- end attribute review--> | |
<div id="chart"></div> | |
<div class = "row"> | |
<a href="#graph-collapse" data-toggle="collapse">Graph</a> | |
<div id = "graph-collapse" class = "collapse"> | |
<div class = "container"> | |
<select class="productName js-states form-control" id="productName" name="productName" multiple="multiple"> </select> | |
<br> | |
Start Date: <br> | |
<label class="control-label" for="date">Date</label> | |
<input class="form-control" id="startdate" name="startdate" placeholder="YYYY-MM-DD" type="text"/><br> | |
End Date: <br> | |
<input class="form-control" id="enddate" name="enddate" placeholder="YYYY-MM-DD" type="text"/><br> | |
<input class="btn btn-primary " id="updategraph "name="updategraph" onclick="morrisLine()" value="Update Graph"><br> | |
</div> | |
</div> | |
</div> | |
</div> | |
</form> | |
<!-- jQuery library --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
<!-- Latest compiled JavaScript --> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script> | |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.20/jquery.fancybox.css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.20/jquery.fancybox.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/> | |
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css"> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script> | |
<!--enables fancybox for image gallery--> | |
<script type="text/javascript"> | |
$("[data-fancybox]").fancybox({ }); | |
</script> | |
<script type="text/javascript"> | |
//this is to pull your ID (ID=) | |
function getUrlParameter(sParam) { | |
var sPageURL = decodeURIComponent(window.location.search.substring(1)), | |
sURLVariables = sPageURL.split('&'), | |
sParameterName, | |
i; | |
for (i = 0; i < sURLVariables.length; i++) { | |
sParameterName = sURLVariables[i].split('='); | |
if (sParameterName[0] === sParam) { | |
return sParameterName[1] === undefined ? true : sParameterName[1]; | |
} | |
} | |
} | |
//defines it in a var for select2. | |
var get = getUrlParameter('ID'); | |
//send data to model | |
function sendGET() { | |
$.ajax({ | |
type: 'GET', | |
url: 'productmodel.php?ID=' + get, | |
success: function (data) { | |
} | |
}); | |
} | |
//select2's javascript | |
function selectmultiple() { | |
//defining the formatting of select2 - what it looks like when it returns. | |
function formatRepo (repo) { | |
//for some reason if you add the comma it doesnt work... to be debugged.... | |
repo = repo.title | |
return repo; | |
} | |
function formatRepoSelection (repo) | |
{ | |
return repo.title; | |
} | |
//begin select2 | |
$(".productName").select2({ | |
ajax: { | |
url: "multipleselect.php", | |
dataType: 'json', | |
delay: 250, | |
data: function (params) { | |
return { | |
q: params.term, // search term | |
troll: get | |
} | |
}, | |
processResults: function (data, params) { | |
// parse the results into the format expected by Select2. | |
// since we are using custom formatting functions we do not need to | |
//alter the remote JSON data | |
return{ | |
results: data.items | |
}; | |
}, | |
cache: true | |
}, | |
minimumInputLength: 0, | |
templateResult: formatRepo, | |
templateSelection: formatRepoSelection | |
}) | |
} | |
function morrisLine() | |
{ | |
var prodname = $(this).serialize(); | |
prodname = $('#productName').val(); | |
var startdate = $(this).serialize(); | |
startdate = $('#startdate').val(); | |
var enddate = $(this).serialize; | |
enddate = $('#enddate').val(); | |
$.ajax({ | |
type: 'GET', | |
url: 'morrisgraph.php', | |
data: {'prodname': prodname, 'startdate': startdate, 'enddate': enddate}, | |
success: function (data) { | |
var d1 = JSON.parse(data); | |
newMorris(d1); | |
} | |
}); | |
} | |
function newMorris(d1){ | |
$("#chart").empty(); | |
new Morris.Line({ | |
// ID of the element in which to draw the chart. | |
element: 'chart', | |
// Chart data records -- each entry in this array corresponds to a point on | |
// the chart. | |
data: d1.morris, | |
// The name of the data record attribute that contains x-values. | |
xkey: 'y', | |
// A list of names of data record attributes that contain y-values. | |
ykeys: d1.def, | |
// Labels for the ykeys -- will be displayed when you hover over the | |
// chart. | |
labels: d1.lab | |
}); | |
} | |
//makes magic happen when you click the start date inputbox | |
function startcalender() | |
{ | |
var date_input=$('input[name="startdate"]'); //our date input has the name "date" | |
var options={ | |
format: 'yyyy-mm-dd', | |
todayHighlight: true, | |
autoclose: true | |
}; | |
date_input.datepicker(options); | |
} | |
//makes magic happen when you click the end date input box. | |
function endcalender() | |
{ | |
var date_input=$('input[name="enddate"]'); //our date input has the name "date" | |
var options={ | |
format: 'yyyy-mm-dd', | |
todayHighlight: true, | |
autoclose: true | |
}; | |
date_input.datepicker(options); | |
} | |
$('#product').on('submit', function (e) | |
{ | |
var focusSet = false; | |
var startDate = new Date($('#startdate').val()); | |
var endDate = new Date($('#enddate').val()); | |
}); | |
function prodImg() | |
{ | |
$.ajax({ | |
type: 'GET', | |
url: 'ImageController.php?ID=' + get, | |
success: function (data) { | |
var imagestring = data; | |
$('.gallery').append(imagestring); | |
} | |
}); | |
} | |
function prodDetails(){ | |
$.ajax({ | |
type: 'GET', | |
url: 'DetailsController.php?ID=' + get, | |
success: function (data) { | |
var detailstring = data; | |
$('#proddetails').append(detailstring); | |
} | |
}); | |
} | |
function desc(){ | |
$.ajax({ | |
type: 'GET', | |
url: 'DescriptionController.php?ID=' + get, | |
success: function (data) { | |
var descstring = data; | |
$('#proddesc').append(descstring); | |
} | |
}); | |
} | |
function key() { | |
$.ajax({ | |
type: 'GET', | |
url: 'KeywordController.php?ID=' + get, | |
success: function (data) { | |
var keystr = data; | |
$('#keywords').append(keystr); | |
} | |
}); | |
} | |
function rev(){ | |
$.ajax({ | |
type: 'GET', | |
url: 'ReviewController.php?ID=' + get, | |
success: function (data) { | |
var revstring = data; | |
$('#reviews').append(revstring); | |
} | |
}); | |
} | |
function att(){ | |
$.ajax({ | |
type: 'GET', | |
url: 'AttController.php?ID=' + get, | |
success: function (data) { | |
var attstring = data; | |
$('#att').append(attstring); | |
} | |
}); | |
} | |
$(document).ready(function () { | |
sendGET(); | |
startcalender(); | |
endcalender(); | |
selectmultiple(); | |
prodImg(); | |
prodDetails(); | |
desc(); | |
key(); | |
rev(); | |
att(); | |
}); | |
</script> | |
</body> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: tanji | |
* Date: 7/17/2017 | |
* Time: 3:59 PM | |
*/ | |
include 'connection.php'; | |
try { | |
$id = $_GET["ID"]; | |
$checkdbq = "SELECT * FROM products WHERE proMkt_Item_ID = :getid"; | |
$checkitemx = $dbh->prepare($checkdbq); | |
$checkitemx->bindParam(':getid', $id, PDO::PARAM_INT); | |
$checkitemx->execute(); | |
} | |
catch(PDOException $e) | |
{ //else exception. self-explanatory | |
echo $e->getMessage(); | |
} | |
try { | |
$productsq = "SELECT * FROM products WHERE proMkt_Item_ID = :getid GROUP BY proTitle"; | |
$keywordsq = "SELECT * FROM keywords WHERE keyIDStr = :getid"; | |
$imagesq = "SELECT * FROM images WHERE imgProd_ID = :getid"; | |
$attributesq = "SELECT * FROM attributes WHERE attProd_ID = :getid"; | |
$reviewq = "SELECT * FROM review WHERE revProdID = :getid"; | |
$monthq = "SELECT proFetch_Time AS MonthOut from products WHERE proMkt_Item_ID = :getid GROUP BY MonthOut"; | |
$productsx = $dbh->prepare($productsq); | |
$productsx->bindParam(':getid', $id); | |
$productsx->execute(); | |
$keywordsx = $dbh->prepare($keywordsq); | |
$keywordsx->bindParam(':getid', $id); | |
$keywordsx->execute(); | |
$imagesx = $dbh->prepare($imagesq); | |
$imagesx->bindParam(':getid', $id); | |
$imagesx->execute(); | |
$attributesx = $dbh->prepare($attributesq); | |
$attributesx->bindParam(':getid', $id); | |
$attributesx->execute(); | |
$reviewx = $dbh->prepare($reviewq); | |
$reviewx->bindParam(':getid', $id); | |
$reviewx->execute(); | |
$monthx = $dbh->prepare($monthq); | |
$monthx->bindParam(':getid', $id); | |
$monthx->execute(); | |
$ddlq = "SELECT * FROM products where proMkt_Item_ID = :getid GROUP BY proTitle"; | |
$ddlqx = $dbh->prepare($ddlq); | |
$ddlqx->bindParam(':getid', $id); | |
$ddlqx->execute(); | |
$ddlqfetch = $ddlqx->fetchAll(); | |
} | |
catch(PDOException $e) | |
{ //else exception. self-explanatory | |
echo $e->getMessage(); | |
} | |
$rn =$productsx->fetch(); | |
$marid = $rn['proMkt_Name']; | |
$monthqfetch = $monthx->fetchall(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'connection.php'; | |
include 'productmodel.php'; | |
$string = ''; | |
$obtainrev = $reviewx->fetchAll(); | |
if(empty($obtainrev)) | |
{ | |
$string .= 'There are no reviews for this product!'; | |
} | |
else | |
{ | |
foreach ($obtainrev as $row) { | |
$revid = $row['revIDString']; | |
$reviewtt = $row['revTitle']; | |
$revcontent = $row['revContent']; | |
$revusn = $row['revUserName']; | |
$revsentiment = $row['revSentiment']; | |
$revrcmd = $row['revRecommend']; | |
$revscore = $row['revScore']; | |
$revpubd = $row['revPublishDate']; | |
$revpurcdate = $row['revPurcDate']; | |
$string.= ' Review ID:' . $revid . '<br> Review Title:' . $reviewtt . '<br> Content:' . $revcontent . '<br> Username:' . $revusn . | |
'<br>Sentiment:' . $revsentiment .'<br>Score: '.$revscore. '<br>Recommend:' . $revrcmd . '<br>Publish Date:' . $revpubd . '<br>Purchase Date:' . $revpurcdate . '<br><br>'; | |
} | |
} | |
echo $string; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment