Drupal DB Query - drupal-6

I have a problem with a custom query in drupal:
$brief = db_query("SELECT * FROMdr_wiwe_profile_valuesWHEREfid= 16 ANDuid= 266");
This query returns resource(286) of type (mysql result) resource(562) of type (mysql result) .
What is wrong with my query?

loop over the db resource object
$dbh = db_query("SELECT * FROM dr_wiwe_profile_values WHERE fid=16 AND uid=266");
$results = array();
while($row = db_fetch_array($dbh)){
$results[] = $row;
}

Related

Netsuite PHP Toolkit find Sale Order based on tranid

What I'm trying to do seems basic, and should be straight forward, but I'm obviously doing something wrong. I just want to return the Sales Order object based on the tranid. My code is as follows
require_once ('netsuite/PHPToolkit/NetSuiteService.php');
$ns = new NetSuiteService();
$ns->setSearchPreferences(false, 20);
$search = new TransactionSearchBasic();
$needle = new SearchStringField();
$needle->operator = "is";
$needle->searchValue = "SO1047429";
$search->tranid = $needle;
$req = new SearchRequest();
$req->searchRecord = $search;
try {
$res = $ns->search($req);
} catch (Exception $e) {
print_r ($e);
exit;
}
print_r ($res);
Problem is, this is returning every record we have in Netsuite....
SearchResponse Object
(
[searchResult] => SearchResult Object
(
[status] => Status Object
(
[statusDetail] =>
[isSuccess] => 1
)
[totalRecords] => 3569384
[pageSize] => 20
[totalPages] => 178470
I'm hoping that another set of eyes here can spot my error, as it's driving me nuts.
You've not specified "tranid" correctly - it needs a capital "I":
$search->tranid = $needle;
should read
$search->tranId = $needle;

Spatial query in sql database

hi I am currently developing a geo location based app which updates the user's location and displays the shops around him, I am using ordinary sql queries in sql database .My php code to select the shops around the user is :
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
if (isset($_POST['code']) && isset($_POST['lat']) && isset($_POST['lng'])) {
$code = $_POST['code'];
$lng = $_POST['lng'];
$lat = $_POST['lat'];
// get all data from table this is my code to fetch data where i need change
$result = mysql_query("SELECT *, ( 3959 * acos( cos( radians($lat) ) * cos( radians( lat ) ) * cos( radians(lng) - radians($lng) ) + sin( radians($lat) ) * sin( radians(lat)))) AS distance
FROM maintable
HAVING distance < 25
ORDER BY distance
") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["people"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$people = array();
$product["_id"] = $row["_id"];
$product["name"] = $row["name"];
$product["distance"] = $row["distance"];
$product["lat"] = $row["lat"];
$product["lng"] = $row["lng"];
$product["image_bit"] = $row["image_bit"];
$product["security"] = $row["security"];
$product["status"] = $row["status"];
$product["code"] = $row["country_code"];
$product["phone"] = $row["phone"];
// push single product into final response array
array_push($response["people"], $people);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No people found";
// echo no users JSON
echo json_encode($response);
}
}
else{
//required field is missing
$response["success"] = 0;
$response["message"] = "Required field missing";
// echoing JSON response
echo json_encode($response);
}
?>
i store the user's latitude and longitude values as lat and lng respectively.
But i recently heard about spatial datatype in sql,which will is more efficient, what i need to know is if i need to use spatial queries what change should be done in my lat and lng columns in sql table and can please anyone modify mysql query as a spatial query .any help would be appreciable
You can try a quadkey. Translate the points to a binary and interleave it. Treat it as base-4 number. The quadkey is similar to a quadtree but also it has interesting properties. It is often use for tiling.

Zend DB Table update affected rows are zero

I am updating the db table using below code but it does not seem to working fine.
$model = new Admin_Model_DbTable_SmsTemplate();
$where = $model->getDbTable()->getAdapter()->quoteInto('id = ?', $id);
$model->getDbTable()->update(array('content'=>$content), $where);
what is the error in this code as it is giving affected rows zero.
Thanks.
When using Zend_Db_table IN ZF1.
You can achieve it like this:-
$db=Zend_Db_Table::getDefaultAdapter();
$model = new Admin_Model_DbTable_SmsTemplate($db);
$where = 'id = ' . $id;
$model->update(array('content'=>$content), $where);
OR
$db=Zend_Db_Table::getDefaultAdapter();
$where = 'id = ' . $id;
$db->update('YourTableName', array('content = ?' => $content,),
$where
);
And the adapter will do quote work for you.

How store string with accent in MongoDB?

I use MongoDB and I want to store a string with accent but my database don't work if there are them.
If I take off it, it store string without problems.
foreach ($user as $key=>$value){
$value = utf8_encode($value);
}
$conn = new Mongo ();
if ($conn) {
$db = $conn->RecipeWorld;
$utenti = $db->users;
$result = $utenti->insert ( $user );
This code creates to me an empty database, only the name of it.
How can I resolve it?

node.js - differences with php

I have the following code in PHP:
$IDs = implode(",", array_keys($result["matches"]));
$sql = "SELECT * FROM table WHERE id IN ($IDs)";
I am "translating" it into Node.js, and I suppose that implode becomes array.join, so I tried this:
var ids = Object.keys(answer['matches']).join(",");
var sql = "SELECT * FROM xml_it WHERE id IN (" + ids + ")";
now, if I echo the PHP $sql variable, I get the expected result:
SELECT * FROM table WHERE id IN (3187,3220,3233,3245,3246,3251,3253,3256, ...
BUT, with node.js, I am getting this:
SELECT * FROM xml_it WHERE id_xml IN ([0,1,2,3,4, ...
The answer['matches'] obviously is the same result (it's basically a Sphinx search result)
Any idea why I am not getting it as a string but the keys?
the data of $result and var answer looks like this:
[{"doc":3187,"weight":1,"attrs":{}},{"doc":3220,"weight":1,"attrs":{}},{"doc":3233,"weight":1,"attrs":{}},
This should work:
var matches = answer['matches'].map( function( o ) {
return o.doc;
});
var ids = matches.join(",");
var sql = "SELECT * FROM xml_it WHERE id IN (" + ids + ")";
gotta map out the doc field since the structure is different

Resources