
cypher86
Members-
Posts
88 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
cypher86's Achievements

Member (2/5)
0
Reputation
-
right! follow the ginerjm way
-
i think you got the parenthesis wrong while ($i < $size) { if ($arr[$i] == $num) { return TRUE; } else { i++; } return FALSE; } like this the while does 1 loop only. either find the number on the first hit or return false. should be more like $found=false while ($i < $size) { if ($arr[$i] == $num) { //return TRUE; $found=true; } else { i++; } //return FALSE; } return $found; this solution is not optimized because evaluate all the array even when not needed but does the trick
-
php has already a built-in function that does the trick. it's called in_array() http://php.net/manual/en/function.in-array.php
-
Help needed with language selection dropdown menu
cypher86 replied to izzy's topic in PHP Coding Help
i didn't fully understand your question, still there is for sure an error in your script, an echo is missing <option value=<?""$lang""?>>Language selection</option> should be <option value="<?php echo $lang; ?>">Language selection</option> in order to work -
$row is already in that format. anyway try this $i=0; while($row = mysql_fetch_assoc($result)) { $co-ordinate[$i]= ( "postcode" => $row['postcode'], "latitude" => $row['latitude'], "longitude" => $row['longitude'] ); $i++; }
-
i'm so sorry. i don't know what i was testing. now with the code given in the first post works correctly
-
yes no error are diplayed, the json is returned and seems identical to the one returned from the first script then it returns nothing. since the json is returned i assume that the parameters are correctly set.
-
sorry for the double posting. the script does not return any error. echoing the results i don't see any difference. do you need me to post the two results?
-
hello, i developed a php script which get called via autocomplete jQuery. surfing the internet i found the following script that does the work $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends $qstring = "query text"; $result = mysql_query($qstring);//query the database for entries containing the term while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values { $row['field1']=htmlentities(stripslashes($row['field1'])); $row['field2']=htmlentities(stripslashes($row['field2'])); $row['field3']=htmlentities(stripslashes($row['field3'])); $row['id']=(int)$row['id']; $row_set[] = $row;//build an array } echo json_encode($row_set);//format the array into json data but i wanted (for security reason) to use bind parameter so i convert it to $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends $qstring = "query string"; $search="%$term%"; $sql=$db->prepare($qstring); $sql->bind_param('s',$search); $sql->execute(); $sql->bind_result($id,$field1,$field2,$field3); //build an array while($sql->fetch()) { $row['id']=(int)$id; $row['field1']=htmlentities(stripslashes($field1)); $row['field2']=htmlentities(stripslashes($field2)); $row['field3']=htmlentities(stripslashes($field3)); $row_set[]=$row; } echo json_encode($row_set);//format the array into json data*/ i echoed the output and seems identical to me, still with the first script the autocomplete works while the second don't. any clue?
-
hello, i'm facing this problem. i have a main page with the definition of tab. each tab is a different page called by ajax when selected. in some tabs i'd like to add datepickers but i'm having trouble. when i load the tab the datepicker does not work. do you have any suggestion or a better way to do this? thanks here's the code i'm using main.php <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css" /> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script> <script src="../lib/datepicker-it.js"></script> <script type="text/javascript" src="../lib/rollover.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="../css/screen.css" /> <link rel="stylesheet" type="text/css" media="screen" href="../css/jqueryobject.css" /> <script> $(document).ready(function() { $( "#tabs" ).tabs({ }); }); </script> </head> <body> <?php include ("../top.php"); ?> <br /> <fieldset><legend>Ricerche</legend> <div id="tabs"> <ul> <li><a href="tab1.php">Tab1</a></li> <li><a href="tab2.php">Tab2</a></li> <li><a href="tab3.php">Tab3</a></li> </ul> </div> </fieldset> </body> </html> tab1.php <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script> <script> $(document).ready(function() { $.datepicker.setDefaults( $.datepicker.regional[ "it" ] ); $( ".datepicker" ).datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd/mm/yy", beforeShowDay: highlightOddsEven, showOtherMonths: true, selectOtherMonths: true }); function highlightOddsEven(date) { //return [true, date.getDate() % 2 == 1 ? 'odd' : '']; return [true, date.getDate() % 2 == 1 ? 'oddEven' : 'oddEven']; } </script> <div id="termConsegna" name="termConsegna"> <fieldset><legend>Termini Consegna</legend> <form class="cmxform" name="form_termine" id="form_termine" method="post" action="tab1.php"> <input type="hidden" id="submit" name="submit" value="1"> <table id="tab_termine" class="css-table"> <?php $i=1; while($sql->fetch()){ echo "<tr> <td>da <input type=\"text\" name=\"data_da$i\" id=\"data_da$i\" class=\"datepicker\" pattern=\"\d{1,2}/\d{1,2}/\d{4}\" $dateValidation value=\"".dbDateToNormal($da)."\"></td> <td> a <input type=\"text\" name=\"data_a$i\" id=\"data_a$i\" class=\"datepicker\" pattern=\"\d{1,2}/\d{1,2}/\d{4}\" $dateValidation value=\"".dbDateToNormal($a)."\"></td> <td><input type=\"text\" name=\"data_termine$i\" id=\"data_termine$i\" class=\"datepicker\" pattern=\"\d{1,2}/\d{1,2}/\d{4}\" $dateValidation value=\"".dbDateToNormal($termine)."\"></td> </tr>"; $i++; } ?> <input type="hidden" name="num_termini" id="num_termini" value="<?php echo $i; ?>"> <tr><td colspan="3"><input type="submit" value="Salva"></td></tr> </table> </form> </fieldset> </div> tab2.php <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script> <script> $(document).ready(function() { $.datepicker.setDefaults( $.datepicker.regional[ "it" ] ); $( ".datepicker" ).datepicker({ changeMonth: true, changeYear: true, dateFormat: "dd/mm/yy", beforeShowDay: highlightOddsEven, showOtherMonths: true, selectOtherMonths: true }); function highlightOddsEven(date) { //return [true, date.getDate() % 2 == 1 ? 'odd' : '']; return [true, date.getDate() % 2 == 1 ? 'oddEven' : 'oddEven']; } </script> <div id="ricAvanz" name="ricAvanz"> <fieldset><legend>Ricerca Avanzata</legend> <form class="cmxform" id="form_ricerca" name="form_ricerca" action="ricerca.php" method="post"> <input type="hidden" id="ricerca" name="ricerca" value="1"> <p><label>Data1: </label>da:<input type="text" name="da_comparizione" id="da_comparizione" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php echo $dateValidation; ?> value="<?php if(isset($_POST['ricerca'])) echo $_POST['da_comparizione']; ?>" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php echo $dateValidation; ?>><label> </label>a:<input type="text" name="a_comparizione" id="a_comparizione" value="<?php if(isset($_POST['ricerca'])) echo $_POST['a_comparizione']; ?>" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php if(isset($_POST['ricerca'])) echo $dateValidation; ?>></p> <p><label>Data2: </label><input type="text" name="asta_si" id="asta_si" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php echo $dateValidation; ?> value="<?php if(isset($_POST['ricerca'])) echo $_POST['asta_si']; ?>" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php echo $dateValidation; ?>></p> <p><label>Data3: </label><input type="text" name="asta_ci" id="asta_ci" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php echo $dateValidation; ?> value="<?php if(isset($_POST['ricerca'])) echo $_POST['asta_ci']; ?>" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php echo $dateValidation; ?>></p> <p><label>Data4: </label><input type="text" name="sloggio_pa" id="sloggio_pa" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php echo $dateValidation; ?> value="<?php if(isset($_POST['ricerca'])) echo $_POST['sloggio_pa']; ?>" class="datepicker" pattern="\d{1,2}/\d{1,2}/\d{4}" <?php echo $dateValidation; ?>></p> <p><input type="submit" value="Cerca"></p> </form> <fieldset> <?php echo $fieldset; while (isset($_POST['ricerca']) and $ricerca->fetch()) echo "<p><a href=\"../esecuzioni/panel_generale.php\">.......</a></p>"; ?> </fieldset> </div>
-
i'm using jquery autocomplete with a remote php script. this code works fine: db_connect(); $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends $qstring = "SELECT id,nominativo,indirizzo,telefono,fax,e_mail FROM legale WHERE nominativo LIKE '%".$term."%'"; $result = mysql_query($qstring);//query the database for entries containing the term while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values { $row['nominativo']=htmlentities(stripslashes($row['nominativo'])); $row['indirizzo']=htmlentities(stripslashes($row['indirizzo'])); $row['telefono']=htmlentities(stripslashes($row['telefono'])); $row['fax']=htmlentities(stripslashes($row['fax'])); $row['e_mail']=htmlentities(stripslashes($row['e_mail'])); $row['id']=(int)$row['id']; $row_set[] = $row;//build an array } echo json_encode($row_set);//format the array into json data this one doesn't: $db=db_connect_param(); $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends if($_GET['what']=="legale") $qstring = "SELECT id,nominativo,indirizzo,telefono,fax,e_mail FROM legale WHERE nominativo LIKE ?"; $search="%$term%"; $sql=$db->prepare($qstring); $sql->bind_param('s',$search); $sql->execute(); $sql->bind_result($id,$nominativo,$indirizzo,$telefono,$fax,$e_mail); //build an array while($sql->fetch()) { $row['nominativo']=htmlentities(stripslashes($nominativo)); $row['indirizzo']=htmlentities(stripslashes($indirizzo)); $row['telefono']=htmlentities(stripslashes($telefono)); $row['fax']=htmlentities(stripslashes($fax)); $row['e_mail']=htmlentities(stripslashes($e_mail)); $row['id']=(int)$id; $row_set[]=$row; } echo json_encode($row_set);//format the array into json data*/ what's the difference? the json returned seems the same.
-
nothing append. the last log seems to refer to 9:15 am while i load the page now...
-
ok thx. i add the @ORM\Entity and repalce the datetime doctrine type with date. now a strange thing append.... when i refresh the page it gives me a blank page.
-
ok i'm totally confused... what am i doing wrong???? Nominativo entity: <?php namespace Fatturazione\FatturazioneBundle\Entity; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\Length; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="nominativo") * @ORM\HasLifecycleCallbacks */ class Nominativo { /** * @ORM\id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string") */ protected $nominativo; /** * @ORM\Column(type="string") */ protected $indirizzo; /** * @ORM\Column(type="string") */ protected $pi; /** * @ORM\Column(type="string") */ protected $cf; /** * @ORM\Column(type="string") */ protected $tel; /** * @ORM\Column(type="string") */ protected $fax; /** * @ORM\Column(type="string") */ protected $email; public function getNominativo() { return $this->nominativo; } public function setNominativo($nominativo) { $this->nominativo=$nominativo; } public function getIndirizzo() { return $this->indirizzo; } public function setIndirizzo($indirizzo) { $this->indirizzo=$indirizzo; } public function getPi() { return $this->pi; } public function setPi($pi) { $this->pi=$pi; } public function getCf() { return $this->cf; } public function setCf($cf) { $this->cf=$cf; } public function getTel() { return $this->tel; } public function setTel($tel) { $this->tel=$tel; } public function getFax() { return $this->fax; } public function setFax($fax) { $this->fax=$fax; } public function getEmail() { return $this->email; } public function setEmail($email) { $this->email=$email; } public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('nominativo', new NotBlank()); $metadata->addPropertyConstraint('nominativo', new Length(array('max'=>50, 'maxMessage'=>'Testo massimo di 50 caratteri'))); $metadata->addPropertyConstraint('indirizzo', new NotBlank()); $metadata->addPropertyConstraint('indirizzo', new Length(array('max'=>50, 'maxMessage'=>'Testo massimo di 50 caratteri'))); $metadata->addPropertyConstraint('pi', new NotBlank()); $metadata->addPropertyConstraint('pi', new Length(array('max'=>20, 'maxMessage'=>'Testo massimo di 20 caratteri'))); $metadata->addPropertyConstraint('cf', new NotBlank()); $metadata->addPropertyConstraint('cf', new Length(array('max'=>20, 'maxMessage'=>'Testo massimo di 20 caratteri'))); $metadata->addPropertyConstraint('tel', new NotBlank()); $metadata->addPropertyConstraint('tel', new Length(array('max'=>20, 'maxMessage'=>'Testo massimo di 20 caratteri'))); $metadata->addPropertyConstraint('fax', new NotBlank()); $metadata->addPropertyConstraint('fax', new Length(array('max'=>20, 'maxMessage'=>'Testo massimo di 20 caratteri'))); $metadata->addPropertyConstraint('email', new Email()); } public function getNominativi($limit = null) { $qb = $this->createQueryBuilder('b') ->select('b.id, b.nominativo') ->addOrderBy('b.nominativo', 'ASC'); if (false === is_null($limit)) $qb->setMaxResults($limit); return $qb->getQuery() ->getResult(); } public function __toString() { return getNominativi(); } } ?> causale entity: <?php namespace Fatturazione\FatturazioneBundle\Entity; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\Date; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="causale") * @ORM\HasLifecycleCallbacks */ class Causale { /** * @ORM\id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="datetime") */ protected $data; /** * @ORM\Column(type="string") */ protected $descrizione; /** * @ORM\Column(type="number") */ protected $onorario; /** * @ORM\Column(type="number") */ protected $spese; /** * @ORM\Column(type="number") */ protected $rimborsi; /** * @ORM\ManyToOne(targetEntity="Nominativo", inversedBy="causale") * @ORM\JoinColumn(name="nominativo", referencedColumnName="id") * @ORM\Column(type="integer") */ protected $nominativo; protected $tipoCausale; public function getId() { return $this->id; } public function setId($id) { $this->id=$id; } public function getData() { return $this->data; } public function setData($data) { $this->data=$data; } public function getDescrizione() { return $this->descrizione; } public function setDescrizione($descrizione) { $this->descrizione=$descrizione; } public function getOnorario() { return $this->onorario; } public function setOnorario($onorario) { $this->onorario=$onorario; } public function getSpese() { return $this->spese; } public function setSpese($spese) { $this->spese=$spese; } public function getRimborsi() { return $this->rimborsi; } public function setRimborsi($rimborsi) { $this->rimborsi=$rimborsi; } public function getNominativo() { return $this->nominativo; } public function setNominativo($nominativo) { $this->nominativo=$nominativo; } public function getTipoCausale() { return $this->tipoCausale; } public function setTipoCausale($tipoCausale) { $this->tipoCausale=$tipoCausale; } public function __toString() { return $this->getNominativo; } public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('data', new NotBlank()); $metadata->addPropertyConstraint('data', new Date(array('message'=>'Data non valida'))); $metadata->addPropertyConstraint('descrizione', new Length(array('max'=>200, 'maxMessage'=>'Testo massimo di 200 caratteri'))); } } ?> form: <?php namespace Fatturazione\FatturazioneBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Doctrine\ORM\EntityRepository; class CausaleType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('data','date',array('widget' => 'single_text', 'format' => 'yyyy-MM-dd')); $builder->add('descrizione'); $builder->add('onorario','number'); $builder->add('spese','number'); $builder->add('rimborsi','number'); $builder->add('nominativo','entity', array('class' => 'FatturazioneFatturazioneBundle:Causale', 'expanded' => 'false', 'multiple' => 'false')); $builder->add('tipoCausale','choice',array('choices' => array('0' => 'Fattura', '1' => 'Causale'), 'required' => true)); } public function getName() { return 'causale'; } } ?>
-
my need is to create a combobox that takes its values from a table (or generally a query)