Simple database structure:
If I do:
SELECT info FROM `wp_participants_database` WHERE standard = '456' AND zertifikatsnummer = 'iso777' AND _firmennamen = 'Firma789';
I get: "d", which is fine.
But when im using $wpdb, like here:
$query = "SELECT info FROM wp_participants_database WHERE standard = %d AND zertifikatsnummer = %d AND _firmennamen = %d";
$firmennamenx = $wpdb->get_row($wpdb->prepare( $query, '456', 'iso777', 'Firma789' ));
echo $firmennamenx->info;
I get: "b", why?
Try with below code
$query = "SELECT info FROM wp_participants_database WHERE standard = %d AND zertifikatsnummer = %s AND _firmennamen = %s";
$firmennamenx = $wpdb->get_row($wpdb->prepare( $query, '456', 'iso777', 'Firma789' ));
echo $firmennamenx->info;
Here %d is for the decimal values and %s for the string value. Your other fields are having the string value so for that you need to set %s
Hope now you got my point why you need to set %s.
Related
Retrieve a node based on condition:
$query = \Drupal::entityQuery('node')
->condition('type', 'my_content_type')
->condition('title', 'my node title');
$nid = $query->execute();
The result of $nid is the correct node ID but the format is a string, (es: "123")
When I want to load the node by its ID, I write:
$node_id = Node::load($nid);
Doing this, the result I get is NULL because the variable $nid is holding a string (not integer).
If I write the code like this:
$node_id = Node::load(123);
I get the node loaded.
How can I convert the variable string ($nid) as an integer ?
I tried:
$nid_int = (int) $nid;
$node_id = Node::load($nid_int);
also I tried:
$nid_int = intval($nid);
$node_id = Node::load($nid_int);
But I alwas get result NULL
Thanks for your help
You can't use Node::load($nid); directly, because the $query->execute() return an array like ['vid' => "nid"].
$query = \Drupal::entityQuery('node')
->condition('type', 'my_content_type')
->condition('title', 'my node title');
$nids = $query->execute();
$nid = (int)array_shift($nids);
Can try:-
$nid_string = $nid->__toString();
$node_id = Node::load((int) $nid_string);
First I make a request on google.com
Then I get the values.
And pull the date of the month.
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "https://google.com", False);
$oHTTP.Send();
$HeaderResponses = $oHTTP.GetAllResponseHeaders(); cookie
;$resp=$oHTTP.ResponseText; html
$date = StringRegExpReplace($HeaderResponses, '/^(?!.*$)(.*)$/', '/^(?!.*$)(.*)$/'); get date
FileWriteLine("test.txt", $date);
Not sure it will helpful or not I have used string functions for your query:
cpp
#include <StringConstants.au3>
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "https://google.com", False)
$oHTTP.Send()
$HeaderResponses = $oHTTP.GetAllResponseHeaders() ; cookie
;$resp = $oHTTP.ResponseText ; html
$datepostionstart = StringInStr($HeaderResponses,"Date:")
$datepostionstend = StringInStr($HeaderResponses,"GMT")
$firstsring = StringLeft($HeaderResponses,$datepostionstend-10)
MsgBox(1,"",$firstsring)
$date = StringTrimLeft($firstsring,$datepostionstart+10)
MsgBox(1,"",$date)
FileWriteLine("test.txt", "Cookie Date = "&$date)
I want to do a query like:
$qbFoo = $this->createQueryBuilder('foo');
$qbFoo->where($qbFoo->expr()-eq('foo.field', $value));
$qbProduct = $this->createQueryBuilder('product');
$qbProduct->select(['product'])
->addSelect(sprintf('(%s) as foo', $qbFoo->getDQL()))
->where($qbProduct->expr()->eq('product.id', $prodId));
$result = $qbProduct->getQuery()->getResult();
The value of $result will be:
$result[0][0] = {AppBundle\Entity\Product}
$result[0]['foo'] = 6 (6 is the value of foo.id)
How can I get the $result to be like:
$result[0][0] = {AppBundle\Entity\Product}
$result[0]['foo'] = {AppBundle\Entity\Foo}
I have a problem I'm generating an array with PHPExcel but to insert the date on the base gives an error because the date is in excel format and need mysql here is the code used
$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load( $targetFile );
$objPHPExcel->setActiveSheetIndex(0);
$lastRow = $objPHPExcel->getActiveSheet()->getHighestRow();
$dataExcel = array();
for ( $i = 2; $i <= $lastRow; $i++ ){
$dataExcel[$i]['usr_date_entry'] = $objPHPExcel->getActiveSheet()->getCell('K'.$i)->getCalculatedValue();
}
´echo $dataExcel[0]['usr_date_entry']; // return 21774´
I'm trying to get this working and the query executes but nothing comes back. I've tried everything I can think of, can you spot what I'm doing wrong?
$nido = $node->nid;
$result = db_query_range('
SELECT i.nid, i.iid, a.fid, p.filename, p.filepath
FROM {drup_image_attach} i
LEFT JOIN {drup_image} a ON i.iid = a.nid
LEFT JOIN {drup_files} p ON a.fid = p.fid
WHERE i.nid = %d AND p.filename = "recipe_thumb"', $nido, 0, 10);
echo "Filepath = " . $result ->filepath. "<br>";
echo "Filepath = " . $result ->filename . "<br>";
echo "IID = " . $result ->iid. "<br>";
echo "NID = " . $result ->nid . "<br>";
}
EDIT - I sorted out a couple of bits, but the output is still empty!
EDIT - this is the working code:
$nodeid = $node->nid;
$get_image = db_query('
SELECT p.filepath as imagefilename
FROM {image_attach} i
LEFT JOIN {image} a ON i.iid = a.nid
LEFT JOIN {files} p ON a.fid = p.fid
WHERE i.nid = %d AND p.filename = "recipe_thumb"', $nodeid);
$obj_image = db_fetch_object($get_image);
$imagefilename = $obj_image->imagefilename;
$result is a mysql(i) resource only. You first have to fetch the row/object.
$result = db_query_range(....);
$object = db_fetch_object($result);
print_r $object;
Assuming you have a range ob results not a single result this should work. You need to store the results in an array or process them in a different manner. for a single result see db_result()
$nodeid = $node->nid;
$get_image = db_query('
SELECT p.filepath as imagefilename
FROM {image_attach} i
LEFT JOIN {image} a ON i.iid = a.nid
LEFT JOIN {files} p ON a.fid = p.fid
WHERE i.nid = %d AND p.filename = "recipe_thumb"', $nodeid);
while(($obj_image = db_fetch_object($obj_image)) == TRUE){
$imagefilename[] = $obj_image->imagefilename;
}