Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:15:54+00:00 2026-06-02T09:15:54+00:00

i have this table in database which called data and i want make this

  • 0

i have this table in database which called data
table data

and i want make this sql

     $sql = mysql_query("SELECT $menucompare,( substr($menucompare, 13, 2)) AS dayname FROM data WHERE ... ");

Obs

    $menucompare // is variable which the date is selected from table(date or date2 or date3..) 

lets say we have this date from table 04/10/2012-(Tuesday) under the week 6 in w_date, so after substracting as it saids in sql it will be Tu .

in week 7 there is 2 dates one .
what i want is to output by every week the days names ordered by days

exemple like that

  week 7

   Tu
   Fr
   .
   .

or

week 6
Tu
.
.

can this happen ?is there a special WHERE clause here ?
and is it possible to write sql where claculating how many dates are in the week
for exemple how many dates in week 7 , in the table up there is 2 in week 7

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:15:56+00:00Added an answer on June 2, 2026 at 9:15 am

    You’ve asked a couple of different questions here, but before I try to address them directly it might be worth considering (if at all possible) changing the data type of your date columns to the DATE type and then using functions such as DATE_FORMAT(`date`, "%a") to obtain the first characters of the relevant day name.

    Also, please be very careful to avoid malicious SQL injection when inserting variables from another language into a SQL statement: consider using prepared statements. Sadly, to do so in this case you will stumble upon another problem because of your database design: see this question for more information.

    On to your questions:

    1. can this [the example output shown] happen?

      Yes, it can. You want to “group” your results, so have a look at the GROUP BY clause to the SELECT statement. Try a command like:

      SELECT
        `w_date`,
        GROUP_CONCAT(SUBSTR(`date`, 13, 2) SEPARATOR "\n") AS `daynames`
      FROM `data`
      WHERE ...
      GROUP BY `w_date`;
      

      As you can see, the results are grouped in the way you want – but the list of day abbreviations is a separate result column to the week number; to output the data precisely as shown is a further manipulation that must occur at the application level.

    2. is it possible to write sql where claculating how many dates are in the week for exemple how many dates in week 7

      Yes, absolutely. To obtain the total number of records for a given week:

      SELECT COUNT(*) FROM `data` WHERE `w_date` = 7;
      

      Or for the number of distinct days within a given week:

      SELECT COUNT(DISTINCT `date`) FROM `data` WHERE `w_date` = 7;
      

      Or to get such for every week:

      SELECT `w_date`, COUNT(*) FROM `data` GROUP BY `w_date`;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table in my SQL Server database called OrderDetail which stores the order
I have a database application in which a group is modeled like this: TABLE
I have a table like this in my database (SQL Server 2008) ID Type
I have a database table called AllCustomersHistoryOfRecords which is table with history of all
So I have this table in my database Item Cat1 Cat2 -------------------- Aaa Red
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have a database table using an enum. This is already working with hibernate
I have written a function to print database table to an array like this
I always forget how to do things like this. I have a database table
I have a table in my postgresql 8.4 database like this: id(serial), event_type_id(id, foreign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.