I have such a query and I want to get how many records have been added or updated.
$insertData = Lpis::UpdateOrCreate(['objectid' => $insert[$i]['objectid']],['identyfikator' => $insert[$i]['identyfikator'],'powierzchnia' => $insert[$i]['powierzchnia'],'teryt' => $insert[$i]['teryt'],'numer' => $insert[$i]['numer'],'wojewodztwo' => $insert[$i]['wojewodztwo'],'powiat' => $insert[$i]['powiat'],'gmina' => $insert[$i]['gmina'],'data_od' => $insert[$i]['data_od'],'shape_leng' => $insert[$i]['shape_leng'],'shape_area' => $insert[$i]['shape_area']]);
Anyone help ?
I am trying to display double variable inside an Smarty environment converting it into int.
The File configuring the variables has the following code.
The Variable PRODUCTS_Quantity_x is the viewed Variable which I added. It is giving me a comma separated value with 3 fractional digits. The {$module_data.PRODUCTS_Quantity} is already be able to get displayed in through the html.
I have already tryed things like count() etc. I mostly got an empty variable or smarty errors ...
$t_data_array = array ( 'PRODUCTS_NAME' => htmlspecialchars_wrapper($array['products_name']),
'COUNT' => $array['ID'],
'PRODUCTS_ID' => $array['products_id'],
'PRODUCTS_VPE' => $this->getVPEtext($array, $products_price['plain']),
'PRODUCTS_IMAGE' => $this->productImage($array['products_image'], $image),
'PRODUCTS_IMAGE_W' => $array['products_image_w'],
'PRODUCTS_IMAGE_H' => $array['products_image_h'],
'PRODUCTS_IMAGE_WIDTH' => PRODUCT_IMAGE_THUMBNAIL_WIDTH,
'PRODUCTS_IMAGE_PADDING' => ((PRODUCT_IMAGE_THUMBNAIL_HEIGHT + 8) - $array['products_image_h'])/2,
'PRODUCTS_IMAGE_ALT' => $array['gm_alt_text'],
'PRODUCTS_LINK' => $gm_product_link,
'PRODUCTS_PRICE' => $products_price['formated'],
'PRODUCTS_TAX_INFO' => $gm_tax_info,
'PRODUCTS_SHIPPING_LINK' => $gm_shipping_link,
'PRODUCTS_BUTTON_BUY_NOW' => $buy_now,
'GM_PRODUCTS_BUTTON_BUY_NOW_URL' => $gm_buy_now_url,
'GM_PRODUCTS_BUTTON_BUY_NOW' => $gm_buy_now,
'PRODUCTS_SHIPPING_NAME' => $shipping_status_name,
'PRODUCTS_SHIPPING_IMAGE' => $shipping_status_image,
'PRODUCTS_DESCRIPTION' => $array['products_description'],
'PRODUCTS_EXPIRES' => $array['expires_date'],
'PRODUCTS_CATEGORY_URL' => $array['cat_url'],
'PRODUCTS_SHORT_DESCRIPTION' => $array['products_short_description'],
'PRODUCTS_FSK18' => $array['products_fsk18'],
'GM_FORM_ACTION' => xtc_draw_form('gm_add_to_cart_'.$array['products_id'], xtc_href_link('index.php', 'action=buy_now&BUYproducts_id=' . $array['products_id'] . $gm_cat_search, 'NONSSL', true, true, true), 'post', 'onsubmit="return gm_quantity_check_listing(\'' . $array['products_id'] . '\')"'),
'FORM_DATA' => $t_form_array,
'QTY_DATA' => $t_qty_array,
'PRODUCTS_Quantity_x' => $array['products_quantity'],
'GM_FORM_END' => '</form>',
'GM_PRODUCTS_QTY' => $gm_qty,
'GM_PRODUCTS_STOCK' => $gm_products_stock,
'PRODUCTS_META_DESCRIPTION' => $array['products_meta_description'],
'PRODUCTS_WEIGHT' => gm_prepare_number((double)$array['products_weight'], $xtPrice->currencies[$xtPrice->actualCurr]['decimal_point']),
'SHOW_PRODUCTS_WEIGHT' => $array['gm_show_weight']);
return $t_data_array;
// EOF GM_MOD
Inside the html the following code is given
<span class="label">{$module_data.PRODUCTS_Quantity_x}<span>
I hope you can help me out here
thanks in advance
You can do this 2 way:
1) First way:
You simple use in Smarty the following code with added string_format:
<span class="label">{$module_data.PRODUCTS_Quantity_x|string_format:"%d"}<span>
2) Second way:
You do whatever you need in PHP and assign desired value in PHP.
So in PHP you can change line:
'PRODUCTS_Quantity_x'=> $array['products_quantity'],
into
'PRODUCTS_Quantity_x'=> (int) $array['products_quantity'],
and then in Smarty you use the same code as you used earlier (without string_format):
<span class="label">{$module_data.PRODUCTS_Quantity_x}<span>
I have part of my PHP file below. I'm using PDO for communication with a database and I'm receiving the data from a HTML Form. Both try/catches are laid out in the same format, however only the first try/catch will INSERT the information correctly. The second try/catch is not inserting any information, and it's not catching any errors. Echos display just fine, but again no data in NAMES table.
If anyone can point out my mistake I'd greatly appreciate it.
$thenumdrivers = $_POST['reg_drivers_num'];
//Query for INSERT drivers into DRIVERS table
try{
echo "Number of drivers being registered: $thenumdrivers!<br>";
$STH=$DBH->prepare("INSERT INTO `Drivers` (`Account_id`, `Driver_license`, `Driver_name`, `Driver_birthdate`)
VALUES (:reg_accountid,:drivers_license,:drivers_firstname,:drivers_dob)");
for($i=1;$i<=$thenumdrivers;$i++){
$STH->execute(array(':reg_accountid'=>$theaccountid,':drivers_license'=>$_POST['drivers_license'.$i],':drivers_firstname'=>$_POST['drivers_firstname'.$i],':drivers_dob'=>$_POST['drivers_dob'.$i]));
echo "1 Driver added!<br>";
}
}
catch(PDOException $e){
$e->getMessage();
}
//Query to INSERT driver names into NAMES table
try{
echo "Number of drivers being added to Names: $thenumdrivers!<br>";
$STH=$DBH->prepare("INSERT INTO `Names` (`Account_id`, `Name_first`, `Name_middle`, `Name_last`) VALUES (:reg_accountid,:drivers_firstname,:drivers_middleinit,:drivers_lastname)");
for($k=1;$k<=$thenumdrivers;$k++){
$STH->execute(array(':reg_accountid'=>$theaccountid,':drivers_firstname'=>$_POST['drivers_firstname'.$k],':drivers_middleinit'=>$_POST['drivers_middleinit'.$k],':drivers_lastname'=>$_POST['drivers_lastname'.$k]));
echo "1 Name added!<br>";
}
}
catch(PDOException $e){
$e->getMessage();
}
print_r($_POST) output for just this section of data. I only tried to register 1 driver. So the blanks for the others are correct.
Array ( [reg_vehicles_num] => 1 [reg_make1] => make [reg_model1] => model [reg_year1] => 2014 [reg_vin1] => 3 [reg_make2] => [reg_model2] => [reg_year2] => [reg_vin2] => [reg_make3] => [reg_model3] => [reg_year3] => [reg_vin3] => [reg_make4] => [reg_model4] => [reg_year4] => [reg_vin4] => [reg_drivers_num] => 1 [drivers_lastname1] => Tester [drivers_middleinit1] => J [drivers_firstname1] => Fester [drivers_dob1] => 2014-04-01 [drivers_license1] => 0987654321 [drivers_lastname2] => [drivers_middleinit2] => [drivers_firstname2] => [drivers_dob2] => [drivers_license2] => [drivers_lastname3] => [drivers_middleinit3] => [drivers_firstname3] => [drivers_dob3] => [drivers_license3] => [drivers_lastname4] => [drivers_middleinit4] => [drivers_firstname4] => [drivers_dob4] => [drivers_license4] => )
Ok the only thing I can see is that in your sending $_POST['reg_drivers_num'] but tying to access $_POST['reg_number_drivers'], enable error_reporting(E_ALL).
You might also want to look into structuring your POST input values better and send an array of values, this way you can use a foreach to loop the values and not need the reg_number_drivers value.
I've found answers that are similar to the one I'm looking for, but not one that completely addresses my problem.
A user clicks a link on my page which takes them to Google Books and does a search. However, if the first word in the title of the book contains a contraction, everything gets thrown off and none of my corrections seem to work.
Example:
The link on my page looks like this:
mysite.com/book-search?bookauthor=Lance Armstrong&booktitle=It's Not About the Bike
However, when I run this:
$bookTitle = $_GET['booktitle']
I get the same title with the apostrophe in "It's" removed. And that's enough to completely throw off the Google Books Search and return no results.
The endpoint in the cURL session that does the search looks like this:
https://www.googleapis.com/books/v1/volumes?q=intitle:' . $bookTitle . '+inauthor:' . $bookAuthor;
Try it yourself -
https://www.googleapis.com/books/v1/volumes?q=intitle:It%27s+Not_About+The+Bike+inauthor:Lance+Armstrong
Returns a completely different result than
https://www.googleapis.com/books/v1/volumes?q=intitle:Its+Not_About+The+Bike+inauthor:Lance+Armstrong
You'd think that if I urlencoded the strings, that would solve the problem. But it doesn't. Still, for a reason that I can't fathom, when I do this:
$google_endpoint_a = 'https://www.googleapis.com/books/v1/volumes?q=intitle:' . urlencode($bookTitle) . '+inauthor:' . urlencode($bookAuthor);
...the urlencoding gets stripped out when it's passed to the GoogleAPI and I get a zero result search again.
Can somebody help me wade through this? I've tried everything I can think of.
OH - and here's the bonus - this ONLY happens if the first word in the string contains the apostrophe. So it happens with book titles like "It's Not About The Bike" and "Don't Blink". Apostrophes in other words don't seem to matter. (Like author Bill O'Reilly, for example.)
Is there an easy way to remove the first word from the string IF it contains an apostrophe? Or is there a better way?
The Really Ugly Solution:
So PHP passes $_GET variables through urldecode(). So even though it's ugly, here's what I ended up doing that solved the problem, even though I hope someone will come up with a better way.
Before I passed the variable through the URL, I replaced the apostrophe with a string of gibberish, like this:
$booktitle = str_replace("'", "W5x32RS97", $booktitle);
Then ran this:
$bookTitleTemp = $_GET('booktitle');
$bookTitle = str_replace("W5x32RS97", "'", $bookTitleTemp);
And suddenly, everything works. But there's GOT to be a better way.
Hadn't you try to subtitute the ' by \' in your title string? I mean, instead of:
It's Not About the Bike, using this: It\'s Not About the Bike
Without the apostrophe, you can drop intitle: and just use the following string:
$google_endpoint_a = 'https://www.googleapis.com/books/v1/volumes?q=' . urlencode($bookTitle) . '+inauthor:' . urlencode($bookAuthor);
https://www.googleapis.com/books/v1/volumes?q=Its+Not_About+The+Bike&inauthor:Lance+Armstrong
Update
To write a condition to use intitle if the first word has an apostrophe, you can do something like:
$pieces = explode(" ", $bookTitle);
if (strpos($pieces[0], "'") !== FALSE) {
$google_endpoint_a = 'https://www.googleapis.com/books/v1/volumes?q=' . urlencode($bookTitle) . '+inauthor:' . urlencode($bookAuthor);
}
else {
$google_endpoint_a = 'https://www.googleapis.com/books/v1/volumes?q=intitle:' . urlencode($bookTitle) . '+inauthor:' . urlencode($bookAuthor);
}
I would also see if encoding the variables earlier would work:
$bookTitle = urlencode($_GET[booktitle]);
in your link
use "It\'s"
not IT's
if you want to remove any apostrophe in the first word, then just test that the apostrophe has a lower string position than the first space. If it does, then remove it.
if(strpos($bookTitle,"'") < strpos($bookTitle," ")){
$bookTitle = preg_replace('/\'/', '', $bookTitle, 1);
}
Desperate diseases need desperate remedies.
$translation = array("aint" => "ain't", "arent" => "aren't", "cant" => "can't", "cantve" => "can't've", "cause" => "'cause", "couldve" => "could've", "couldnt" => "couldn't", "couldntve" => "couldn't've", "didnt" => "didn't", "doesnt" => "doesn't", "dont" => "don't", "hadnt" => "hadn't", "hadntve" => "hadn't've", "hasnt" => "hasn't", "havent" => "haven't", "hed" => "he'd", "hedve" => "he'd've", "hell" => "he'll", "hellve" => "he'll've", "hes" => "he's", "hows" => "how's", "Id" => "I'd", "Idve" => "I'd've", "Ill" => "I'll", "Illve" => "I'll've", "Im" => "I'm", "Ive" => "I've", "isnt" => "isn't", "itd" => "it'd", "itdve" => "it'd've", "itll" => "it'll", "itllve" => "it'll've", "its" => "it's", "lets" => "let's", "maam" => "ma'am", "mightve" => "might've", "mightnt" => "mightn't", "mightntve" => "mightn't've", "mustve" => "must've", "mustnt" => "mustn't", "mustntve" => "mustn't've", "oclock" => "o'clock", "oughtnt" => "oughtn't", "oughtntve" => "oughtn't've", "shant" => "shan't", "shantve" => "shan't've", "shed" => "she'd", "shedve" => "she'd've", "shell" => "she'll", "shellve" => "she'll've", "shes" => "she's", "shouldve" => "should've", "shouldnt" => "shouldn't", "shouldntve" => "shouldn't've", "sos" => "so's", "thats" => "that's", "thered" => "there'd", "theres" => "there's", "theyd" => "they'd", "theyll" => "they'll", "theyllve" => "they'll've", "theyre" => "they're", "theyve" => "they've", "wasnt" => "wasn't", "wed" => "we'd", "well" => "we'll", "wellve" => "we'll've", "were" => "we're", "weve" => "we've", "werent" => "weren't", "whatll" => "what'll", "whatllve" => "what'll've", "whatre" => "what're", "whats" => "what's", "whatve" => "what've", "whens" => "when's", "whenve" => "when've", "whered" => "where'd", "wheres" => "where's", "whereve" => "where've", "wholl" => "who'll", "whollve" => "who'll've", "whos" => "who's", "whove" => "who've", "whys" => "why's", "willve" => "will've", "wont" => "won't", "wontve" => "won't've", "wouldve" => "would've", "wouldnt" => "wouldn't", "wouldntve" => "wouldn't've", "yall" => "y'all", "yalldve" => "y'all'd've", "yallre" => "y'all're", "yallve" => "y'all've", "youd" => "you'd", "youdve" => "you'd've", "youll" => "you'll", "youllve" => "you'll've", "youre" => "you're", "youve" => "you've", );
$bookTitle = strtr($bookTitle, $translation);
I am trying to insert a email into the database. All other values except email gets posted. '0' is being inserted into the database instead of email id.
$wpdb->bloodregistration = $wpdb->prefix.'bloodregistration';
$wpdb->insert( $wpdb->bloodregistration,array( 'name' => $_POST['myname'], 'myemail' => $mailid,'age' => $_POST['age'],'gender' => $_POST['gender'],'location' => $_POST['location']
,'address' => $_POST['address'],'phone_land' => $_POST['ph_land'],'phone_mob' => $_POST['ph_mobile'],'blood_group' => $_POST['blood_group']
,'dob' => $dob,'lastblooddate' => $doblood),array('%s','%d') );
What DB do you use? My guess is that you forgot to assign sequence/serial/auto-increment to ID column.
EDIT:
So the problem was this part 'myemail' => $mailid you were inserting empty or not set variable into this field and therefore you got 0 in DB.
In DB set the column "myemail" to auto-increment, NOT NULL and INDEX PRIMARY.
Then in PHP simply skip this field when adding new records, DB will auto-increment it.
Try:
$wpdb->bloodregistration = $wpdb->prefix.'bloodregistration';
$wpdb->insert( $wpdb->bloodregistration,array( 'name' => $_POST['myname'],'age' => $_POST['age'],'gender' => $_POST['gender'],'location' => $_POST['location']
,'address' => $_POST['address'],'phone_land' => $_POST['ph_land'],'phone_mob' => $_POST['ph_mobile'],'blood_group' => $_POST['blood_group']
,'dob' => $dob,'lastblooddate' => $doblood),array('%s','%d') );