Jump to content

Barand

Moderators
  • Posts

    24,551
  • Joined

  • Last visited

  • Days Won

    821

Community Answers

  1. Barand's post in MySQL Workbench ENUM() Given data type contains error was marked as the answer   
    Yes. Notepad is using non-standard single quotes. This should work
    ENUM('Ford','GMC','Chevrolet','Chrysler','Dodge','Buick','Toyota','Volvo','International','Kenworth','Peterbilt','Mack','Freightliner','Isuzu')
  2. Barand's post in Join three tables and show Null Values was marked as the answer   
    What if you select "childrenID" instead of "signupChildrenID"?
     
    Or
    SELECT * FROM activities LEFT JOIN signupActivity ON activityID = SignupActivityID AND signupActivitychildID = 33 LEFT JOIN children ON signupActivitychildID = childrenID WHERE activitySection = 3
  3. Barand's post in PDO statement error was marked as the answer   
    row is an object but row.id_itens isn't.
     
    You could have just done this (without the stringify)
    $('#myModal').modal('show').find('.modal-body #id_itens').val(row.id_itens);
  4. Barand's post in Can php do two execute (queries) in same time? was marked as the answer   
    try something like this
    <?php include('db_inc.php'); // defines HOST etc $db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE); $sql = "SELECT firstname , lastname , local FROM member ORDER BY firstname, lastname"; $local = ''; $nonlocal = ''; $res = $db->query($sql); while (list($fn, $ln, $loc) = $res->fetch_row()) { if ($loc=='Y') { $local .= "$fn $ln<br>"; } else { $nonlocal .= "$fn $ln<br>"; } } ?> <html> <head> </head> <body> <table border='1'> <tr><th>Local</th><th>Non-Local</th></tr> <tr style='vertical-align: top;'> <td><?=$local?></td> <td><?=$nonlocal?></td> </tr> </table> </body> </html>
  5. Barand's post in Mysql select latest record. was marked as the answer   
    try this
    SELECT sc.StringyChat_name , sc.StringyChat_ip , sc.StringyChat_time FROM StringyChat sc INNER JOIN ( SELECT StringyChat_name , MAX(StringyChat_time) as StringyChat_time FROM StringyChat GROUP BY StringyChat_name ) latest USING (StringyChat_name, StringyChat_time) WHERE sc.StringyChat_time >= (UNIX_TIMESTAMP() - 3600) AND StringyChat_name NOT IN ( '" . implode($galleries, "', '") . "' ) ORDER BY StringyChat_time DESC LIMIT $offset, $rowsperpage If that gets what you want then you need to JOIN to user2 to get the id's in the same query. (Don't run queries inside loops)
  6. Barand's post in Changing Dates to nearest Business Day was marked as the answer   
    try this to correct the dates in the table
    UPDATE date_sample SET date = CASE WHEN dayofweek(date)=1 THEN date + INTERVAL 1 DAY -- change Sun to Mon WHEN dayofweek(date)=7 THEN date - INTERVAL 1 DAY -- change Sat to Fri ELSE date -- leave weekdays alone END If you want to leave them alone in the table but modify on selection then you can use the same CASE statement
    SELECT CASE WHEN dayofweek(date)=1 THEN date + INTERVAL 1 DAY -- change Sun to Mon WHEN dayofweek(date)=7 THEN date - INTERVAL 1 DAY -- change Sat to Fri ELSE date -- leave weekdays alone END as date FROM table
  7. Barand's post in Selecting two rows by date was marked as the answer   
    You could
    ... ORDER BY date='$XXX' DESC LIMIT 1
  8. 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?
  9. 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; });
  10. 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)
  11. 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.
  12. 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
  13. 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']]; ?>
  14. 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); ?>

  15. 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/>'; }
  16. 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 | +-------------+-----------+----------+----------+-----------+---------------------+
  17. 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.
  18. 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')";
  19. 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.