Re: [PHP-DB] PHP sort from .... best solution?
Hi again! Is it possibile to only show articles from a sertain month. say I want to show all articles from June 2003 (2003 01/06 - 2003 31/06)... the variable here is publisert It should be enough info over to help me :) Regards, A. Lyse A. Lyse [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi! Thanks! But I got a problem with the code: The PHP file as it is with the code pasted into it will i'll past at the end of this post. The problem is I get the error: Warning: Invalid argument supplied for foreach() in /home/amotor/www/list_ingresser_artikler.php on line 43 If I put a // in front of line 32 the script feeds correct, but not sorted. I think there is a very easy solution to this, but I dont know so mutch PHP :( I'm reading though. Thanx alot for the help I got so far. I've learned alot! Regards, A. Lyse The PHP file ?php //Dette er en mal for å lette implementering av pusyset til de enkelte sider. //Denne malen viser ingressene til de 50 siste artikler denne siden skal ha. include ../lib/ingress.lib; $nettstedid=11; //Id til nettstedet. Dersom man ikke husker sin nettstedid finnes den i admindelen av pubsyset. $sprakid=1; //Språkid. 1=Norsk $offset=0; //Offset, dersom man ikke skal vise fra artikkel 0, men f.eks. fra artikkel 51. $offset3ingr=2; //Offset, dersom man ikke skal vise fra artikkel 0, men f.eks. fra artikkel 51. $offsetannet=1; //Offset, dersom man ikke skal vise fra artikkel 0, men f.eks. fra artikkel 51. $antall=50; //Hvor mange artikler skal vises $antallmotor=25; //Hvor mange artikler skal vises på motorsport $antallmotor3ingresser=3; //Hvor mange artikler skal vises videre på motorsport $antallmc=1; //Hvor mange artikler skal vises på MC $antallmc3ingresser=3; //Hvor mange artikler skal vises videre på MC $antallstyling=1; //Hvor mange artikler skal vises på MC $antallstyling3ingresser=3; //Hvor mange artikler skal vises videre på MC $typeid=0; //Hva slags ingresser skal vises? 0 viser alle typer. $i1 = hentIngresser($nettstedid,38,$sprakid,$offset,$antallmotor); $i2 = hentIngresser($nettstedid,39,$sprakid,$offset,$antallmotor); function obj_date_compare($a, $b) { return strcmp($a-publisertLang, $b-publisertLang); } if($ingresser = array_merge($i1 ,$i2)) { $ingresser = usort($ingresser, 'obj_date_compare'); listIngresser($ingresser); } else echo 'Det oppstod en feil ved henting av ingresser.'; function listIngresser($ingresser){ foreach($ingresser as $i){ echo ' tr td width=100% align=left bgcolor=#ebe8e4 a href='.$i-artikkellink.' img class=lesmer src=/bilder/design/lesmer.gif width=61 height=19 align=right b a class=forsidelinker href='.$i-artikkellink.''.$i-overskrift.'/a /b nbsp;nbsp;b class=dato('.$i-publisert.')/b /tr /td tr td height=121 class=ingresshoved a href='.$i-artikkellink.'img class=bilde src=' . $i-bilde . ' width=100 height=85 border=1 align=right/a /font'.$i-ingress.' tr td align=left width=100% bgcolor=#f4f4f4 p /p /td ' ; } } ? ** END PHP file *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP sort from .... best solution?
Hi! Thanks! But I got a problem with the code: The PHP file as it is with the code pasted into it will i'll past at the end of this post. The problem is I get the error: Warning: Invalid argument supplied for foreach() in /home/amotor/www/list_ingresser_artikler.php on line 43 If I put a // in front of line 32 the script feeds correct, but not sorted. I think there is a very easy solution to this, but I dont know so mutch PHP :( I'm reading though. Thanx alot for the help I got so far. I've learned alot! Regards, A. Lyse The PHP file ?php //Dette er en mal for å lette implementering av pusyset til de enkelte sider. //Denne malen viser ingressene til de 50 siste artikler denne siden skal ha. include ../lib/ingress.lib; $nettstedid=11; //Id til nettstedet. Dersom man ikke husker sin nettstedid finnes den i admindelen av pubsyset. $sprakid=1; //Språkid. 1=Norsk $offset=0; //Offset, dersom man ikke skal vise fra artikkel 0, men f.eks. fra artikkel 51. $offset3ingr=2; //Offset, dersom man ikke skal vise fra artikkel 0, men f.eks. fra artikkel 51. $offsetannet=1; //Offset, dersom man ikke skal vise fra artikkel 0, men f.eks. fra artikkel 51. $antall=50; //Hvor mange artikler skal vises $antallmotor=25; //Hvor mange artikler skal vises på motorsport $antallmotor3ingresser=3; //Hvor mange artikler skal vises videre på motorsport $antallmc=1; //Hvor mange artikler skal vises på MC $antallmc3ingresser=3; //Hvor mange artikler skal vises videre på MC $antallstyling=1; //Hvor mange artikler skal vises på MC $antallstyling3ingresser=3; //Hvor mange artikler skal vises videre på MC $typeid=0; //Hva slags ingresser skal vises? 0 viser alle typer. $i1 = hentIngresser($nettstedid,38,$sprakid,$offset,$antallmotor); $i2 = hentIngresser($nettstedid,39,$sprakid,$offset,$antallmotor); function obj_date_compare($a, $b) { return strcmp($a-publisertLang, $b-publisertLang); } if($ingresser = array_merge($i1 ,$i2)) { $ingresser = usort($ingresser, 'obj_date_compare'); listIngresser($ingresser); } else echo 'Det oppstod en feil ved henting av ingresser.'; function listIngresser($ingresser){ foreach($ingresser as $i){ echo ' tr td width=100% align=left bgcolor=#ebe8e4 a href='.$i-artikkellink.' img class=lesmer src=/bilder/design/lesmer.gif width=61 height=19 align=right b a class=forsidelinker href='.$i-artikkellink.''.$i-overskrift.'/a /b nbsp;nbsp;b class=dato('.$i-publisert.')/b /tr /td tr td height=121 class=ingresshoved a href='.$i-artikkellink.'img class=bilde src=' . $i-bilde . ' width=100 height=85 border=1 align=right/a /font'.$i-ingress.' tr td align=left width=100% bgcolor=#f4f4f4 p /p /td ' ; } } ? ** END PHP file *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP sort from .... best solution?
hi the easier way is as Mike Ford did it very elegantly with this structur: function obj_date_compare($a, $b) { return strcmp($a-publisertLang, $b-publisertLang); } ... if($ingresser = array_merge($i1 ,$i2)) { $ingresser = usort($ingresser, 'obj_date_compare'); listIngresser($ingresser); } the for-structure from your admin guy is also a possibility, but i think php offers cool sort-functions like this usort-function (which was also new to me - [EMAIL PROTECTED]). so it is not necessary to write your own sorting-algorithm. .ma A. Lyse [EMAIL PROTECTED] [EMAIL PROTECTED] 13:40 Uhr: Hi again! I talked to the admin guy and he said there is an easyer way to do this (as usual he doenst have the time to show me) so I try here: He gave me a liddle example in c and a light translation to PHP: Bubble sort (exampel written in c, but can easyly be translated to php): for (i=0; in-1; i++) { for (j=0; jn-1-i; j++) if (a[j+1] a[j]) { /* compare the two neighbors */ tmp = a[j]; /* swap a[j] and a[j+1] */ a[j] = a[j+1]; a[j+1] = tmp; } } ** More example of Bubble Sort: http://www.cs.ust.hk/faculty/tcpong/cs102/summer96/aids/bubble.html The if-sentense must here be written to if($a[$j+1]-publisertLang $a[$j]-publisertLang) where a is $ingresser and $n is the number of elements in $ingresser. I The if sentese is going in the php file pastet yesterday. Not that yeasterdays metod did'nt work, but if somebody has an idea on this one and can give me a full example based on the info i've pastet yesterday it would be great! Regards, A. Lyse -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP sort from .... best solution?
no prob i think its not the best solution, because its a workaround the core-problem. as i said it would be better to access the data directly and without any functions or complicated classes. this structure is for very complex systems whose code may change very often. so the highest standard of scaleability is needed and the code must be very modular. in this case (its only a news-module) you do not need such a professional and therefore complicated structure. it is enough to formulate a simple query and give the news out with a while-loop. maybe this is only my personal opinion. i do not want to critisize your code - but adding this workaround crushes the whole modularity because it is very specialized on your environement. may be this produces headache if you want to update your code later on? (this is something that happens to me all the time with code which is veeery old comeing from times where i didn't thought of the future :) well - it works - what more? .ma A. Lyse [EMAIL PROTECTED] [EMAIL PROTECTED] 1:16 Uhr: It worked. Thanx! Why is this a bad solution? Will it slow down the feed? Regards, A. Lyse -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP sort from .... best solution?
Hi again! I talked to the admin guy and he said there is an easyer way to do this (as usual he doenst have the time to show me) so I try here: He gave me a liddle example in c and a light translation to PHP: Bubble sort (exampel written in c, but can easyly be translated to php): for (i=0; in-1; i++) { for (j=0; jn-1-i; j++) if (a[j+1] a[j]) { /* compare the two neighbors */ tmp = a[j]; /* swap a[j] and a[j+1] */ a[j] = a[j+1]; a[j+1] = tmp; } } ** More example of Bubble Sort: http://www.cs.ust.hk/faculty/tcpong/cs102/summer96/aids/bubble.html The if-sentense must here be written to if($a[$j+1]-publisertLang $a[$j]-publisertLang) where a is $ingresser and $n is the number of elements in $ingresser. I The if sentese is going in the php file pastet yesterday. Not that yeasterdays metod did'nt work, but if somebody has an idea on this one and can give me a full example based on the info i've pastet yesterday it would be great! Regards, A. Lyse -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php