I have a part of code from php like this. Any two table tbl_gejala for change a sentence and tbl_hormon for move a Layout. Tbl_gejala with $id_g and tbl_hormon $id_h. and this php called by gejala.php.
I use 2 choice for this application, yes or no. $jawab == 1 for yes and $jawab == o for no.
$id_g = $_GET['id_g'];
$jawab = $_GET['a'];
$link = mysql_connect('localhost', 'root', '') or die ('Tidak bisa menampilkan');
mysql_select_db('hormon', $link) or die('Tidak bisa select');
if($id_g == 1 && $jawab == 1){
$query = "SELECT * from tbl_gejala where id_g = 3";
}elseif($id_g == 3 && $jawab == 1){
$query = "SELECT * from tbl_gejala where id_g = 5";
}elseif($id_g == 5 && $jawab == 1){
//intent activity and parseJSON with table hormon
$query = "SELECT * from tbl_hormon where id_h = 16";
}elseif($id_g == 5 && $jawab == 0){
$query = "SELECT * from tbl_gejala where id_g = 10";
}elseif($id_g == 10 && $jawab == 1){
$query = "SELECT * from tbl_hormon where id_h = 1";
}elseif($id_g == 10 && $jawab == 0){
$query = "SELECT * from tbl_hormon where id_h = 7";
I want to parseJSON with gejala.php in konsultasi.class
I have try this coding, but any problem by logic error. This coding like this:
void parseJSON(String response) {
try {
JSONObject json = new JSONObject(response);
listArray = new ArrayList<ListModel>();
JSONArray jArray = json.getJSONArray("Hormon");
log("lenght: " + jArray.length());
for (int i = 0; i < jArray.length(); i++) {
JSONObject jData = jArray.getJSONObject(i);
if(idPert.equals("5")&&yes.equals("1") ||
idPert.equals("7")&&yes.equals("1") ||
idPert.equals("11")&&yes.equals("1") ||
idPert.equals("11")&&no.equals("0") ||
idPert.equals("10")&&yes.equals("1") ||
idPert.equals("16")&&yes.equals("1") ||
idPert.equals("19")&&yes.equals("1") ||
idPert.equals("20")&&yes.equals("1") ||
idPert.equals("20")&&no.equals("0") ||
idPert.equals("8")&&yes.equals("1") ||
idPert.equals("17")&&yes.equals("1") ||
idPert.equals("17")&&no.equals("0") ||
idPert.equals("6")&&yes.equals("1") ||
idPert.equals("13")&&yes.equals("1") ||
idPert.equals("13")&&no.equals("0") ||
idPert.equals("12")&&yes.equals("1") ||
idPert.equals("14")&&yes.equals("1") ||
idPert.equals("15")&&yes.equals("1") ||
idPert.equals("18")&&yes.equals("1") ||
idPert.equals("21")&&yes.equals("1") ||
idPert.equals("22")&&yes.equals("1") ||
idPert.equals("10")&&no.equals("0")) {
id_h = jData.getString("id_h");
nm_penyakit = jData.getString("nm_penyakit");
definisi = jData.getString("definisi");
gejala = jData.getString("gejala");
penyebab = jData.getString("penyebab");
solusi = jData.getString("solusi");
gambar = jData.getString("gambar");
munculPenyakit = true;
}else{
idPert = jData.getString("id_g");
pertanyaan = jData.getString("gejala2")+"?";
munculPenyakit = false;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Please help me, thanks a lot before.
Related
I am attempting to have a script check sheet1 for first and last names (2 cells), use the first and last name of each person in sheet1, then in sheet2 check each person for a value in 4-5 rows greater than 0.
The issue is that certain names are in different columns and I need to check one column and have those names in that one column checked against a large (180 cells) list of names. This is the part where it times out.
I have the code fully functioning and working, but it uses some parts too heavily and ends up timing out. The getvalue function is used heavily and I am unsure of a better way to use it. I am looking for how to make it more efficient and or run better.
I may just have to input the names in the code to make it faster, but I was hoping for a more user-friendly approach so that names could change in sheet1 and format automatically in the script.
Thank you!
function getvalue(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2').getRange(CellName).getValues();
}
function getAdvisee(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1').getRange(CellName).getValues();
}
function teacher1() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var LastRow = ss.getLastRow();
var columns = 3;
var columnassignments = 3;
var columnEnrichment = 3;
var columnAmount = 3;
var advisoryStudent = getvalue('a' + columnEnrichment);
var studentEnrichment = getvalue('g'+ columnEnrichment);
var hours = Utilities.formatDate(studentEnrichment, 'EST', 'mm');
var minutes = Utilities.formatDate(studentEnrichment, 'EST', 'ss');
var teacherEmail = getAdvisee('b2');
var student1 = getAdvisee('b3');
var student1F = getAdvisee('b3');
var student2 = getAdvisee('b4');
var student2F = getAdvisee('b4');
var student3 = getAdvisee('b5');
var student3F = getAdvisee('b5');
var student4 = getAdvisee('b6');
var student4F = getAdvisee('b6');
var student5 = getAdvisee('b7');
var student5F = getAdvisee('b7');
var student6 = getAdvisee('b8');
var student6F = getAdvisee('b8');
var student7 = getAdvisee('b9');
var student7F = getAdvisee('c9');
var student8 = getAdvisee('b10');
var student8F = getAdvisee('c10');
var student9 = getAdvisee('b11');
var student9F = getAdvisee('c11');
var student10 = getAdvisee('b12');
var student10F = getAdvisee('c12');
var student11 = getAdvisee('b13');
var student11F = getAdvisee('c13');
for (columns; columns <= LastRow && columns <= 160; columns++) {
var advisoryStudent = getvalue('a' + columns);
var advisoryStudentSp = getvalue('b' + columns);
var reminderCount = getvalue('e' + columns);
var reminderLink = getvalue('m'+columns);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if ( getvalue('e' + columns) > 0 ) {
reminders = reminders + getvalue('b' + columns) + ' ' + getvalue('a' + columns) + ': ' + reminderCount + '<br>Reminder Link: ' + reminderLink + '<br>';
}
}
}
for (columnassignments; columnassignments <= LastRow && columnassignments <= 160; columnassignments++) {
var advisoryStudent = getvalue('a' + columnassignments);
var advisoryStudentSp = getvalue('b'+columnassignments);
var assignmentCount = getvalue ('f' + columnassignments);
var assignmentLink = getvalue('n' + columnassignments);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (getvalue('f' + columnassignments) > 0) {
assignments = assignments + getvalue('b' + columnassignments) + ' ' + getvalue('a' + columnassignments) + ': ' + assignmentCount + '<br>Assignment Link: ' + assignmentLink + '<br>';
}
}
}
for (columnAmount; columnAmount <= LastRow && columnAmount <= 160; columnAmount++) {
var advisoryStudent = getvalue('a' + columnAmount);
var advisoryStudentSp = getvalue('b' + columnAmount);
var amountowed = getvalue ('i' + columnAmount);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (getvalue('i' + columnAmount) > 0) {
amount = amount + getvalue('b' + columnAmount) + ' ' + getvalue('a' + columnAmount) + ': ' + '$' + amountowed + '<br>';
}
}
}
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Status Calculator');
var LastRow = ss.getLastRow();
var columns = 3;
var columnassignments = 3;
var columnEnrichment = 3;
for (columnEnrichment; columnEnrichment <= LastRow && columnEnrichment <= 160; columnEnrichment++) {
var advisoryStudent = getvalue('a'+columnEnrichment);
var advisoryStudentSp = getvalue('b' + columnEnrichment);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'HH') > 0 || Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'mm') > 0){
enrichment = enrichment + getvalue('b' + columnEnrichment) + ' ' + getvalue('a' + columnEnrichment) + ': ' + Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'HH') + ' hours ' + Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'mm') + ' minutes <br>'
}
}
}
}
EDIT:
This portion just has a list of names in one column and searches for one word in the entire 200 row column and returns the rows with that word, then returns it again if it is greater than 5.
If I had it just looking for numbers greater than or equal to 5 and using a getvalue function, would that be the most efficient way to return names with values of 5 or more?
function getValues(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(CellName).getValues();
}
function setvalue(CellName, value) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(CellName).setValue(value);
}
function test(i) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh2 = ss.getSheetByName('Sheet2');
var data = sh2.getRange('A1:C200').getValues();
var amount = sh2.getRange('c1:c200').getValues()
var findthis = sh2.getRange('e1').getValues();
var acol = sh2.getRange(1,sh2.getLastRow(),1,1).getValues();
var bcol = sh2.getRange(1,sh2.getLastRow(), 2, 1).getValues();
var test = acol.join().split(',');
var test2 = bcol.join().split(',');
for (i = 0; i<data.length; i++) { //search all rows
if ('wet' == data[i][0]) { //finds wet in the data column and returns row
Logger.log('testing' + ' row ' + (i+1))
if (amount[i][0] >= 5) { //search if c >= 5
Logger.log('Larger ' + ' row ' + (i+1))
}
}
}
}
I would suggest grouping your data into arrays by its natural grid ranges and then accessing the values by array index.
Something along the lines of:
function teacher1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh_1 = ss.getSheetByName('sheet1');
var sh_2 = ss.getSheetByName('sheet2');
...
// Get all related values into array & retrieve each row record by index
var student = sh_1.getRange("B3:C13").getValues(); // student[row][col] :ex: student11 => student[12][0]::student11F => student[12][1]
...
// remove the for loop & get all values in a col with one call per col
//(this could be optimized further)
var a_col = sh_2.getRange(1, sh_2.getLastRow(), 1, 1).getValues(); // col a rows 1-lastrow()
var b_col = sh_2.getRange(1, sh_2.getLastRow(), 2, 1).getValues(); // col b rows 1-lastrow()
// Flatten the array to make searching that column easier
var advisoryStudent = a_col.join().split(",")
var advisoryStudentSp = b_col.join().split(",")
// etc ...
// To check if student11 is in advisoryStudentSp: (can loop through students here)
// -1 means not found
// any other number is the index position of `advisoryStudentSp[i]`
// if 5 is returned then student11 matched the value in sheet2 colB row6
Logger.log("student11 is in position: %s", advisoryStudentSp.indexOf(student[12][0]))
}
edit: added the somewhat important .getValues()
Rather than retrieve the cell values one by one using your getValue() / getAdvisee() formulas you need to read the entire sheets or the relevant ranges all at once using Range.getValues(), then work with the data in the arrays.
The key issue here is that each individual call to Range.getValues() consumes a lot of time, whether you read in 100 cells at once or a single cell value. Thus your current approach of reading in one cell at a time is extremely slow (as you are seeing).
Refactoring in this way is too large to undertake as part of my answer, but once completed this script will run in just a couple seconds.
I've five fields- rate, qty. discount, cgst_percent, cgst_amount.
I want to calculate cgst_amount. The formula should be -
cgst_amount = ((rate*qty - (rate*qty*discount)/100)*cgst_percent)/100
To Start with simple steps, I tried cgst_amount = rate*qty
The javascript part is as below -
<?php
/* start getting the cgst */
$script = <<< JS
function getGst(item) {
var index = item.attr("id").replace(/[^0-9.]/g, "");
var qtyvar = ratevar = discvar = cgstpercentvar = cgstvar = 0;
var id = item.attr("id");
var myString = id.split("-").pop();
if (myString == "rate") {
fetch1 = index.concat("-qty");
fetch2 = index.concat("-discount");
fetch3 = index.concat("-cgst_rate");
} else if (myString == "qty") {
fetch1 = index.concat("-rate");
fetch2 = index.concat("-discount");
fetch3 = index.concat("-cgst_rate");
} else if (myString == "discount"){
fetch1 = index.concat("-qty");
fetch2 = index.concat("-rate");
fetch3 = index.concat("-cgst_rate");
} else {
fetch1 = index.concat("-qty");
fetch2 = index.concat("-rate");
fetch3 = index.concat("-discount");
}
temp1 = $("#productsales-"+fetch1+"").val();
temp2 = $("#productsales-"+fetch2+"").val();
temp3 = $("#productsales-"+fetch3+"").val();
//alert (temp2);
if (!isNaN(temp1) && temp1.length != 0) {
ratevar = temp1;
}
if (isNaN(temp2) || temp2.length != 0) {
discvar = temp2;
}
if (isNaN(temp3) || temp3.length != 0) {
cgstpercentvar = temp3;
}
qtyvar = item.val();
if (isNaN(qtyvar) || qtyvar.length == 0) {
qtyvar = 0;
}
//alert (qtyvar);
if (!isNaN(qtyvar) && !isNaN(ratevar) && !isNaN(discvar) && !isNaN(cgstpercentvar)) {
cgstvar = (parseFloat(qtyvar) * parseFloat(ratevar)).toFixed(2);
}
cgstField = "productsales-".concat(index).concat("-cgst_amount");
$("#"+cgstField+"").val(cgstvar);
}
JS;
$this->registerJs($script, View::POS_END);
/* end getting the cgst */
?>
Whn I key in rate and qty I get multiply of them as output in cgst_amount textbox. No problem so far. As soon as I key in anything in discount,the same texts are getting written in cgst_amount as output.
I'm not quite sure about the javascript part.
It is an extension of - Calculate from 3 inputfield in dynamic form yii2 and Calculate 3 fields and display the result in the 4th in yii2 dynamic form
If I work on the full formula, the javascript calculation part becomes - cgstvar = ((((parseFloat(ratevar) * parseFloat(qtyvar)) - (parseFloat(ratevar) * parseFloat(qtyvar) * parseFloat(discvar))/100) * parseFloat(cgstpercentvar))/100).toFixed(2);
And the example is as below image -
The actual result should have been - 5.43. Instead I'm getting -0.00
You meshed up with fields and variables, i have updated a script a bit :
function getGst(item) {
var index = item.attr("id").replace(/[^0-9.]/g, "");
var qtyvar = ratevar = discvar = cgstpercentvar = cgstvar = 0;
var id = item.attr("id");
var myString = id.split("-").pop();
quantity = index.concat("-qty");
rate = index.concat("-rate");
discount = index.concat("-discount");
cgstRate = index.concat("-cgst_rate");
temp1 = $("#productsales-"+quantity+"").val();
temp2 = $("#productsales-"+rate+"").val();
temp3 = $("#productsales-"+discount+"").val();
temp4 = $("#productsales-"+cgstRate+"").val();
if (isNaN(temp1) || temp1.length != 0) {
qtyvar = temp1;
}
if (!isNaN(temp2) && temp2.length != 0) {
ratevar = temp2;
}
if (isNaN(temp3) || temp3.length != 0) {
discvar = temp3;
}
if (isNaN(temp4) || temp4.length != 0) {
cgstpercentvar = temp4;
}
if (!isNaN(qtyvar) && !isNaN(ratevar) && !isNaN(discvar) && !isNaN(cgstpercentvar)) {
cgstvar = ((((parseFloat(ratevar) * parseFloat(qtyvar)) - (parseFloat(ratevar) * parseFloat(qtyvar) * parseFloat(discvar))/100) * parseFloat(cgstpercentvar))/100).toFixed(2);
}
cgstField = "productsales-".concat(index).concat("-cgst_amount");
$("#"+cgstField+"").val(cgstvar);
}
I have a simple form for update image name into mysql database, but unfortunately it always throw the error SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens. The code seems OK, but I don't know it cannot update the database. Any help is appreciated.
Here is the image name and the SQL that I have printed out.
Array
(
[0] => 20141027103534_0.jpg
[1] => 20141027103534_1.jpg
[2] =>
[3] =>
[4] =>
[5] => 20141027103534_5.jpg
[6] => 20141027103534_6.jpg
[7] =>
[8] =>
[9] =>
)
UPDATE `image`
SET
`propertyPictureCate1` = :propertyPictureCate1,
`propertyPictureCate2` = :propertyPictureCate2,
`propertyPictureCate3` = :propertyPictureCate3,
`propertyPictureCate4` = :propertyPictureCate4,
`propertyPictureCate5` = :propertyPictureCate5,
`memo1` = :memo1,
`memo2` = :memo2,
`memo3` = :memo3,
`memo4` = :memo4,
`memo5` = :memo5,
`spotPictureCate1` = :spotPictureCate1,
`spotPictureCate2` = :spotPictureCate2,
`spotPictureCate3` = :spotPictureCate3,
`spotPictureCate4` = :spotPictureCate4,
`spotPictureCate5` = :spotPictureCate5,
`spotName1` = :spotName1,
`spotName2` = :spotName2,
`spotName3` = :spotName3,
`spotName4` = :spotName4,
`spotName5` = :spotName5,
`distance1` = :distance1,
`distance2` = :distance2,
`distance3` = :distance3,
`distance4` = :distance4,
`distance5` = :distance5,
`img1` = :img1,
`img2` = :img2,
`img6` = :img6,
`img7` = :img7
WHERE `buildingID` = :buildingID
the image name within bindParam that I tested to print out.
img1 20141027103534_0.jpg
img2 20141027103534_1.jpg
img6 20141027103534_5.jpg
img7 20141027103534_6.jpg
and below is my code for above result
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$file_name = [];
for ($i = 0; $i < count($_FILES['file']['tmp_name']); $i++) {
if($_FILES['file']['error'][$i] != 4) {
$validextensions = array("jpeg", "jpg", "png","gif");
$ext = explode('.', basename($_FILES['file']['name'][$i]));
$file_extension = end($ext);
$file_name[$i] = date("Ymdhis") . "_". $i . "." . $ext[count($ext) - 1];
$target_path = $_SERVER['DOCUMENT_ROOT'] . "/".PROJ_DIR."/uploads/" . date("Ymdhis") . "_". $i . "." . $ext[count($ext) - 1];
move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path);
} else {
$file_name[$i] = "";
}
}
try {
$sql = "
UPDATE `image`
SET
`propertyPictureCate1` = :propertyPictureCate1,
`propertyPictureCate2` = :propertyPictureCate2,
`propertyPictureCate3` = :propertyPictureCate3,
`propertyPictureCate4` = :propertyPictureCate4,
`propertyPictureCate5` = :propertyPictureCate5,
`memo1` = :memo1,
`memo2` = :memo2,
`memo3` = :memo3,
`memo4` = :memo4,
`memo5` = :memo5,
`spotPictureCate1` = :spotPictureCate1,
`spotPictureCate2` = :spotPictureCate2,
`spotPictureCate3` = :spotPictureCate3,
`spotPictureCate4` = :spotPictureCate4,
`spotPictureCate5` = :spotPictureCate5,
`spotName1` = :spotName1,
`spotName2` = :spotName2,
`spotName3` = :spotName3,
`spotName4` = :spotName4,
`spotName5` = :spotName5,
`distance1` = :distance1,
`distance2` = :distance2,
`distance3` = :distance3,
`distance4` = :distance4,
`distance5` = :distance5".
$s1 = (($file_name[0] != "") ? ",\n`img1` = :img1" : NULL).
$s2 = (($file_name[1] != "") ? ",\n`img2` = :img2" : NULL).
$s3 = (($file_name[2] != "") ? ",\n`img3` = :img3" : NULL).
$s4 = (($file_name[3] != "") ? ",\n`img4` = :img4" : NULL).
$s5 = (($file_name[4] != "") ? ",\n`img5` = :img5" : NULL).
$s6 = (($file_name[5] != "") ? ",\n`img6` = :img6" : NULL).
$s7 = (($file_name[6] != "") ? ",\n`img7` = :img7" : NULL).
$s8 = (($file_name[7] != "") ? ",\n`img8` = :img8" : NULL).
$s9 = (($file_name[8] != "") ? ",\n`img9` = :img9" : NULL).
$s10 = (($file_name[9] != "") ? ",\n`img10` = :img10" : NULL).
" \nWHERE `buildingID` = :buildingID
";
echo '<pre>';
print_r($file_name);
echo '</pre>';
echo '<pre>';
print_r($sql);
echo '</pre>';
$stmt = $con->prepare($sql);
$stmt->bindParam(":propertyPictureCate1",$_POST['propertyPictureCate1']);
$stmt->bindParam(":propertyPictureCate2",$_POST['propertyPictureCate2']);
$stmt->bindParam(":propertyPictureCate3",$_POST['propertyPictureCate3']);
$stmt->bindParam(":propertyPictureCate4",$_POST['propertyPictureCate4']);
$stmt->bindParam(":propertyPictureCate5",$_POST['propertyPictureCate5']);
$stmt->bindParam(":memo1",$_POST['memo1']);
$stmt->bindParam(":memo2",$_POST['memo2']);
$stmt->bindParam(":memo3",$_POST['memo3']);
$stmt->bindParam(":memo4",$_POST['memo4']);
$stmt->bindParam(":memo5",$_POST['memo5']);
$stmt->bindParam(":spotPictureCate1",$_POST['spotPictureCate1']);
$stmt->bindParam(":spotPictureCate2",$_POST['spotPictureCate2']);
$stmt->bindParam(":spotPictureCate3",$_POST['spotPictureCate3']);
$stmt->bindParam(":spotPictureCate4",$_POST['spotPictureCate4']);
$stmt->bindParam(":spotPictureCate5",$_POST['spotPictureCate5']);
$stmt->bindParam(":spotName1",$_POST['spotName1']);
$stmt->bindParam(":spotName2",$_POST['spotName2']);
$stmt->bindParam(":spotName3",$_POST['spotName3']);
$stmt->bindParam(":spotName4",$_POST['spotName4']);
$stmt->bindParam(":spotName5",$_POST['spotName5']);
$stmt->bindParam(":buildingID",$_POST['buildingID']);
if($file_name[0] !== ""){
echo 'img1 '.$file_name[0].'<br>';
$stmt->bindParam(":img1", $file_name[0]);
}
if($file_name[1] !== ""){
echo 'img2 '.$file_name[1].'<br>';
$stmt->bindParam(":img2", $file_name[1]);
}
if($file_name[2] !== ""){
echo 'img3 '.$file_name[2].'<br>';
$stmt->bindParam(":img3", $file_name[2]);
}
if($file_name[3] !== ""){
echo 'img4 '.$file_name[3].'<br>';
$stmt->bindParam(":img4", $file_name[3]);
}
if($file_name[4] !== ""){
echo 'img5 '.$file_name[4].'<br>';
$stmt->bindParam(":img5", $file_name[4]);
}
if($file_name[5] !== ""){
echo 'img6 '.$file_name[5].'<br>';
$stmt->bindParam(":img6", $file_name[5]);
}
if($file_name[6] !== ""){
echo 'img7 '.$file_name[6].'<br>';
$stmt->bindParam(":img7", $file_name[6]);
}
if($file_name[7] !== ""){
echo 'img8 '.$file_name[7].'<br>';
$stmt->bindParam(":img8", $file_name[7]);
}
if($file_name[8] !== ""){
echo 'img9 '.$file_name[8].'<br>';
$stmt->bindParam(":img9", $file_name[8]);
}
if($file_name[9] !== ""){
echo 'img10 '.$file_name[9].'<br>';
$stmt->bindParam(":img10", $file_name[9]);
}
//$stmt->debugDumpParams();
$stmt->execute();
$con = null;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
You forgot to bind distance parameters to your statement.
Before calling $stmt->execute(), you should either add these lines for binding to $stmt
$stmt->bindParam(":distance1",$_POST['distance1']);
$stmt->bindParam(":distance2",$_POST['distance2']);
$stmt->bindParam(":distance3",$_POST['distance3']);
$stmt->bindParam(":distance4",$_POST['distance4']);
$stmt->bindParam(":distance5",$_POST['distance5']);
or remove these lines from you $sql string variable
`distance1` = :distance1,
`distance2` = :distance2,
`distance3` = :distance3,
`distance4` = :distance4,
`distance5` = :distance5
i have a mysql table
||==========||==========||==========||
|| id || name || age ||
||==========||==========||==========||
|| 1 || joe || 10 ||
|| 2 || harry || 20 ||
|| 3 || jane || 45 ||
|| 4 || john || 56 ||
|| 5 || larry || 89 ||
|| 6 || henry || 23 ||
|| 7 || steve || 25 ||
|| 8 || eric || 56 ||
|| 9 || dave || 98 ||
|| 10 || mat || 56 ||
||==========||==========||==========||
i need the sql query that would make an associative array from this table and give me values like this
id=>age
1=>10
4=>56
i also need to make all the id's as a variable where there value would be the age like
$1 = 10
$4 = 56
or if i could add a prefix to the variables
$id_1 = 10
$id_4 = 56
thanks in advance
In PHP, mysql_fetch_assoc() takes the result of a query, and returns one row as an associative array. Call it repeatedly to get all rows.
if your using php for fetching your data you may use the function mysql_fetch_array example:
while($row = mysql_fetch_assoc($resource))
{
echo $row['name'].'<br>';
}
you may know more about mysql functions for php on this site: http://www.php.net/manual/en/book.mysql.php
$ids = '1, 4';
$sql = "select age from __TABLE__ where id in ( {$ids} )";
$link = mysql_connect('__SERVER__', '__DBUSER__', '__DB_PWD__') or die('connect error');
$db = mysql_select_db('__DBNAME__', $link) or die('db error');
$rs = mysql_query($sql, $link);
$result = array();
while($row = mysql_fetch_assoc($rs))
{
$result[] = $row;
}
extract(my_result($result));
var_dump($id_1);
var_dump($id_4);
function my_result($result, $prefix = 'id_')
{
$data = array();
foreach($result as $k => $v)
{
$data[$prefix . $v['id']] = $v['order_no'];
}
return $data;
}
So I'm attempting to run a webpage that shows security camera feeds for a client. However it does not render properly at all and only shows the background. I have a feeling it has to do with a limitation of the iframe tag, since using other iframe testing gadgets online I get the same results. Other clients are using camera feeds with a different interface and my solution works fine for them. Are there any alternatives to iframe?
edit: The page actually renders perfectly fine when being visited directly, and not through an iframe.
edit2: By popular request here is the source for the security feed site. I did not post my iframe code, since no matter what I use for iframe it will not display.
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="expires" content="-1">
<title>:::</title>
<script language="JavaScript" src="/js/lgSource.js"></script>
<script language="JavaScript" src="/js/data_init.js"></script>
<script language="javascript" src="/js/AVUtility.js"></script>
<script language="JavaScript">
var d = document ;
d.write( "<frameset frameSpacing=0 rows='37,*' frameBorder='no' >" ) ;
d.write( " <frame name='ban' src='' scrolling='no'>" ) ;
d.write( " <frameset frameSpacing=0 frameBorder='no' cols='*,195'>" ) ;
d.write( " <frame name='main' src='home.htm' scrolling='auto'>" ) ;
d.write( " <frame name='left' src='' noResize scrolling='no'>" ) ;
d.write( " </frameset>" ) ;
d.write( "</frameset>" ) ;
d.write( "<noframes><body><p>no frame</p></body></noframes>" ) ;
var httpObj,httpObj2,httpObj3;
//alert("Code in NFS. H264 \n\n charset=utf-8");
//top.dt.user.SupportLG = "ENGLISH&CHINESE&"
loadSupportLanguage();
//loadUserPwd();
function loadSupportLanguage()
{
httpObj3 = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/nobody/Machine.cgi?action=get_capability";
httpObj3.onreadystatechange = updSL;
requestCgiParam(httpObj3, requestData);
}
function updSL()
{
if (httpObj3.readyState == 4 && httpObj3.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj3.responseText;
if (GetCgiParam(objStr,"Language.Support=") == 1)
if (objStr.strGet != "")
top.dt.user.SupportLG = objStr.strGet;
loadUserPwd();
}
}
function loadUserPwd()
{
httpObj = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/guest/UserInfo.cgi?action=query";
httpObj.onreadystatechange = updUserPwd;
requestCgiParam(httpObj, requestData);
}
function updUserPwd()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
if (GetCgiParam(objStr, "Username=") == 1)
top.dt.user.username = objStr.strGet;
if (GetCgiParam(objStr, "Password=") == 1)
top.dt.user.password = objStr.strGet;
loadLogin();
}
}
function loadLogin()
{
httpObj2 = createHttpRequestObj();
requestData = "http://"+getURL()+"/cgi-bin/guest/Login.cgi?rnd="+Math.random();
httpObj2.onreadystatechange = updLogin;
httpObj2.open("get", requestData, true);
httpObj2.send(null);
}
function updLogin()
{
if (httpObj2.readyState == 4 && httpObj2.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj2.responseText;
if (GetCgiParam(objStr,"Server-Language=") == 1)
{
if(objStr.strGet.toUpperCase() == "CHINESE")
top.dt.user.language = 2;
else if(objStr.strGet.toUpperCase() == "GREEK")
top.dt.user.language = 3;
else
top.dt.user.language = 1;
}
if (GetCgiParam(objStr, "Video-System=") == 1)
top.dt.user.VideoSystem = objStr.strGet;
if (GetCgiParam(objStr, "User-Level=") == 1)
top.dt.user.ulevel = objStr.strGet;
if (GetCgiParam(objStr, "Product-ShortName=") == 1)
{
if(objStr.strGet == "V_Indep")
top.dt.user.IndepFlag = true;
}
//top.dt.user.NatSupport = true;
//top.dt.user.PosSupport = true;
if (GetCgiParam(objStr, "Capability=") == 1)
{
tmpStr = objStr.strGet.split(",");
if(tmpStr.length==4){
if(parseInt(tmpStr[3],16)&0x01)
top.dt.user.isDvrPtz = true;
if(parseInt(tmpStr[2],16)&0x01)
top.dt.user.DvrHaSupport = true; // HA
if(parseInt(tmpStr[2],16)&0x02)
top.dt.account.NotifySys = true; //3G Notify
if(parseInt(tmpStr[2],16)&0x04)
top.dt.user.NatSupport = true; //NAT
if(parseInt(tmpStr[2],16)&0x08)
top.dt.user.RfidSupport = true; //RFID
if(parseInt(tmpStr[1],16)&0x01)
top.dt.user.PosSupport = true; //POS
}
}
if (GetCgiParam(objStr, "Product-ID-Minor=") == 1)
{
top.dt.user.ProductID = objStr.strGet;
var pid = objStr.strGet;
// Video Channel (default: 4 ch)
if(pid == "787" || pid == "718" || pid == "616" || pid == "757" || pid == "677" || pid == "678" || pid == "DG1648" || pid == "798"){
top.dt.user.dvrCh = 16;
}
else if (pid == "785" || pid == "608" || pid == "716" || pid == "755" || pid == "675" || pid == "676" || pid == "DG0824" || pid == "796"){
top.dt.user.dvrCh = 8;
}
else if (pid == "783" || pid == "604" || pid == "604F" || pid == "714" || pid == "724" || pid == "DG0412" || pid == "763" || pid == "764" || pid == "760A" || pid == "761A" || pid == "041"){
top.dt.user.dvrCh = 4;
}
else{
top.dt.user.dvrCh = 4; /* default 4 ch */
}
// Audio Channel
if(pid == "DG0824" || pid == "608" || pid == "DG1648" || pid == "616" || pid == "718" || pid == "757" || pid == "755" || pid == "675" || pid == "676" || pid == "677" || pid == "678" || pid == "724" || pid == "764" || pid == "673" || pid == "674" || pid == "683" || pid == "796" || pid == "798"){
top.dt.user.soundCh = 4;
}
else if (pid == "732E" || pid == "DG0412" || pid == "714"){
top.dt.user.soundCh = 2;
}
else if (pid == "733" || pid == "944" || pid == "945" || pid == "946" || pid == "311" || pid == "321" || pid == "202" || pid == "212" || pid == "604F" || pid == "203" || pid == "671" || pid == "672" || pid == "681"){
top.dt.user.soundCh = 1;
}
else{
top.dt.user.soundCh = 0;
}
//Top-Page
if(top.dt.user.ulevel != "SUPERVISOR" || pid == "203" || pid == "763")
top.dt.user.topSrc = "/top2.htm";
else
top.dt.user.topSrc = "/top.htm";
//show Left-Page
if(pid == "311" || pid == "321"){
top.dt.user.leftSrc = "/left_ipcam.htm";
top.dt.user.confSrc = "/left_ipcam_config.htm";
top.dt.user.ProductType = "IP CAMERA";
top.dt.user.isAutomoveSupport = true;
}
else if(pid == "203"){
top.dt.user.leftSrc = "/left_ipcam_h264.htm";
top.dt.user.ProductType = "IP CAMERA";
}
else{
if(pid == "763"){
top.dt.user.leftSrc = "/left_home763.htm";
}else if(pid == "798" || pid == "796"){
top.dt.user.leftSrc = "/left_home16ch.htm";
}
else{
top.dt.user.leftSrc = "/left_home.htm";
}
top.dt.user.confSrc = "/left_config.htm";
top.dt.user.ProductType = "DVR";
}
//show Title
if(pid == "764" || pid == "671" || pid == "672" || pid == "673" || pid == "674" || pid == "681" || pid == "683" || pid == "203" || pid == "796" || pid == "798" || pid == "041"){
top.dt.user.MediaType = "H264";
document.title = "H264 "+ top.dt.user.ProductType;
}
else
document.title = "MPEG4 "+ top.dt.user.ProductType;
if(top.dt.user.ulevel == "SUPERVISOR")
if(top.dt.user.ProductType == "DVR")
loadRecImageSize();
else
chkNatFirstUse();
else
loadMainPage();
}
}
}
function loadRecImageSize()
{
httpObj = createHttpRequestObj();
var requestData = "http://"+getURL()+"/cgi-bin/user/Config.cgi?action=get&category=DVR.Record.*";
httpObj.onreadystatechange = updRecImageSize;
requestCgiParam(httpObj, requestData);
}
function updRecImageSize()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
if (GetCgiParam(objStr,"ImageSize=") == 1){
top.dt.user.DVR_Record_ImageSize = objStr.strGet;
chkNatFirstUse();
}
}
}
function chkNatFirstUse()
{
httpObj = createHttpRequestObj();
var requestData = "http://"+getURL()+"/cgi-bin/user/Config.cgi?action=get&category=Network.NAT.*";
httpObj.onreadystatechange = updNatFirstUse;
requestCgiParam(httpObj, requestData);
}
function updNatFirstUse()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
var objStr = new Object();
objStr.strSrc = httpObj.responseText;
var FirstUseNatFlag = false;
if (GetCgiParam(objStr,"FirstUse=") == 1)
if(objStr.strGet == "YES")
FirstUseNatFlag = true;
if (GetCgiParam(objStr,"Hostname=") == 1)
top.dt.user.NatName = objStr.strGet;
if(FirstUseNatFlag)
showNatFirstUseWeb();
else
loadMainPage();
}
}
function showNatFirstUseWeb()
{
top.ban.location.replace("/top2.htm");
top.left.location.replace("/left_empty.htm");
top.main.location.replace("/combo/nat_firstuse.htm");
}
function loadMainPage()
{
top.dt.user.mainSrc = "/home.htm";
top.ban.location.replace(top.dt.user.topSrc);
top.left.location.replace(top.dt.user.leftSrc);
}
</script>
</html>
The page actually renders perfectly
fine when being visited directly, and
not through an iframe.
The only thing I can think of that the page has a frame busting technique.
You can read a little about it here.
I can't help you much more without the code!