@cereal
Thank you.
I have the following code in application.ini
resources.db.adapter=PDO_MYSQL
resources.db.params.host=localhost
resources.db.params.username=myusername
resources.db.params.password=mypassword
resources.db.params.dbname=mydb
resources.db.params.charset = "utf8"
resources.db.params.driver_options.1002 = "SET NAMES utf8"
I cheked on the internet and could not find out an answer, may you could help.
Why the last row
resources.db.params.driver_options.1002 = "SET NAMES utf8"
is used, if the charset has already been set in the previous line:
resources.db.params.charset = "utf8"
?
I am new in Wordpress. I have installed a plugin "Infinite Scroll". When I scroll down the page to load new articles into the page, a message appear "Loading...". I have tried to translate the message in admin panel, but that was not a translation, just a replacement of the string "Loading...". Is it possible to translate this? Please advise.
I am not sure if it is recomended using this, but it is working only if adding 'document.' before 'write':
function lw(bat,bat2,bat3){
this.bat = bat;
this.bat2 = bat2;
this.bat3 = bat3;
}
var what = new lw("one","two","three");
for (var apple in what){
document.write(what[apple]+"<br/>");
}
PHP is executed on the server.
Javascript is executed on the client side (in the browser).
If you want to create real dynamic pages, I think you should learn Javascript as well. Also jQuery (Javascript library) and AJAX.
Check jqGrid if it is what you need.
http://www.trirand.com/jqgridwiki/doku.php
http://trirand.com/blog/jqgrid/jqgrid.html
http://www.trirand.com/blog/?page_id=5
This works for me:
$connection = mysql_connect ("localhost",$database_username,$database_password);
mysql_select_db ($database_name,$connection);
$result = mysql_query ("SELECT * FROM table",$connection);
while($row = mysql_fetch_array($result)){
echo $row['column_name'];
}
Does it help?
Instead:
$statement = $db->query($query);
Write:
$statement = $db->query($sql);
It worked for me this way:
var lw = function(){};
lw.prototype = {
getData : function(bat,bat2,bat3){
var params = {};
params[bat] = bat;
params[bat2] = bat2;
params[bat3] = bat3;
return params;
}
}
var what = new lw();
var result = what.getData("one","two","three");
for (var apple in result) {
document.write(result[apple]+"<br/>");
}
You're welcome!
Try instead:
$something = mysql_fetch_array($count);
while ($something = mysql_fetch_array($count)){
write:
while ($something = mysql_fetch_array($result)){
Does it help you?
<select name="table-type" id="select-t">
<option value="" disabled selected>Types of Tables</option>
<option value="seat-r">Round Table</option>
<option value="seat-b">Banquet Table</option>
<option value="seat-s">Square Table</option>
</select><br>
No. of seats : <br>
<input type="text" readonly placeholder="Select Table" size="8" id="inform" />
<select name="seatno" class="seat" id="seat-r" style="display: none;">
<option value="" selected disabled>No. of seats</option>
<option value="6">6</option>
<option value="8">8</option>
<option value="10">10</option>
<option value="12">12</option>
</select>
<select name="seatno" class="seat" id="seat-b" style="display: none;">
<option value="" disabled selected>No. of seats</option>
<option value="6">6</option>
<option value="8"></option>
<option value="10"></option>
</select>
<select name="seatno" class="seat" id="seat-s" style="display: none;">
<option value="" disabled selected></option>
<option value="6">6</option>
<option value="8">8</option>
</select>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#select-t').unbind().bind('change',function(){
var elemId = $(this).val();
showElement(elemId);
$("#inform").hide();
});
function showElement(id){
$('.seat').each(function(){
if($(this).attr('id') == id){
$(this).show();
} else {
$(this).hide();
}
});
}
});
</script>
Does it help you?
<div id="parent">
<div id="id1">1</div>
<div id="id2">2</div>
<div id="id3">3</div>
<div id="id4">4</div>
<div id="id5">5</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var divsTotal = $('#parent div').length-1;
var divId = $('#parent div:nth-child(' + divsTotal + ')').attr('id');
alert(divId);
});
</script>
Hi. I have an input type "number" set to display decimals. For example if I type "5" there should appear "5.0000". It works in Chrome and previous versions of Firefox. Now with Firefox 29 it does not work anymore. Does somebody know what could be the problem?
$('#mynumber').bind('focusout', function(){
if(!isNaN(parseFloat($(this).val()))){
$(this).val(parseFloat($(this).val()).toFixed(4));
}
});
Thank you for help. I finally managed to do it. Here is an example:
<input type="text" id="country" />
<script type="text/javascript">
$(document).ready(function(){
// Creating an array with country names and load them into local storage
var countries = new Array();
countries = ['Afghanistan','Albania','Algeria','Andorra','Angola','Antigua and Barbuda','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan'];
localStorage.setItem('countries',JSON.stringify(countries));
// Adding autocmplete functionality to a textfield with data from local storage
$('#country').autocomplete({source:JSON.parse(localStorage.getItem('countries')), minLength:1, delay:0});
});
</script>
Finally I've got the solution.
->where("FIND_IN_SET($id, TRIM(TRAILING ']' FROM (TRIM(LEADING '[' FROM `id`))))");
Thank you all for reply.
I think it is not possible to use LIKE here because there may be found situation of [12,32] will return true when searching for 2.
I have tried FIND_IN_SET(). The problem is that it is working without '[]', but I need these square brackets.
Hi. I have a mysql field with a record like: [2,5,11].
I have a query like:
$query = $this->select()
->from($this->_name)
->where('id = ?', $id);
This query work if record is of integer type: 5.
Is it possible to create a query to find 5 in the array? Please advise. Thanks.
Hello. I have a function that checks the internet connection. I need to set a timeout to it. I have tried without success to do that. Please help. Here is the function:
function isOnline() {
if(navigator.onLine){
var uri = baseUrl+'ping';
var xhr = new XMLHttpRequest();
xhr.open('GET',uri,false);
try{
xhr.send();
return true;
}catch(err){
return false;
}
}else{
return false;
}
}
Hello!
Is it possible to add autocomplete feature to input field with data loaded from local storage?
<input type="text" id="medicine" />
<script type="text/javascript">
$(document).ready(function($){
var medicine = localStorage.getItem('medicine');
console.log(medicine);
$('#medicine').autocomplete({source:medicine, minLength:2});
});
</script>
I know thta 'source' requires an url, I succeded to make autocomplete with data from mysql. But this takes longer time, and I thought to load data once in local storage, then use them for autocomplete.
Thank you for reply. The result is still NULL and I do not get the error message, even if I have removed '@'. It's strange.
Hello everyone,
I am trying to retrieve some info from a remote site using PHP DOMDocument and I cannot figure out why the code returns NULL, although the provided ID exists on the page. Please help.
$dom = new DOMDocument("1.0", "utf-8");
@$dom->loadHTMLFile('http://sports.yahoo.com/news/messis-tax-hearing-put-back-122033643--sow.html');
$content = $dom->getElementById('yog-content');
var_dump($content);
I've got it.
protected $_name = 'results';
public function getResults($resource_id_team1, $resource_id_team2)
{
$query = $this->select()
->setIntegrityCheck(false)
->from(array('rt' => $this->_name))
->joinLeft(array('rs1'=>'resource'),
'rt.resource_id_team1 = rs1.resource_id',
array('rs1.resource_id_team1' => 'rs1.resource_id', 'rs1.resource_name_team1' => 'rs1.resource_name'))
->joinLeft(array('rs2'=>'resource'),
'rt.resource_id_team2 = rs2.resource_id',
array('rs2.resource_id_team2' => 'rs2.resource_id', 'rs2.resource_name_team2' => 'rs2.resource_name'))
->where('resource_id_team1 = ?', $resource_id_team1)
->where('resource_id_team2 = ?', $resource_id_team2)
->where('match_result is NOT NULL');
return $this->fetchAll($query)->toArray();
}
Hi.
I am using Zend Framework Models. I have 2 tables: 'results' and 'resources'.
Table 'results' has the columns:
'results_id',
'resource_id_team1',
'resource_id_team2',
'match_result'.
Table 'resources' has the columns:
'resource_id',
'resource_name'.
I want to retrieve the results from the table 'results' and I want to join 2 times
the table 'resources', so that to have the names of the teams in the array and to obtain something like:
'results_id' => 1,
'resource_id_team1' => 1,
'resource_id_team2' => 2,
'match_result' => '2:1',
'resource_id' => '1',
'resource_name' => 'barcelona',
'resource_id' => 2,
'resource_name' => 'real_madrid'.
I have tried to get the data with joinLeft, but the problem is the same 'resource_id' and I couldn't succeed.
protected $_name = 'results';
public function getResults($resource_id_team1, $resource_id_team2)
{
$query = $this->select()
->setIntegrityCheck(false)
->from(array('rt' => $this->_name),'rt.results_id')
->joinLeft(array(
'rs'=>'resource'),
'rt.resource_id_team1 = rs.resource_id')
->joinLeft(array(
'rs'=>'resource'),
'rt.resource_id_team2 = rs.resource_id')
->where('resource_id_team1 = ?', $resource_id_team1)
->where('resource_id_team2 = ?', $resource_id_team2)
->where('match_result is NOT NULL');
return $this->fetchAll($query)->toArray();
}
Is there a solution, please help.
@cereal
Thank you!
Hello.
I need to create an array dynamically from a string value. Please advise how is it possible to retrieve the array values by keys.
$mystring = 'myarray';
$myarray = ['a','b','c'];
echo '<pre>';
print_r($$mystring); // it works properly
echo '</pre>';
echo $$mystring[0]; // returns error
Hello.
I have a form with captcha element. The text field displays on the right of the image. How can I make it displaying below the image?
$path = Zend_Controller_Front::getInstance()->getBaseUrl();
$captcha = new Zend_Form_Element_Captcha(
'captcha',
array(
'label' => 'Type the characters you see in the image below:',
'attribs' => array('id' => 'captcha', 'class' => 'required'),
'required' => true,
'captcha' => array(
'captcha' => 'Image',
'wordLen' => 6,
'timeout' => 300,
'font' => APPLICATION_PATH . '/../public/css/LeagueGothic/League_Gothic-webfont.ttf',
'imgDir' => APPLICATION_PATH . '/../public/images/captcha/',
'imgUrl' => $path . '/images/captcha',
'dotNoiseLevel' => 5,
'lineNoiseLevel' => 2,
'width' => 220)
));
I used its id in css file:
#captcha {display: block;}
but the validation error message that needs to appear on the right, now displays below the textfield.
Please advise a solution. Thank you.
After many hours of googling, I have found a solution that works on: http://www.hardcode.nl/archives_132/article_564-get-baseurl-inside-a-zend-form-descendant-class.htm and implemented it as follows:
class Application_Form_Login extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('login');
$this->setMethod('post');
$view = Zend_Layout::getMvcInstance()->getView();
$this->setAction($view->baseUrl() . '/auth/index');
...
The problem is that action does not go to the right page. For example I am in the page
->http://localhost/mysite/public/mycontroller/myaction
and the form should post to
->http://localhost/mysite/public/auth/index
but after I submit the form, the link transforms into
->http://localhost/mysite/public/mycontroller/auth/index
Please advise how to fix this problem.
In my code it is exactly the same and that's why I post here, maybe there is other thing to do when calling the form from a view helper...
I have a login form 'Application_Form_Login' that I call in 'Application_View_Helper_Auth', so that the signin form appears on all pages. If I login from 'index/index', everything is ok, but it doesn't work correctly if I login from 'index/otheraction' or 'othercontroller/index'. The form code starts as follows:
class Application_Form_Login extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('login');
$this->setMethod('post');
$this->setAction("/auth/index");
...
Please help, where should I change something to make it work?
What I was looking for is this:
$email = new Zend_Form_Element_Text('email');
$email->setLabel($sessionSettings->tr->translate('email'))
->setValue('')
->setAttribs(array('id' => 'email', 'class' => 'required email'))
->setRequired(true)
->addFilters(array('StripTags','StringTrim','StringToLower'))
->addValidators(array(
array('NotEmpty',true, array('messages' => array('isEmpty' => 'Email address field cannot be empty.'))),
array('EmailAddress',true, array('messages' => array('emailAddressInvalidFormat' => 'Email address name not corresponding.'))),
array('Db_NoRecordExists', true, array('table' => 'user', 'field' => 'email_address', 'messages' => array('recordFound' => 'Email address is taken.')))
));
@pritaeas
Thank you for fast reply. I am using version 1.X. I have tried the method setMessages and didn't work. Then I tried other method setErrorMessages and it worked.
->addValidators(array(
'NotEmpty',
'EmailAddress',
array('Db_NoRecordExists', true, array('user', 'email_address'))
))->setErrorMessages(array('Email address is taken.'));
Hello!
I have a signup form that is working fine. Here it is a text element for providing the email address:
$email = new Zend_Form_Element_Text('email');
$email->setLabel($sessionSettings->tr->translate('email'))
->setValue('')
->setAttribs(array('id' => 'email', 'class' => 'required email'))
->setRequired(true)
->addFilters(array('StripTags','StringTrim','StringToLower'))
->addValidators(array(
'NotEmpty',
'EmailAddress',
array('Db_NoRecordExists', true, array('user', 'email_address'))
));
$email->getValidator('NotEmpty')->setMessage('Email address field cannot be empty.');
$email->getValidator('EmailAddress')->setMessage('Email address name not corresponding.');
$email->getValidator('Db_NoRecordExists')->setMessage('Email address is taken.');
I wonder if it is possible to add the error messages to 'addValidators' array and removing in this way the last 3 lines. Please advise.
Hi, all.
I have a login form with a checkbox that needs to create cookies if checked. How is it possible to check after the form has been submitted if the checkbox has been checked?
I have the following code in 'application/forms/Login.php':
$remember = new Zend_Form_Element_Checkbox("remember", array('disableLoadDefaultDecorators' => true, 'required' => false));
$remember->setDecorators(array('ViewHelper', array('Description', array('escape' => false, 'tag' => 'span'))))->setDescription("Remember me");
And in 'application/controllers/Auth.php':
$form = new Application_Form_Login();
$request = $this->getRequest();
if($request->isPost() && $request->getPost('submit_login')) {
if($form->isValid($request->getPost())) {
if ($this->_process($form->getValues())) {
$data = $form->getValues();
if(isset($data['remember'])){
setcookie("username", $data['username'], time()+60*60*24*100, "/");
setcookie("password", $data['password'], time()+60*60*24*100, "/");
}
}
}
}
The code works fine, but it creates cookis, no matter if checked or unchecked. Please advise. Thank you.
$fruit = 'apple';
$$fruit = 'red';
echo $fruit . ' is ' . $apple; // returns 'apple is red'
Hi!
I have a form in Drupal that is filled up by an user and sent as email to the server. I have created a new module to modify the values in the form after the user submit it and to send them to the server with new values.
Here is my code:
function medilux_cm_form_alter (&$form, $form_state, $form_id) {
if ($form_id == "webform_client_form_59") {
$form['#submit'][] = 'medilux_custom_webform_submit';
}
}
function medilux_custom_webform_submit($form, $form_state){
foreach($form_state['values']['submitted'] as $key => $value){
$form_state['values']['submitted'][$key] = 'new_value_' . $key;
};
}
Please advise what is wrong in this code.
This should work:
<?php
$i = 0;
while($row = mysql_fetch_assoc($query)){
$dataLevel[$i]['q_id'] = $row['q_id'];
$dataLevel[$i]['response_value'] = $row['response_value'];
$dataLevel[$i]['cr_chpt'] = $row['cr_chpt'];
$dataLevel[$i]['ql_level'] = $row['ql_level'];
$i++;
}
?>
<script type="text/javascript">
var dataLevel = JSON.parse('<?php echo json_encode($dataLevel); ?>');
for(var i=0; i<dataLevel.length; i++){
document.write(dataLevel[i]['q_id'] + '<br />');
document.write(dataLevel[i]['response_value'] + '<br />');
document.write(dataLevel[i]['cr_chpt'] + '<br />');
document.write(dataLevel[i]['ql_level'] + '<br /><br />');
}
</script>
Can this help you?
<?php
$dataLevel = [[280, "ANALYZE", 260, 560],
[230, "APPLY", 260, 510],
[180, "UNDERSTAND", 260, 460],
[130, "REMEMBER", 260, 410]];
?>
<script type="text/javascript">
var dataLevel = JSON.parse('<?php echo json_encode($dataLevel); ?>');
for(var i=0; i<dataLevel.length; i++){
document.write(dataLevel[i] + '<br />');
}
</script>
jQuery('.date-pick').removeClass('hasDatepicker').datepicker({
dateFormat: 'mm-dd-yy'
});
Hi all.
I have a grid table and I need to set globally 2 kind of values for emptyrecords:
1. 'Nothing to display from the DB' -> if no data is retrieved from mysql
2. 'No data matches the search' -> after using search and nothing matched.
Till now I succeeded just to set globally emptyrecords, but only with one value:
$.extend($.jgrid.defaults,{emptyrecords: "Nothing to display"});
I have tried to combine with other methods:
-beforeProcessing
-gridComplete
-loadComplete
-jQuery("#grid-tbl").jqGrid('navGrid','#grid-pg',{emptyrecords: "No data matches the search"});
but it didn't work.
Please advise if it is possible to achieve this with jqGrid?
Finally I have managed to solve this task and works as expected. Of course, it can be extended. Here it is a simple way.
application.ini
resources.frontController.actionhelperpaths.Application_Controller_Helper = APPLICATION_PATH "/controllers/helpers"
Bootstrap.php
protected function _initMyActionHelpers()
{
$this->bootstrap('frontController');
$login = Zend_Controller_Action_HelperBroker::getStaticHelper('Login');
Zend_Controller_Action_HelperBroker::addHelper($login);
}
application/forms/Login.php
class Application_Form_Login extends Zend_Form
{
public function init()
{
$this->addElement('text', 'username', array(
'placeholder' => 'Userame',
'required' => true,
'validators' => array(
array('StringLength', false, array('max'=>75))
)
));
$this->addElement('password', 'password', array(
'placeholder' => 'Password',
'required' => true,
'validators' => array(
array('StringLength', false, array('max'=>150))
)
));
$this->addElement('submit', 'submitlogin', array(
'label' => 'Login'
));
}
}
application/forms/Logout.php
class Application_Form_Logout extends Zend_Form
{
public function init()
{
$this->addElement('submit', 'submitlogout', array(
'label' => 'Logout'
));
}
}
application/controllers/helpers/Login.php
class Application_Controller_Helper_Login extends Zend_Controller_Action_Helper_Abstract
{
public function preDispatch()
{
$sessionUser = new Zend_Session_Namespace('user');
$request = $this->getActionController()->getRequest();
if(!isset($sessionUser->username)){
$form = new Application_Form_Login();
if($request->isPost() && $request->getPost('submitlogin')) {
if($form->isValid($request->getPost())) {
$data = $form->getValues();
$sessionUser = new Zend_Session_Namespace('user');
$sessionUser->username = $data['username'];
}
}
} else {
if($request->isPost() && $request->getPost('submitlogout')) {
Zend_Session::namespaceUnset('user');
}
}
}
}
application/views/helpers/Login.php
class Zend_View_Helper_Login extends Zend_View_Helper_Abstract
{
public function Login()
{
$html = '';
$sessionUser = new Zend_Session_Namespace('user');
if(isset($sessionUser->username)) {
$html = '<p>Welcome, ' . $sessionUser->username . '.</p>';
$logout_form = new Application_Form_Logout();
$html .= $logout_form;
} else {
$login_form = new Application_Form_Login();
$html .= $login_form;
}
return $html;
}
}
layout.phtml
<div id="header"><?php echo $this->Login($this->Login); ?></div>
Hi!
I have a Zend project and I would like to implement a login form in the header of the site in such a way, that if a user is not logged in, he can use the site, but the form is always there, no matter what pages he access. If he is logged in, then his username is always in the header.
Please advise some links for documentation on this subject.
Thank you.
Is the server on Linux? I tested the code on the server that runs on Linux and I had the same problem and after runing in Terminal 'chmod 777 -R mytestsite' it worked fine. I just gave all privileges to the folder that contains the php script file and the image.
Check the picture properties, it may be read-only.
Then you may change the code to:
$old = "./images/general/item2.jpg";
$new = "./images/general/item44.jpg";
if(file_exists($old))
{
rename($old, $new) or die('Error renaming file.');
echo "The file has been renamed successfully.";
}
else
{
echo 'The file does not exist.';
}
Yes, it is working.
Actually I make some settings in Bootstrap for language, timezone, etc. The javascript code for getting user timezone I put in Layout. With the codes above I am able to catch the cookie value set with javascript and use in PHP.
But if there are better solutions, I would like to know them.