Jump to content

Barand

Moderators
  • Posts

    24,450
  • Joined

  • Last visited

  • Days Won

    809

Community Answers

  1. Barand's post in Selecting two rows by date was marked as the answer   
    You could
    ... ORDER BY date='$XXX' DESC LIMIT 1
  2. Barand's post in Find duplicate rows on specific value was marked as the answer   
    if you run this query
    SELECT * FROM zamjene_brojeva WHERE glavni_broj='966 45 19-68' does it list those four records?
  3. Barand's post in How to Have 2 field sorting in PHP was marked as the answer   
    Just swap the $a and $b round
    uasort($data, function($a, $b) { $total = $b['total'] - $a['total']; //SORT BY DESC if($total === 0) { return strcmp($a['emp'], $b['emp']); // THIS line now sorts by ASC } return $total; });
  4. Barand's post in GrandTotal for the field Price was marked as the answer   
    Are you formatting the price fields with commas in the query? If so 1,850.00 is treated as 1 by PHP (up to the first non-numeric character)
  5. Barand's post in mysqli LIKE query does not work was marked as the answer   
    You use LIKE with wildcards when you are searching for something that contains the search string. If you are looking for an exact match use "=". In this case it could be that perhaps the title in the db has extra space character at the end.
     
    Try this with your current query
    $LIKE ="%rammstein%"; If that fails it could be you are using a case-sensitive collation.
  6. Barand's post in query with two between error was marked as the answer   
    Yes, you are correct. It does return a count of 1. So changing the query to see what it is counting gives
    SELECT * FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = 61 AND (((`ebspma_paad_ebspma`.`req_material_reserva`.`idtempoInicio` BETWEEN 3 AND 3) AND (`ebspma_paad_ebspma`.`req_material_reserva`.`idTempoFim` BETWEEN 3 AND 3)) OR (`ebspma_paad_ebspma`.`req_material_reserva`.`idtempoInicio` <= 3 AND `ebspma_paad_ebspma`.`req_material_reserva`.`idTempoFim` >= 3)) AND `ebspma_paad_ebspma`.`req_material_reserva`.`data` = "2015-10-23" +-----------+--------------+--------+---------------+------------+---------------+------------+ | idreserva | idutilizador | idsala | idtempoInicio | idtempoFim | idequipamento | data | +-----------+--------------+--------+---------------+------------+---------------+------------+ | 3 | 719 | 61 | 3 | 3 | NULL | 2015-10-23 | +-----------+--------------+--------+---------------+------------+---------------+------------+ which. I believe, explains the count of 1
  7. Barand's post in can anybody help me! was marked as the answer   
    It's a lot easier to use an array for the messages
     
    form
    <select name='language'> <option value='1'>English</option> <option value='2'>French</option> <option value='3'>German</option> <option value='4'>Klingon</option> </select> processing
    <?php $translations = array ( 1 => 'Welcome', 2 => 'Bienvenue', 3 => 'Herzlich Willkommen', 4 => 'yI\'el' ); echo $translations[$_GET['language']]; ?>
  8. Barand's post in cropping a part of an image was marked as the answer   
    Is this what you are trying to achieve?
    <?php $x1 = 224; $y1 = 94; $x2 = 663; $y2 = 487; $w = $x2-$x1; $h = $y2-$y1; $im = imagecreatetruecolor($w, $h); $src = imagecreatefrompng('leopard.png'); imagecopyresized($im,$src,0,0,$x1,$y1,$w,$h,$w,$h); imagepng($im, 'leopard_cropped.png'); imagedestroy($im); imagedestroy($src); ?>

  9. Barand's post in Need help printing a value from array was marked as the answer   
    try
    foreach ($example as $obj) { echo $obj->fileUrl . '<br/>'; }
  10. Barand's post in Select Query Problems was marked as the answer   
    My data
    mysql> SELECT * FROM database_prospects; +-------------+-----------+----------+--------+ | prospect_id | FirstName | LastName | Active | +-------------+-----------+----------+--------+ | 1 | John | Smith | 1 | | 2 | Jane | Doe | 0 | | 3 | Joe | Bloggs | 1 | | 4 | Davy | Jones | 1 | +-------------+-----------+----------+--------+ 4 rows in set (0.00 sec) mysql> SELECT * FROM database_prospect_notes; +---------+-------------+----------+-----------+---------------------+ | note_id | prospect_id | staff_id | comment | date | +---------+-------------+----------+-----------+---------------------+ | 1 | 1 | 123 | comment 1 | 2015-07-12 00:00:00 | | 2 | 1 | 120 | comment 2 | 2015-09-14 00:00:00 | | 3 | 2 | 125 | comment 3 | 2015-06-22 00:00:00 | | 4 | 2 | 128 | comment 4 | 2015-09-01 00:00:00 | | 5 | 3 | 125 | comment 5 | 2015-08-02 00:00:00 | | 6 | 3 | 129 | comment 6 | 2015-09-05 00:00:00 | +---------+-------------+----------+-----------+---------------------+ 6 rows in set (0.00 sec) Query
    SELECT p.prospect_id , p.FirstName , p.LastName , notes.staff_id , notes.comment , notes.date FROM database_prospects p LEFT join ( -- -- subquery to get notes record with latest date -- SELECT n.prospect_id , n.staff_id , n.date , n.comment FROM database_prospect_notes n INNER JOIN ( -- -- subquery to find latest dates -- SELECT prospect_id , MAX(date) as date FROM database_prospect_notes GROUP BY prospect_id ) latest ON n.prospect_id = latest.prospect_id AND n.date = latest.date ) notes USING (prospect_id) WHERE p.active = 1; Results
    +-------------+-----------+----------+----------+-----------+---------------------+ | prospect_id | FirstName | LastName | staff_id | comment | date | +-------------+-----------+----------+----------+-----------+---------------------+ | 1 | John | Smith | 120 | comment 2 | 2015-09-14 00:00:00 | | 3 | Joe | Bloggs | 129 | comment 6 | 2015-09-05 00:00:00 | | 4 | Davy | Jones | NULL | NULL | NULL | +-------------+-----------+----------+----------+-----------+---------------------+
  11. Barand's post in Call to a member function prepare() on a non-object was marked as the answer   
    The error message suggests that $this->connection is not a valid connection object in the failing function.
     
    The query in the first function does not need to be a prepared statement - there is no user input.
     
    The second function does not require the parameter to be sanitized if you are preparing the statement, You should use a placeholder and bind the parameter to the placeholder. It is the separation of data from query statement that makes preparation effective.
  12. Barand's post in how to delete from a table was marked as the answer   
    This could work
    $str = 'HG||Fxg|||ergx||xx'; // replace "|||" with "','" so you have separate records split by quote-comma-quote $str = str_replace("|||", "','", $str); $sql = "DELETE FROM _projecttbl WHERE P_id = 1 AND CONCAT(Prt_id, '||', Oth_id) NOT IN ('$str')";
  13. Barand's post in Complex query help was marked as the answer   
    try
    SELECT COUNT( * ) AS total FROM `nem_pae_atividades` WHERE `idutilizador` =1355 AND `data` <= CURDATE( ) AND ( `realizado` IS NULL OR LENGTH( `realizado` )=0 )
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.