I am aware of array_walk() and array_map(). However when using the former like so (on an old project) it failed
array_walk($_POST, 'mysql_real_escape_string');
Warning: mysql_real_escape_string()
expects parameter 2 to be resource,
string given.
So I went with this slightly more ugly version
foreach($_POST as $key => $value) {
$_POST[$key] = mysql_real_escape_string($value);
}
So why didn't the first way work? What is the best way to map values of an array to a function?
Hi all,
I am using WordPress Version 2.9.2 for my blog.when i am trying to include a database connection in one of my plug-in which is not working properly.Which did not get the database connection.But in all other directory it is possible to use a common connection.So,now I am using manual coding in all of my plug-in file.Any ways to getting a common connection in all of my plug-in.Help me please...
I've seen a lot this kind of code recently :
if ($foo = $bar->getFoo())
{
baz($foo);
}
Is this considered good or bad practice ?
For example, Netbeans IDE give a notice if you use this kind of code :
Possible accidental assignment,
assignments in conditions should be
avoided
What do you think ?
Hi
In my mode I am selecting a field as
$query1 = $this->db->query("SELECT dPassword
FROM tbl_login
WHERE dEmailID='[email protected]'");
How to return dpassword as a variable to my controller
I tried this way return dpassword;
I am about to upload my site to the Server, and I have ubuntu 9.1 as OS.
Now, I have installed LAMP, and need to somehow password protect my website.
How can I do this so only I have access to my website while developing it?
Please be thorough... Thanks
I am preparing a chart which will display the number of orders placed for a particular day in the current month and year. I wanted the count of orders placed for each day.
I am showing the count of orders on the y-axis and the day on the x-axis.
In my database, there is table called "order" in which order data is placed: order date, user_id, order_price, etc. For example, if on 4 July, 10 orders are placed, on 5 july, 20 orders are placed, and so on.
How can I get the count of orders placed for day of the current month?
I have a piece of code that generates soccer/football fixtures.
The idea is that for every round of fixtures, the date will be 4 days further than the last round.
So round one will be 3rd may, round two will be 7th may, round three 11th may, etc.
I am not sure how to do this?
The code that currently makes the fixtures are as follows:
$totalRounds = $teams - 1;
$matchesPerRound = $teams / 2;
$rounds = array();
for ($i = 0; $i < $totalRounds; $i++) {
$rounds[$i] = array();
}
for ($round = 0; $round < $totalRounds; $round++) {
for ($match = 0; $match < $matchesPerRound; $match++) {
$home = ($round + $match) % ($teams - 1);
$away = ($teams - 1 - $match + $round) % ($teams - 1);
// Last team stays in the same place while the others
// rotate around it.
if ($match == 0) {
$away = $teams - 1;
}
$rounds[$round][$match] = "$user[$home]~$team[$home]@$user[$away]~$team[$away]";
}
}
The teams would be the total users in the league.
So if there are 8 teams, there will be 7 rounds.
And i will want each round 4 days apart.
And that date will be within each fixture within each round.
Any further information needed just ask!
Thanks, really stuck on this
Does Doctrine 1.2 support importing indexes with Doctrine_Core::generateModelsFromDb() function?
I need to make a migration between 2 database connections, one of them having unique index on 2 fields and one doesn't. And my migration is empty. It looks like Doctrine doesn't support indexes when importing from databae, other than those tied to relationship foreign keys.
$changes = Doctrine_Core::generateMigrationsFromDiff($migrationsPath,
array('doctrineOld'),
array('doctrine'));
Im working on a script to tear into a csv file and ive got the rows separated, but im not sure how to assign variables to the fields within the row, so that i can perform functions with them.
my code:
<?
ini_set('auto_detect_line_endings', true);
$csvraw = file_get_contents("file.csv");
$csv = explode("\n", $csvraw);
$i=0;
foreach($csv AS $key=>$value){
$rowsplit = explode(",", $value);
// This is where i get my headers
if($i == 0){
$col0 = $rowsplit[0];
$col1 = $rowsplit[1];
$col2 = $rowsplit[2];
$col3 = $rowsplit[3];
$col4 = $rowsplit[4];
$col5 = $rowsplit[5];
$col6 = $rowsplit[6];
$col7 = $rowsplit[7];
}
$i++;
//This is where i loop through each row's fields
foreach($rowsplit AS $key2=>$value2){
if(empty($value2)){
echo "";
}else{
echo "$value2 <br>";
}
// This is where i need to assign $variable0 through $variable7 so i can perform a function with the field values.
}
echo "<br><br><br>";
}
?>
I am a Yii beginner and am running into a bit of a wall and hope someone will be able to help me get back onto track. I think this might be a fairly straight forward question to the seasoned Yii user. So here goes...
In the controller, let's say I run the following call to the model-
$variable = Post::model()->findAll();
All works fine and I pass the variable into the view. Here's where I get pretty stuck. The array that is returned in the above query is far more complex than I anticipated and I'm struggling to make sense of it. Here's a sample-
print_r($variable);
gives-
Array ( [0] => Post Object ( [_md:CActiveRecord:private] => CActiveRecordMetaData Object ( [tableSchema] => CMysqlTableSchema Object ( [schemaName] => [name] => tbl_post [rawName] => `tbl_post` [primaryKey] => id [sequenceName] => [foreignKeys] => Array ( ) [columns] => Array ( [id] => CMysqlColumnSchema Object ( [name] => id [rawName] => `id` [allowNull] => [dbType] => int(11) [type] => integer [defaultValue] => [size] => 11 [precision] => 11 [scale] => [isPrimaryKey] => 1 [isForeignKey] => [autoIncrement] => 1 [_e:CComponent:private] => [_m:CComponent:private] => ) [post] => CMysqlColumnSchema Object ( [name] => post [rawName] => `post` [allowNull] => [dbType] => text [type] => string [defaultValue] => [size] => [precision] => [scale] => [isPrimaryKey] => [isForeignKey] => [autoIncrement] => [_e:CComponent:private] => [_m:CComponent:private] => ) ) [_e:CComponent:private] => [_m:CComponent:private] => ) [columns] => Array ( [id] => CMysqlColumnSchema Object ( [name] => id [rawName] => `id` [allowNull] => [dbType] => int(11) [type] => integer [defaultValue] => [size] => 11 [precision] => 11 [scale] => [isPrimaryKey] => 1 [isForeignKey] => [autoIncrement] => 1 [_e:CComponent:private] => [_m:CComponent:private] => ) [post] => CMysqlColumnSchema Object ( [name] => post [rawName] => `post` [allowNull] => [dbType] => text [type] => string [defaultValue] => [size] => [precision] => [scale] => [isPrimaryKey] => [isForeignKey] => [autoIncrement] => [_e:CComponent:private] => [_m:CComponent:private] => ) ) [relations] => Array ( [responses] => CHasManyRelation Object ( [limit] => -1 [offset] => -1 [index] => [through] => [joinType] => LEFT OUTER JOIN [on] => [alias] => [with] => Array ( ) [together] => [scopes] => [name] => responses [className] => Response [foreignKey] => post_id [select] => * [condition] => [params] => Array ( ) [group] => [join] => [having] => [order] => [_e:CComponent:private] => [_m:CComponent:private] => ) ) [attributeDefaults] => Array ( ) [_model:CActiveRecordMetaData:private] => Post Object ( [_md:CActiveRecord:private] => CActiveRecordMetaData Object *RECURSION* [_new:CActiveRecord:private] => [_attributes:CActiveRecord:private] => Array ( ) [_related:CActiveRecord:private] => Array ( ) [_c:CActiveRecord:private] => [_pk:CActiveRecord:private] => [_alias:CActiveRecord:private] => t [_errors:CModel:private] => Array ( ) [_validators:CModel:private] => [_scenario:CModel:private] => [_e:CComponent:private] => [_m:CComponent:private] => ) ) [_new:CActiveRecord:private] => [_attributes:CActiveRecord:private] => Array ( [id] => 1 [post] => User Post ) [_related:CActiveRecord:private] => Array ( ) [_c:CActiveRecord:private] => [_pk:CActiveRecord:private] => 1 [_alias:CActiveRecord:private] => t [_errors:CModel:private] => Array ( ) [_validators:CModel:private] => [_scenario:CModel:private] => update [_e:CComponent:private] => [_m:CComponent:private] => ) )
[sorry if there's an easier way to show this array, I'm not aware of it]
Can anyone explain to me why the model returns such a complex array? It doesn't seem to matter what tables or columns or relations are used in your application, they all seem to me to return this format.
Also, can someone explain the structure to me so that I can isolate the variables that I want to recover?
Many thanks in advance,
Nick
I run a small, niche personal ads site. People post ads and then other people reply to them, which sends an email to the original creator of the ad telling them that someone is interested and giving them contact information for that interested person.
Lately there's been some weird spam. People are receiving nonsense replies to their ads. Here is an example of one:
Name: xkauwvyr
Reply: vRYmbI <a href="http://rypmoxdkfblf.com/">rypmoxdkfblf</a>, url=http://pnjlwvhizwbq.com/]pnjlwvhizwbq[/url], [link=http://hmenwoujxrfv.com/]hmenwoujxrfv[/link], http://ogsekuhoyeud.com/
They vary in length and composition but they all look roughly like that. The first idea I had was to simply throw out any reply that contained the string "
Also, is this spam just some ass playing a trick on my website, or is it something more malicious?
We make use of views and panels quite often in Drupal and a lot of people are utilizing CTools in development. I can't find a lot of documentation on what it is and why you'd use it and the drupal.org forum isn't providing much either.
What is CTools, and is it worth using? What is the best use-case for utilizing it?
often i want to email some code without attaching a file, are there any gmail/google wave/gdocs plugins for code sharing?
gmail would obviously be most useful!
Hey guys quick question, I thought I was doing the right thing but I keep getting the wrong result. I am trying to simply find the id of the entry with the min time, but I am not getting that entry.
$qryuserscount1="SELECT id,min(entry_time) FROM scrusersonline WHERE topic_id='$topic_id'";
$userscount1=mysql_query($qryuserscount1);
while ($row2 = mysql_fetch_assoc($userscount1)) {
echo $onlineuser= $row2['id'];
}
That is my query, and it does not work. This however does work which does not make sense to me
SELECT id FROM scrusersonline WHERE topic_id='$topic_id' ORDER by entry_time LIMIT 1, can anyone quickly point out what I am doing wrong?
I have the following array that I get as an output from facebook:
http://www.paste.to/v/1jntlnml
With the following code:
$stream = $facebook->api_client->stream_get('',128342905144,'0','0',30,'','','','');
foreach($stream as $wallpost) {
echo '<pre>';
print_r($wallpost);
echo '</pre>';
}
So I get the data that I need, but I want to call the individual variables within this array. For example, echo out the [message] for each post.
Since it only loops once, I cant echo $wallpost['message'] or anything similar.
any idea?
I am looking to execute this statement via Zend Framework. As I understand it, I can use Zend_Db_Select. Is it possible to use Zend_Db_Table?
Three tables: classes, students, and class_students
select classes.name, students.student_id, students.fname, students.lname from students, classes, class_students where class_students.student_id=students.student_id AND class_students.class_id=classes.class_id;
how do i have to nest multicheckboxes so that they are named like this 'foo[]['bar']' .
i've used subforms but they give me naming like this 'foo[bar][]'.
my code:
$sub = new Zend_Form_SubForm('sub');
$wish = new Zend_Form_Element_MultiCheckbox('bar');
$wish
->setMultiOptions($education_direction->getAll())
->setLabel('Wish')
->setRequired(true);
$sub-addElements(array(
$wish
));
$this-addSubForm($sub, 'foo');
I am working on a simple gaming ladder script. I am having little to no luck trying to find an effective way to reset my ladder information while leaving my table id and name fields intact.
I am trying to get create a loop to update my entire table, similar to the way I draw my table. Shown below.
......
//Start displaying ladder with with team with most wins at the top
echo "<TABLE border=1 width=500 align=center><TR>";
foreach($db->query('SELECT * FROM test ORDER BY win DESC , name ASC') as $row) {
echo "<TR><TD>" . $row['name'] . "</TD><TD>" . $row['win'] . "</TD><TD>";
echo $row['loss'] . "</TD><TD>" . $row['battles'] . "</TD><TD>";
echo $row['score'] . "</TD></TR>";
}
......
I currently have a table with 6 fields(id,name,win,loss,battles,score). I want to reset the values of win,loss,battles, and score back to 0. While leaving id and name alone. Effective reseting my ladder for a new season to begin.
The only way I have been able to complete this is to find out how many rows there are and run a for loop. It seems vary inefficient. Was hoping I could get some better insight as to how to go about this.
Hello,
What's your favourite programming page you often land at? For example, mine is:
http://code.google.com
Because it provides wealth of resources and tools.
Hello guys,
What I have in mind is this... We are going to have people come from a particular site during a acquisition campaign and was wondering how I could conditionalize a certain section of my site to display a thank you message instead of the sign up form as they would have had the opportunity to fill this out before coming to my landing page.
I have seen solutions like: $referal = mysql_real_escape_string($_SERVER['HTTP_REFERER']);
I would like to know if this is the best way to get this to work???
- okay this is what i think might work. The third party website that is referring people to our landing page once the form on that site has been filled out can push into the record a hidden input value of "www.sample.com" or whatever... then I can have something check the for that particular value and fire off the conidtional.
Does that even sound right?
Very quick question about programming practices here:
I've always used echo() to output HTML code to the user as soon as it was generated, and used ob_start() at the same time to be able to output headers later in the code. Recently, I was made aware that this is bad programming practice and I should be saving HTML output until the end.
Is there a reason for this? What is it, and why isn't output buffering a good alternative?
Thanks!