odisey Posted November 20, 2007 Share Posted November 20, 2007 Hello, I know I can select from several columns and using an array separate the columns into rows effected row[0] row[1] etc... Is it possable to parse one column named dates and create three links based on the range of dates in the db. For example, if dates has 20 records (10 = 2005, 5 = 2006, 5 = 2007), can I order the results in a decending order and create only the three links based on output, and garbage the rest. 2007 2006 2005 So the first is automatically a link 2007 = Link The second: if (second) <!= (first) second = link 2006 = link ] else [ move on The third: if (third) <!= (second) third = link 2005 = link ] else [ na da... Is something link this possable? Marc Quote Link to comment https://forums.phpfreaks.com/topic/78146-solved-not-the-row0-order/ Share on other sites More sharing options...
fenway Posted November 20, 2007 Share Posted November 20, 2007 Where's the mysql part of the question? Quote Link to comment https://forums.phpfreaks.com/topic/78146-solved-not-the-row0-order/#findComment-395464 Share on other sites More sharing options...
odisey Posted November 20, 2007 Author Share Posted November 20, 2007 Using mysql_fetch_array() or the $num function, or something I am not thinking of, it is possable to sort the results of a query on one table - as mentioned above in the example ' dates, ' and create three links ? Marc Quote Link to comment https://forums.phpfreaks.com/topic/78146-solved-not-the-row0-order/#findComment-395517 Share on other sites More sharing options...
odisey Posted November 21, 2007 Author Share Posted November 21, 2007 OK - maybe this makes more sence. If I SELECT * FROM $year WHERE studend_id = $s_id And ORDER DESC in an array() When I print the output can I write a conditional which prints multiple years only 1 time and creates a link. For example, something like: $value // this is the array() variable loaded with data $year = $ value; echo $year // this is the first link I will code here FOREACH ($year >!= $value) { echo $ year } else { echo All years are printed } Quote Link to comment https://forums.phpfreaks.com/topic/78146-solved-not-the-row0-order/#findComment-395614 Share on other sites More sharing options...
BenInBlack Posted November 21, 2007 Share Posted November 21, 2007 why don't you just use distinct in the select statement SELECT DISTINCT year FROM Students WHERE studend_id = $s_id so if the student records span years you will get a nice list in the results year ----- 2005 2006 2007 now if you want the year and number of record for that year you could do this SELECT year,count(year) as 'year_count' FROM Students WHERE studend_id = $s_id GROUP BY year then you will get year year_count ----- ------------ 2005 10 2006 5 2007 5 Quote Link to comment https://forums.phpfreaks.com/topic/78146-solved-not-the-row0-order/#findComment-395722 Share on other sites More sharing options...
odisey Posted November 24, 2007 Author Share Posted November 24, 2007 You guys are genius.... This is why I come here... Absolutely brilliant. I know php has these functions, short cuts, etc... I have no formal training .. I am learning... Trying to write WHILE, FOR, IF statements to accomplish this for three days.... and all I had to do was add the word DISTINCT to the query... GO figure,,, So you added a count function to the example.... this is good.,,,,,,, I can use that. Is it possable to add one more feature..... (Maybe I can actually figure this one out) A feature that lists the DISTINCT years and terms as well. There is a possibility of the followinf output ------------------------------------------- year term 2006 M = Midterm 2006 F = Final 2007 M ------------------------------------------- The 2007 F (Final) data did not print because the query did not find a record in the year 2007 for the student associated with the 'final' evaluation; only the midterm was recorded at the time of the query. Marc Quote Link to comment https://forums.phpfreaks.com/topic/78146-solved-not-the-row0-order/#findComment-398069 Share on other sites More sharing options...
odisey Posted November 24, 2007 Author Share Posted November 24, 2007 I got it! Thanks to you help. $query = "SELECT DISTINCT year as year, mid_final AS mf FROM student_score WHERE student_id = $s_id ORDER BY year ASC"; Thank you again, Marc Quote Link to comment https://forums.phpfreaks.com/topic/78146-solved-not-the-row0-order/#findComment-398081 Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Trying to write WHILE, FOR, IF statements to accomplish this for three days.... hehe We have all been there before, trust me. = ) You know what, though? You learned a few things trying all those wild hair-brained loops! I think I speak for all the people who provide help when I say that we respect someone who has tried everything, and then thrown in some voodoo as well... if you retain that perseverance, you will be a good coder some day. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/78146-solved-not-the-row0-order/#findComment-398085 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.