Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to search mysql DATE and return result together with date and the data?
    text
    copied!<p>I would like to know how to perform a date search and return the result?</p> <p>I made a form for user to key in the date manually</p> <pre><code>&lt;form method="post" action="result.php" id="searchform"&gt; &lt;input type="text" name="dob" /&gt; &lt;input type="submit" name="submit" value="Search" /&gt; </code></pre> <p>Also, already include the mysql connection in search.php</p> <pre><code>$dsn = 'mysql:host=localhost;dbname=mama'; $username = 'root'; $password = ''; $dbh = new PDO($dsn, $username, $password); $userDate = $_POST['dob']; $dateTime = DateTime::createFromFormat('d/m/Y', $userDate); $myFormat = $dateTime-&gt;format('Y-m-d'); $sql = "SELECT dob FROM data WHERE dob = :date"; $sth = $dbh-&gt;prepare($sql); $sth-&gt;execute(array('date'=&gt;$myFormat)); //Switched to array() syntax. $results = $sth-&gt;fetchAll(); foreach($results-&gt;query($sql) as $row) { print $row['rowone'] . " "; print $row['rowtwo'] . " "; print $row['rowthree'] . " "; print "$userDate"; } </code></pre> <p>The user will be key in date as per asian format --> DD/MM/YYYY but i understand that mysql DATE store as Y-m-d, the date row have another three row name (row1,row2,row3) that store data.</p> <p>What I need is, when the user enter the date in asian format, hit the search button, it will look for the date in mysql and return the date back together with other three row data.</p> <p>Besides that, there will be only one date for one row of data.</p> <p>Please advise, as I look at google, I couldn't find the most similar tutorial to perform as what I want.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload