Jump to content

ersaurabh101

New Members
  • Posts

    7
  • Joined

  • Last visited

ersaurabh101's Achievements

Member

Member (2/5)

0

Reputation

  1. I have only 1 record ( this is - username,password saved in my table) I need to select the username and count the no. of rows but both of the things not working, copying my code below SELECT STATEMENT: returning me [object][object] var selectStatement = "select username FROM loggedinuser"; var result; function getusername() { db.transaction(function (tx) { tx.executeSql(selectStatement,[],querySuccess); }); function querySuccess(tx, results) { for(var i=0; i<results.rows.length; i++) { var row = results.rows.item; result = { id: row['username']}; alert(result); } } } COUNT STATEMENT: below record is giving me result "1" at alert(len); var countStatement = "select COUNT(*) from loggedinuser"; var db = openDatabase("AddressBook", "1.0", "Address Book", 200000); // Open SQLite Database var user,password; function countRecord(tx) { db.transaction(function (tx) { tx.executeSql('SELECT count(*) FROM loggedinuser', [], querySuccess, errorCB); }); } function querySuccess(tx, results) { var len = results.rows.length; alert(len); } function errorCB(err) { alert("Error processing SQL: "+err.code); } countRecord(); Please help..
  2. Hii, For local sqlite storage i am following this tutorial - https://tejasrpatel.wordpress.com/2011/12/29/create-sqlite-off-line-database-and-insertupdatedeletedrop-operations-in-sqlite-using-jquery-html5-inputs/ I am using these commands to create a table in my login.html page - var createStatement = "CREATE TABLE IF NOT EXISTS userdetails (username TEXT, password TEXT, company TEXT)"; var db = openDatabase("QuickTask", "1.0", "Quick Task", 200000); // Open SQLite Database function initDatabase() // Function Call When Page is ready. { try { if (!window.openDatabase) // Check browser is supported SQLite or not. { alert('Databases are not supported in this browser.'); } else { createTable(); // If supported then call Function for create table in SQLite } } catch (e) { if (e == 2) { // Version number mismatch. console.log("Invalid database version."); } else { console.log("Unknown error " + e + "."); } return; } } function createTable() // Function for Create Table in SQLite. { db.transaction(function (tx) { tx.executeSql(createStatement, [], showRecords, onError); }); } After succesful login i am directing to welcome.html window.location.href = "welcome.html"; How do i access my tables on this page ? In console i am not finding any tables. I am trying to make an app [will make apk using phonegap] and stuck at the very beginning..Please help / Guide
  3. ohh, it should be ORDER BY RAND() , thanks worked , how to switch on php error reporting ?
  4. Hey, How you been, I was trying to work with json data in php and mysql using ajax Something strange is happening, when i comment the below line - // $row=mysqli_fetch_array($result,MYSQLI_ASSOC); <?php session_start(); $message=array(); include('database.php'); $sql="SELECT * from ratings ORDER BYRAND() LIMIT 1"; $result = mysqli_query($conn,$sql); $row=mysqli_fetch_array($result,MYSQLI_ASSOC); //$message["image"]=$row['image']; $message["message"]='hello'; //$message["message2"]='hello2'; header('content-type: application/json'); echo json_encode($message); I get the message in my console.log using ajax but when i uncomment this $row = mysqli_fetch_array.... i get nothing in my console log what is wrong in here ? I am on xampp 3.2.2 incase and there is no db error, also pasting my databse.php code just incase you wish to see <?php $DBServer = 'localhost'; $DBUser = 'root'; $DBPass = ''; $DBName = 'starrating'; $conn = new mysqli($DBServer,$DBUser,$DBPass,$DBName); if($conn->connect_error){ // echo $conn->connect_error; die('Connect Error: ' . $mysqli->connect_error); } function cleanup($data){ return mysql_real_escape_string(trim(htmlentities(strip_tags($data)))); } incase you want to see my jquery code, but i know its not related to this //ajax call $.ajax({ type:"POST", url:"server.php", datatype:"json", success: function(data){ console.log(data); } Also attaching both the files // $row=mysqli_fetch_array($result,MYSQLI_ASSOC); database.php index.html server.php
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.