If a variable will always be a number, is there a performace loss by putting it in inverted commas?
for example
"SELECT prod.product_name FROM prod WHERE prod.id = '$id'";
Greetings cake experts, I have a question that I think would really help a lot of people getting started with cakePHP. I have a feeling it will be easy for some of you, but it is quite challenging to me.
I have a simple database with multiple tables. I can't figure out how to make cakePHP display the values associated with a foreign key in an index view. Or create a view where the fields of my choice (the ones that make sense to users like location name - not location_id can be updated or viewed on a single page).
I have created an example at http://lovecats.cakeapp.com that illustrate the question. If you look at the page and click the "list cats", you will notice that it shows the location_id field from the locations table. You will also notice that when you click "add cats", you must choose a location_id from the locations table. This is the automagic way that cakePHP builds the app. I want this to be the field location_name.
The database is setup so that the table cats has a foreign key called location_id that has a relationship to a table called locations.
This is my problem: I want these pages to display the location_name instead of the location_id. If you want to login to the application, you can go to http://cakeapp.com/sqldesigners/sql/lovecats and the password 'password' to look at the db relationships, etc.
How do I have a page that shows the fields that I want? And is it possible to create a page that updates fields from all of the tables at once?
This is the slice of cake that I have been trying to figure out and this would REALLY get me over a hump. You can download the app and sql from the above url.
I want to create a sort of datamapper library, where you'd do something like this:
$users = Users::getTable();
$users->add($newUser1);
$users->add($newUser2);
Now $users contains 2 user records, but they aren't yet persisted to the database. To be efficient, I'd like to flush them all at once. I would like to have a flush() method to do this (not an issue), but I'd also like for it to happen implicitly when the $users table reference falls out of scope. Is there any reason I shouldn't do this in the destructor?
I've seen so many misuses of RegExp, I don't really like it :)
I have string (as a result of two str_replaces) that might look something like this:
.?This iš my ".stRiNg."!
|
V
--this-is-my---string---
Is there any way better than
$string = trim(preg_replace('/[-]+/u','-', $string),'-');
to get:
this-is-my-string
?
I have a zip code lookup service and I'm worried about any possible timeouts or the server being down.
If I don't get any HTTP Response after 20-25s of the initial request I would want to respond with a JSON signifying it failed:
({ success:0 })
I have the following recursive function which works... up until a point. Then the script asks for more memory once the queries exceed about 100, and when I add more memory, the script typically just dies (I end up with a white screen on my browser).
public function returnPArray($parent=0,$depth=0,$orderBy = 'showOrder ASC'){
$query = mysql_query("SELECT *, UNIX_TIMESTAMP(lastDate) AS whenTime
FROM these_pages
WHERE parent = '".$parent."' AND deleted = 'N' ORDER BY ".$orderBy."");
$rows = mysql_num_rows($query);
while($row = mysql_fetch_assoc($query)){
// This uses my class and places the content in an array.
MyClass::$_navArray[] = array(
'id' => $row['id'],
'parent' => $row['parent']
);
MyClass::returnPArray($row['id'],($depth+1));
}
$i++;
}
Can anyone help me make this query less resource intensive?
I was just wondering whether it makes a difference if I mysql_real_escape data more than once?
So if I escaped data in one part of my website, and then again in another part of code. Would this be a problem? Or make a difference?
Given original codes as:
foreach($option as $name=>$value)
$array[$name] = $value;
and some $name as
button[0][text], button[0][value], button[1][text], spider[0][name], ...
How could i get results as
$array[button][0][text] = $value
...
$array[spider][0][name] = $value ?
...
I have a form on my website.
When this form is filled out, it is then validated by a javascript validation function.
At the bottom of this function I have this piece of code:
window.location="../index.html";
This wont work on Chrome, but does work in Firefox.
My Q is, how can I make this simple redirect work on all (most) browsers?
Thanks
I'm asked to create an online booking system with online payment and I'm wondering what to do in the case when 2 customers booked for the same room(s) at the same time.
For Example:
At the same time:
Customer1 and Customer2 booked for a standard room which only has 1 room available. (The Room availability will display that there is still 1 room available). And then they hit the 'confirm' button at the same time.
I'm going to create a web site which should manage users accounts.
A user opens an account and gets relevant data for his needs.
What technology should I be using to create this site?
Are there any templates I could use?
I don't have the time to take care of the web site's desgin,
Are there any places where I can buy some graphics?
Thanks
Hello,
This is my first app with CI and I want to know whether $_POST is clean and can I directly insert the data into db?
I have enabled $config['global_xss_filtering'] = TRUE;
Thank You.
I'm using this code but I can't figure out how to get the email from the user. I know you must get special permission from the user but I don't know how.
I can get the public data from the user but that's not what I even need. The only thing I need is the email.
I guess it's something with this line:
$me = $facebook->api('/me');
I have read the documentation but I still don't know how I can get the email. How do I get the email from the user loggin in on my website with the facebook api?
I've lost link to free file browser which can be integrated with ckeditor. I'm looking for it for about 5 hours and no luck, so could you help ? Problem is that I remeber nothing except page had red circle favicon with white text, name was with "net" and "4" . I'll be thankful for help
Hello, how I can use array acces with my static class?
F.e. I like to execute next script:
class A {
...
}
A['p'] = 15;
echo isset(A['p']) ? A['p'] : 0;
Got this function for ammending the query string and was wondering what the replacement part of the pre_replace meant (ie- $1$2$4).
function add_querystring_var($url, $key, $value) {
$url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
if (strpos($url, '?') === false) {
return ($url . '?' . $key . '=' . $value);
} else {
return ($url . '&' . $key . '=' . $value);
}
}
Not too familiar with regular expression stuff. I get the various parts to preg_replace but not 100% about the use of '$1$2$4' in the replacement part.
Hi. I have used the tinymce editor in my form. And I have used an validation for checking whether the editor is empty or not. It works for the initial stage. Also, when I press enter and checks for validation the form got submits. When I checked the source code of the editor it contains the information as below:
<p>&nbsb;</p>
Please check it and help me to get me an answer for this.
I downloaded tripit_php_v1_25392 zip file i try to run the file in my local xamp it asks for api_url, consumer_key, consumer_secret, access_token ,access_token_secret keys how do i get those values and run the file
Hi
I have code where I connected to the database like so:
$db = new mysqli("localhost", "user", "pass", "company");
Now when I query the database like so:
//query calls to a stored procedure 'user_info'
$result = $db->query("CALL user_info('$instruc', 'c_register', '$eml', '$pass', '')");
//I use the $result
This query works well. Now when I try and free that result like so:
$result->free();
or
$result->close();
It seems like it doesn't do anything because $result is still set. When I try to run another query it gives me this error:
Fatal error: Call to a member function fetch_array() on a non-object in...
For me to run this other query I have to close the db conection and connect again, then it will work. I want to know if there is a way I could run the other query without having to disconnect and reconnect to the database.
thanks in advance.
I'm performing a query on a worksheet. I want to update the row if it exists or insert it if it doesn't. How can you check if a result was returned or not?
$query = new Zend_Gdata_Spreadsheets_ListQuery();
$query->setSpreadsheetKey($this->currKey);
$query->setWorksheetId($this->currWkshtId);
$query->setSpreadsheetQuery('cid = ' . $data['cid']);
$listFeed = $this->gdClient->getListFeed($query);
// This does not work!
if(empty($listFeed)){
echo 'No results found!';
}
Trying to set up a script to send commands to a remote client on a Win32 system. Here is the code:
$command = $_POST['command'];
$host = $_POST['host'];
$port = $_POST['port'];
$fp = @fsockopen($host, $port, $e, $s, 15);
if (!$fp) {
echo 'Error! Here\'s your problem: ' . $e . ': ' . $s;
}else{
$fw = fwrite($fp, $command);
if (!$fw){
echo 'Failed sending command.';
fclose($fp);
}else{
fclose($fp);
echo 'Successfully sent: ' . $command;
}
}
My buddy is working on the remote client, and he says that this script is sending ''
However, my script is echoing Successfully sent: test
Am I doing something wrong, or is it a problem on his end?
I have an array:
myarr = [];
I'm filling it with some values:
myarray['name'] = "Me!";
Now I want to transform that array into a set of Key = Value pairs. I though jQuery would do it automatically, but it doesn't seem to.
$.ajax
({
type: "POST",
dataType: "text",
url: "myurl",
data: myarr
});
Is there a way to do this or something I'm doing wrong? I get no javascript errors, and no serverside errors other then no POST information at all.