Jump to content

[SOLVED] Not the row[0] order ...


odisey

Recommended Posts

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

         

 

         

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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  } 

 

 

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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 

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.