Jump to content

Barand

Moderators
  • Content count

    18,366
  • Joined

  • Last visited

  • Days Won

    303

Barand last won the day on July 13

Barand had the most liked content!

Community Reputation

1,166 Excellent

About Barand

  • Rank
    Sen . ( ile || sei )

Profile Information

Recent Profile Visitors

54,997 profile views
  1. You can get the id of the auto_incremented value of the last record added PDO $newId = $stmt->insert_id; MYSQLI $newId = $conn->insert_id;
  2. Barand

    Struggling to select posts & comments

    Example pseudocode currentPost = 0 while fetch next record if postID != currentPost output post data set currentPost = postID endif output comment data endwhile
  3. Barand

    Struggling to select posts & comments

    That's the way JOINS work. You get the data from the post table joined to the data from the matching comments table. If you only want posts that have comments, use INNER JOIN. If you want all posts, and data from comments where they exist, use LEFT JOIN. How you display those results is controlled by your processing of the query results.
  4. FYI Stored procedures do the same job of separating the values from the query as prepared statements do. Both involve passing the values as parameters instead of embedding the variables' values directly in the query string.
  5. Barand

    timer not updating in database reliably

    that line means If the value $_POST['timer'] has been set then set $test to that value, otherwise set it to a default value of 0 (RTFM) After that It then checks that the value is non-zero before attempting to update the database. Regarding database storage, it is a time value so it makes sense to store it as TIME type.
  6. Barand

    timer not updating in database reliably

    Assuming the columns in your table are like this CREATE TABLE `primerlevel_tests` ( `user_uid` varchar(10) NOT NULL DEFAULT '', `time_achieved` time(2) DEFAULT NULL, // seconds to 2 dec.places PRIMARY KEY (`user_uid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; then this revised code should work for you if ($_SERVER['REQUEST_METHOD']=='POST') { include("db_inc.php"); // USE YOR OWN $conn = myConnect('test'); // CONNECT CODE $test = $_POST['timer'] ?? 0; $userid = 'piano0011'; if ($test) { $sql = "INSERT INTO primerlevel_tests (time_achieved, user_uid) VALUES (?,?) ON DUPLICATE KEY UPDATE time_achieved = VALUES(time_achieved) "; $stmt = $conn->prepare($sql); $stmt->bind_param("ss", $test, $userid); $stmt->execute(); } } ?> <!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" type="text/css" href="stopwatch.css"> <link rel="stylesheet" type="text/css" href=""> <link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet"> <script type="text/javascript"> var status =0; var time = 0; function start() { status = 1; document.getElementById("startBtn").disabled = true; timer(); } function stop() { status = 0; } function reset() { status = 0; time = 0; document.getElementById("startBtn").disabled = false; document.getElementById("timerLabel").innerHTML = "00:00:00"; } function timer() { if (status == 1) { setTimeout(function() { time++; var min = Math.floor(time/100/60); var sec = Math.floor(time/100); var mSec = time % 100; if(min < 10) { min = "0" + min; } if (sec >= 60) { sec = sec % 60; } if (sec < 10) { sec = "0" + sec; } document.getElementById("timerResult").innerHTML = "00:" + min + ":" + sec + "." + mSec; timer(); }, 10); } } function output() { var x = document.getElementById('timerResult').innerHTML; document.getElementById('test1').value = x; } </script> </head> <body> <form action="" method="POST"> <input type ="text" name="timer" id='test1' > <button type="submit" name="submit">Click here to submit result</button> <div class="container"> <h1 class="title">Stopwatch</h1> <h1 id="timerResult">00:20:00</h1> <input type="button" value="START" class="myButton" onclick="start()" id="startBtn"> <input type="button" value="STOP" class="myButton" onclick="stop()"> <input type="button" value="RESET" class="myButton" onclick="reset()"> <input type="button" class="myButton" onclick="output()" value="output"> </div> </form> </body> </html>
  7. Barand

    Use of conditions (Switch/IF)

    The quality of the response is proportiional to the quality of the question.
  8. Barand

    Use of conditions (Switch/IF)

    ... But not completely impossible Three quotes, new text and two lines of code <?php ?>
  9. Barand

    Use of conditions (Switch/IF)

    Can you rephrase your question in a way that makes some sense?
  10. Barand

    Dividing $obj->width() output by 2?

    try $halfwidth = $obj->width() / 2; echo '<img src="'.$obj->src().'" title="'.$obj->artist().'" style="max-width:'.$halfwidth.'px;"/>';
  11. Barand

    Dividing $obj->width() output by 2?

    Not from the code you posted - a php line directly followed by an html line. Can you post the relevant current "working" code so I can see it in context. In your Image class, are src(), artist() and width() really methods or are they properties?
  12. Barand

    Dividing $obj->width() output by 2?

    Images tend to be uploaded once but download for display many times. Thus the most efficient method is to create a display-sized image when the file is uploaded and store both. When required for output, get the display-sized image instead of the original. This results in smaller files hence faster loads.
  13. Barand

    mysqli rename table column

    Quite a lot. Assuming it is currently defined as `SALE PRICE` DECIMAL(12, 2) NOT NULL DEFAULT 0 then you need ALTER TABLE bethany CHANGE COLUMN `SALE PRICE` saleprice DECIMAL(12, 2) NOT NULL DEFAULT 0
  14. Barand

    How to handle form variables that aren't used

    I'd go a step further and give all the checkboxes the same name EG name='problem[]' so they are posted as an array <label><input type="checkbox" name="problem[]" value="Hard Drive Crashed"> Hard Drive Crashed</label><br> <label><input type="checkbox" name="problem[]" value="Has Virus"> Has Virus</label><br> <label><input type="checkbox" name="problem[]" value="Needs Operating System"> Needs Operating System</label><br> <label><input type="checkbox" name="problem[]" value="Needs Microsoft Office"> Needs Microsoft Office</label><br> <label><input type="checkbox" name="problem[]" value="Interested In Backup Services"> Interested In Backup Services</label><br> <label><input type="checkbox" name="problem[]" value="Wants A Custom PC Build"> Wants A Custom PC Build</label><br> In your processing foreach ($_POST['problem'] as $problem) { echo $problem . '<br>'; }
  15. Barand

    Intoduce myself

    Looks like you have made yourself at home here already, if not taken over the site
×

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.