Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a database table(eyfstb) containing two fields,

datetable = ",2019-11-04,2019-11-06,2019-11-08"
documenttable = ",first,second,third"

I am trying to use two input fields to get a range of data from the database.


I want the result to be

$datefiles = ",2019-11-04,2019-11-06";
$documentfiles = ",first,second";


What I have tried:

I have a database table(eyfstb) containing two fields,

datetable = ",2019-11-04,2019-11-06,2019-11-08"
documenttable = ",first,second,third"

I am trying to use two input fields to get a range of data from the database.

PHP
<form method="POST" action="" id="my_form">
   <small&gt;Start&lt;/small>
   <input type="date" name="datfrm">
   <input type="date" name="datto">
   <small&gt;End Date&lt;/small>
   <input type="submit" name="subdr" value="Display Record"></center>
</form>

i want to get the record "first,second" and the date "2019-11-04,2019-11-06" if the date ranges are 2019-10-01 to 2019-11-07

PHP
 $products = $db->query("SELECT datetable,documenttable FROM eyfstb WHERE specialnum='$rollnum'");
while($row = $products->fetch_assoc()){
$datefiles = $row["datetable"]; $documentfiles = $row["documenttable"];

I want the result to be
$datefiles = ",2019-11-04,2019-11-06";
$documentfiles = ",first,second";
Posted
Updated 4-Jun-20 8:19am
v2

1 solution

It seems you really need to go "back to the drawing board" on this. Your table design, to start. Learn about datetime fields (or more specifically, date fields).

See if you can put your dates in separate fields.

Learn about the "BETWEEN" clause in a SQL query.

Otherwise, things will not go well for your plans.

Something like this:
SQL
SELECT whatever FROM wherever where something BETWEEN startDate and endDate AND somethingelse between otherStartDate AND otherEndDate.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900