View data in a mysql PHP week range

Asked

Viewed 66 times

1

I am creating a code that will show the tidal table, I have a table with the following fields: Date - Time - Tideheight

It is already all filled, I need to make a query and select the data of the week, as the day, the hour and the height of the tide.

How it works in the navy website.

I wrote the code below, I need it to display the current week, or an interval of 7 days from today forward.

//semana atual
$data = date('W');

// cria a instrução SQL que vai selecionar os dados 
$query = mysql_query("SELECT * FROM tidedata WHERE WEEK(date) = '$data'"); 

echo "Tide for week:<br/>";

while ($array = mysql_fetch_assoc($query)) {

    echo $array["date"]." ".$array["time"]." ".$array["tideheight"]."<br/>";

} 

How do I display the table data in the interval of a week, displaying the day, time and height of the tide?

I solved this problem as follows:

//semana atual
$semana = date('W');
$ano = date('Y');

// cria a instrução SQL que vai selecionar os dados 
$query = mysql_query("SELECT * FROM tidedata WHERE WEEK(date) = '$semana' AND YEAR(date) = '$ano'"); 

echo "Tide for week:<br/>";

while ($array = mysql_fetch_assoc($query)) {

        echo $array["date"]." ".$array["time"]." ".$array["tideheight"]."<br/>";

}

If someone has another solution can post below.

  • 1

    To start your code there is an error: you arrow the variable $date and query in the bank with a variable that does not exist, $date. Fix it and see what happens in your application.

  • I noticed that too, I’m making the necessary changes.

  • 1

    There are functions like WEEK and WEEKOFYEAR that can be useful.

  • 2

    See if any of these questions help: http://answall.com/questions/9296/ | http://answall.com/questions/14653/ | http://answall.com/questions/16600/ | http://answall.com/questions/6073/ | http://answall.com/questions/4177/ http://en.stackoverflow.com/questions/30891/ | http://answall.com/questions/29997/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.