calle08 Posted July 13, 2011 Share Posted July 13, 2011 SELECT name, date, comment FROM narvaro_all WHERE datum ='2011-07-14' AND datum='2011-07-20' Just getting empty result have data in both dats Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/ Share on other sites More sharing options...
trq Posted July 13, 2011 Share Posted July 13, 2011 Read your query. How can datum equal two different values at the same time? Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242193 Share on other sites More sharing options...
calle08 Posted July 13, 2011 Author Share Posted July 13, 2011 Wrong of me SELECT name, date, comment FROM narvaro_all WHERE date='2011-07-14' AND date='2011-07-20' But still get empty results. Don't understand? Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242198 Share on other sites More sharing options...
trq Posted July 13, 2011 Share Posted July 13, 2011 Now, how can date be two different values at the same time? Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242199 Share on other sites More sharing options...
calle08 Posted July 13, 2011 Author Share Posted July 13, 2011 Ok so how can i fix it? Use JOIN? I want the comments from 2011-07-20 to join after the comments from 2011-07-14 just don,t know what i can use? SELECT name, date, comment FROM narvaro_all WHERE date='2011-07-14' Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242206 Share on other sites More sharing options...
gristoi Posted July 13, 2011 Share Posted July 13, 2011 your query can't be TWO dates at the same time. use between: <?php SELECT name, date, comment FROM narvaro_all WHERE date BETWEEN '2011-07-14' AND '2011-07-20' ?> Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242207 Share on other sites More sharing options...
calle08 Posted July 13, 2011 Author Share Posted July 13, 2011 Thats the problem i always get the result as the first example in picture ex1. Thats wrong i want it to look like ex2. It is a script that tell if you can come or not. To print it on a web page i need it to look like ex2 is it possible? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242233 Share on other sites More sharing options...
PFMaBiSmAd Posted July 13, 2011 Share Posted July 13, 2011 You would use OR in order to get both matching rows - WHERE date ='2011-07-14' OR date='2011-07-20' You want to match rows where date is '2011-07-14' or where date is '2011-07-20' You can also use IN() - WHERE date IN('2011-07-14','2011-07-20') Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242235 Share on other sites More sharing options...
calle08 Posted July 13, 2011 Author Share Posted July 13, 2011 That give same result as in ex1 in my picture = wrong. I must get it to look like ex2. I think its harder need somting like join or so? Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242253 Share on other sites More sharing options...
PFMaBiSmAd Posted July 13, 2011 Share Posted July 13, 2011 Perhaps if you describe exactly what you are trying to accomplish, someone can help? The query you posted to get help with and the image you posted don't suggest at all what you are trying to do, having something or nothing to do with matching dates in the data. Without a clearly defined statement of what you are trying to accomplish, it's difficult for you to accomplish anything and impossible for us to help. Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242294 Share on other sites More sharing options...
calle08 Posted July 13, 2011 Author Share Posted July 13, 2011 I need the result to list one row/name there is one field for every date in the database for user test1 there is two fields but i want to make it to one field and have both dates and comments in that one field. Get it to look like this test1 test1 2011-07-14 yes 2011-07-20 No test2 test2 2011-07-14 yes 2011-07-20 No I think i need it to be like thig for using while($kolumn = mysql_fetch_array($result)){ to make tables that works. It is hard for me to explain to SELECT name, date, commentFROM narvaro_allWHERE date BETWEEN '2011-07-14' AND '2011-07-20' If i use that question i get two fields/name i need one. Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242321 Share on other sites More sharing options...
fenway Posted July 14, 2011 Share Posted July 14, 2011 Then self-join. Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242516 Share on other sites More sharing options...
calle08 Posted July 14, 2011 Author Share Posted July 14, 2011 How to get started? I have been thinking that self-join can work. Looking at the manul but dont get it. How to get the date and comments from 2011-07-20 to join on 2011-17-14? Somone good at join can help? Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242588 Share on other sites More sharing options...
calle08 Posted July 14, 2011 Author Share Posted July 14, 2011 Ok this olmost did it. Look at pic. How do i remove the Duplicates? The highlighted lins is the ones i want. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1242775 Share on other sites More sharing options...
fenway Posted July 15, 2011 Share Posted July 15, 2011 Well, you're missing an ON clause. Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1243036 Share on other sites More sharing options...
calle08 Posted July 16, 2011 Author Share Posted July 16, 2011 can someone help me with that? Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1243469 Share on other sites More sharing options...
fenway Posted July 16, 2011 Share Posted July 16, 2011 Sure -- just tell me what's unique about each set you want to combine. Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1243476 Share on other sites More sharing options...
calle08 Posted July 16, 2011 Author Share Posted July 16, 2011 In the pic the i want only the two highlighted lins... Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1243527 Share on other sites More sharing options...
fenway Posted July 17, 2011 Share Posted July 17, 2011 How do you know that? Quote Link to comment https://forums.phpfreaks.com/topic/241892-how-can-i-do-this/#findComment-1243837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.