The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 19, 2019, 06:05:34 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: PHP String to Integer - Bastaard!  (Read 2951 times)
majiren
n00b
*
Offline Offline

Posts: 3


View Profile
« on: November 19, 2008, 01:07:25 PM »

OK, I am hoping someone can help as I have been at this all day!

I am passing a string from JS to my php function.

I know it is a string from gettype($string)

Echo'ing it out gives me "123"

but is_numeric($string) = no

WTF?!? I want this as an integer so I can use it.... shouldn't be that hard but it is!

Any direction would be appreciated!
Logged

No links in signatures please
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #1 on: November 19, 2008, 02:28:20 PM »

multiply it by 1 and then check the type.
Logged

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: November 19, 2008, 03:45:30 PM »

JS is a bitch that way. If you do a switch statement, you need to put both '1' and 1 as cases or you wont branch how you expect to if you're not sure about how the value was created.

If I always always want it to be a number, I subtract zero from it. var val = document.getElementById('theID').value - 0; and such. PIA, but the best you can do.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
majiren
n00b
*
Offline Offline

Posts: 3


View Profile
« Reply #3 on: November 20, 2008, 07:43:48 AM »

Seems I cannot do what I was wanting?!

jquery;

Code:
var thisvariable = parseInt($(".target").val());
$("#status p").html(' <?php $this->sites_model->get_test("'+thisvariable+'"?>' );

pass php my JS variable... impossible  Jackoff
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #4 on: November 20, 2008, 08:53:02 AM »

wow man - it's not often that a bit of syntax stops me cold... I don't understand that at all. That second line is JS? Please outline what exactly that is because I can't find anything about that form of code.

But aside from that, if what you want to do is throw variables up at a PHP script, then there are a variety of ways to do it. Straight up AJAX is easiest - I use a sort of "fire-and-forget" type ajax notation to do that very thing. A faster mechanism would be to create a new Image object, and make the source "/myScript.php?varval=123" - this would instantly cause a pop to the server, your script could grab the value on the $_GET array and then simply return a 1x1px graphic so that the browser doesn't complain.

But looking at your code I'm just not sure. Please outline a bit more of what you're trying to do and that syntax so we can help.

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #5 on: November 20, 2008, 02:03:37 PM »

sorry wait it's jquery

duh. I thought it was Prototype.

Perks does not use jquery. He likes to reinvent the wheel except when it comes to things he should care about like tyrannical corporations controlling his computer via his operating system. *jab jab*

 ROFLMAO

All kidding aside I've benefitted greatly from many of Perk's "reinventions" of the wheel so I can't be too hard on him.
« Last Edit: November 20, 2008, 02:05:27 PM by vsloathe » Logged

hai
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!