mike27 Geschrieben 20. Juli 2003 Geschrieben 20. Juli 2003 Ich habe folgendes Problem: In einer MYSQL Datenbank stehen folgende Daten: Vorname,Name,Geburtstag,Geburtsmonat und Geburtsjahr nun möchte ich bei der Ausgabe anhand des Geburtsjahres das Chinesische Sternzeichen mit ausgeben. Dachte da an eine Switch/Case Lösung und wollte es so umsetzen: Hier ein Script auszug: $i=0; $felder=mysql_num_fields($ergebnis); echo "<tr>\n"; while ($i < $felder) { $name = mysql_field_name($ergebnis,$i); echo "\t<th background=\"grafiken/bgright.gif\" bgcolor=white>$name</th>"; $i++; } echo "\t<th background=\"grafiken/bgright.gif\" bgcolor=white>Sternzeichen</th>"; while ($treffer = mysql_fetch_row($ergebnis)) { echo "<tr>\t"; foreach ($treffer as $feld) if ($feld !="") { echo "\t<td bgcolor=\"#F7F9FD\">$feld</td>\n"; switch ($feld) { case "1971": $china_text="Schwein"; break; case "Ratte": $china_text="Schwein"; break; } } else echo "\t<td bgcolor=\"#F7F9FD\">$china_text</td>\n"; echo "</tr>\n"; } echo "</table>\n<br></center>"; Tja es werden alle Daten angezeigt aber nur nicht das Chinbesische Sternzeichen. Dieses Feld bleibt leider leer. Ist meine Lösung so überhaupt nicht umsetzbar ? gruß Mike Zitieren
Art Geschrieben 20. Juli 2003 Geschrieben 20. Juli 2003 ich würde ja die sternzeichen in eine extra tabelle packen und die zugehörigkeit, dann bei der eingabe berechnen. hab hier was gefunden, mußt du vielleicht nur nach php ummodeln <html> <head> <title>Chinesische Sternzeichen</title> <style type="text/css"><!-- BODY { scrollbar-base-color:darkblue; scrollbar-track-color:#000000; scrollbar-face-color:darkblue; scrollbar-highlight-color:darkblue; scrollbar-3d-light-color:darkblue; scrollbar-dark-shadow-color:darkblue; scrollbar-shadow-color:darkblue; scrollbar-arrow-color:#00a854; } --></style> <META NAME="Keywords" CONTENT="Sternzeichen,Chinesisch,Rechner,Mythologie,Lexikon,ANDALANANGA,Rossa,Alexander"> <script language="JavaScript"> <!-- if( top.location.href==self.location) top.location.href="http://feen.info"; //--> </script> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function signs() { var start = 1901, birthyear = document.kal.year.value, date=document.kal.date.value, month=document.kal.month.selectedIndex; with (document.kal.sign){ if (month == 1 && date >=20 || month == 2 && date <=18) {value = "Wassermann";} if (month == 1 && date > 31) {value = "Huh?";} if (month == 2 && date >=19 || month == 3 && date <=20) {value = "Fische";} if (month == 2 && date > 29) {value = "Say what?";} if (month == 3 && date >=21 || month == 4 && date <=19) {value = "Widder";} if (month == 3 && date > 31) {value = "OK. Whatever.";} if (month == 4 && date >=20 || month == 5 && date <=20) {value = "Stier";} if (month == 4 && date > 30) {value = "I'm soooo sorry!";} if (month == 5 && date >=21 || month == 6 && date <=21) {value = "Zwillinge";} if (month == 5 && date > 31) {value = "Umm ... no.";} if (month == 6 && date >=22 || month == 7 && date <=22) {value = "Krebs";} if (month == 6 && date > 30) {value = "Sorry.";} if (month == 7 && date >=23 || month == 8 && date <=22) {value = "Löwe";} if (month == 7 && date > 31) {value = "Excuse me?";} if (month == 8 && date >=23 || month == 9 && date <=22) {value = "Jungfrau";} if (month == 8 && date > 31) {value = "Yeah. Right.";} if (month == 9 && date >=23 || month == 10 && date <=22) {value = "Waage";} if (month == 9 && date > 30) {value = "Try Again.";} if (month == 10 && date >=23 || month == 11 && date <=21) {value = "Skorpion";} if (month == 10 && date > 31) {value = "Forget it!";} if (month == 11 && date >=22 || month == 12 && date <=21) {value = "Schütze";} if (month == 11 && date > 30) {value = "Invalid Date";} if (month == 12 && date >=22 || month == 1 && date <=19) {value = "Steinbock";} if (month == 12 && date > 31) {value = "No way!";} } x = (start - birthyear) % 12 with (document.kal.csign){ if (x == 1 || x == -11) {value = "Ratte";} if (x == 0) {value = "Ox";} if (x == 11 || x == -1) {value = "Tieger";} if (x == 10 || x == -2) {value = "Hase/Katz";} if (x == 9 || x == -3) {value = "Drache";} if (x == 8 || x == -4) {value ="Schlange";} if (x == 7 || x == -5) {value = "Pferd";} if (x == 6 || x == -6) {value = "Schaf";} if (x == 5 || x == -7) {value = "Affe";} if (x == 4 || x == -8) {value = "Hahn/Phoenix";} if (x == 3 || x == -9) {value = "Hund";} if (x == 2 || x == -10) {value = "Bär";} } } // End --> </script> </head> <body background="" bgcolor="#000000" link="darkorange" vlink="darkorange" alink="darkorange"> <div align="center"><img src="Irrlichter-Dateien/redbar.gif" Alt="Blut und Schmach"></div> <br> <Font Color="black">........</Font><Font face="arial,helvetica" color="#b7b7ff" size="7"> I<Font color="red" face="arial,helvetica" size="5">hre chinesisches Sternzeichen...</Font></div> <br> <center> <table border="1" bgcolor="darkgreen" width="430" cellpadding="20"> <tr> <td> <div style="margin-left:3mm; margin-right:3mm;" align="justify"> <form name="kal"> <center><br><font face="arial,helvetica" size="1">Bitte geben Sie Ihren Geburtstag ein. (Daten werden nicht gespeichert!)</font><br> <table bgcolor="#b7b7ff" border="2" bordercolor="#000000" rules="none" cellspacing="0" cellpadding="6"> <tr><td><font face="arial,helvetica" size="3"><b><i>Jahr</i></b></font></td> <td><div align="right"><input type="text" size="10" name="year" value="Geburtsjahr" onClick=value=""></div></td> <td></td> <tr><td><font face="arial,helvetica" size="3"><b><i>Monat</i></b></font></td> <td><div align="right"> <select name="month"> <option value="x">Wähle Geburtsmonat</option> <option value="1">Januar</option><option value="2">Februar</option><option value="3">März</option> <option value="4">April</option><option value="5">Mai</option><option value="6">Juni</option> <option value="7">Juli</option><option value="8">August</option><option value="9">September</option> <option value="10">Oktober</option><option value="11">November</option> <option value="12">Dezember</option></select></div></td> <td></td></tr> <tr><td><font face="arial,helvetica" size="3"><b><i>Tag</i></b></font></td> <td><div align="right"><input type="text" name="date" value="Tag" size="3" onClick=value=""></td> <td><input type="button" value="Berechne" onClick="signs()"></div></td></tr> <tr><td><font face="arial,helvetica" size="3"><b><i>Sternzeichen:</i></b></font></td> <td><div align="right"><input type="text" name="sign" size="12" value="" align="right"></div</td></tr> <td></td></tr> <tr><td><font face="arial,helvetica" size="3"><b><i>Chinesisches Zeichen:</i></b></font></td> <td><div align="right"><input type="text" name="csign" size="12"></div></td> <td></td></tr> </table> </center> </form> <br></div> </td> </tr> </Font> </table> </center> <div align="center"><img src="Irrlichter-Dateien/redbar.gif" Alt="Blut und Schmach"></div> <br> </body> </html> [/php] Zitieren
jomama Geschrieben 21. Juli 2003 Geschrieben 21. Juli 2003 Das mit der extra Tabelle, wo die Sternzeichen dristehen find ich gut. Ginge dann ganz leicht mit ner Select-Abfrage, so etwa: SELECT Sternzeichen FROM Tabelle WHERE Jahr=$variable Dann sparst du dir den switch case. Zitieren
mike27 Geschrieben 21. Juli 2003 Autor Geschrieben 21. Juli 2003 Tja leider gibts da doch noch ein problem . Die Berechnungen stimmen nicht so ganz. Das chinesische Jahr faengt spaeter als unseres an. So ist jemand wo vor dem 15.02.1972 geboren wurde noch eine Ratte ab dem 03.02.1973 ein Bueffel. Der Jahresbeginn ist alle Jahre unterschiedlich so gilt das Pferd nur noch bis zum 02.02.2003, also weniger als ein Jahr. Gibt es irgendwo im Netz eine Formel für diese Berechnung bisher konnte ich da nichts finden... Und danke für die Lösungsvorschläge... Zitieren
mike27 Geschrieben 21. Juli 2003 Autor Geschrieben 21. Juli 2003 Habe nun doch etwas gefunden für die Berechnung, falls es jemanden intressiert hier die Formel in PHP: $cdate_monthdata=array( 0=>array(8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1), 1=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2), 2=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3), 3=>array(5,29,30,29,30,29,29,30,29,29,30,30,29,30,10,4), 4=>array(0,30,30,29,30,29,29,30,29,29,30,30,29,0,1,5), 5=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,2,6), 6=>array(4,29,30,30,29,30,29,30,29,30,29,30,29,30,3,7), 7=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,4,8), 8=>array(0,30,29,29,30,30,29,30,29,30,30,29,30,0,5,9), 9=>array(2,29,30,29,29,30,29,30,29,30,30,30,29,30,6,10), 10=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,7,11), 11=>array(6,30,29,30,29,29,30,29,29,30,30,29,30,30,8,12), 12=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,9,1), 13=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,10,2), 14=>array(5,30,30,29,30,29,30,29,30,29,30,29,29,30,1,3), 15=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,2,4), 16=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,3,5), 17=>array(2,30,29,29,30,29,30,30,29,30,30,29,30,29,4,6), 18=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,5,7), 19=>array(7,29,30,29,29,30,29,29,30,30,29,30,30,30,6,8), 20=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,7,9), 21=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,8,10), 22=>array(5,30,29,30,30,29,29,30,29,29,30,29,30,30,9,11), 23=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,10,12), 24=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,1,1), 25=>array(4,30,29,30,29,30,30,29,30,30,29,30,29,30,2,2), 26=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,3,3), 27=>array(0,30,29,29,30,29,30,29,30,29,30,30,30,0,4,4), 28=>array(2,29,30,29,29,30,29,29,30,29,30,30,30,30,5,5), 29=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,6,6), 30=>array(6,29,30,30,29,29,30,29,29,30,29,30,30,29,7,7), 31=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,8,8), 32=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,9,9), 33=>array(5,29,30,30,29,30,30,29,30,29,30,29,29,30,10,10), 34=>array(0,29,30,29,30,30,29,30,29,30,30,29,30,0,1,11), 35=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,2,12), 36=>array(3,30,29,29,30,29,29,30,30,29,30,30,30,29,3,1), 37=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,4,2), 38=>array(7,30,30,29,29,30,29,29,30,29,30,30,29,30,5,3), 39=>array(0,30,30,29,29,30,29,29,30,29,30,29,30,0,6,4), 40=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,7,5), 41=>array(6,30,30,29,30,30,29,30,29,29,30,29,30,29,8,6), 42=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,9,7), 43=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,10,8), 44=>array(4,30,29,30,29,30,29,30,29,30,30,29,30,30,1,9), 45=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,2,10), 46=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,3,11), 47=>array(2,30,30,29,29,30,29,29,30,29,30,29,30,30,4,12), 48=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,5,1), 49=>array(7,30,29,30,30,29,30,29,29,30,29,30,29,30,6,2), 50=>array(0,29,30,30,29,30,30,29,29,30,29,30,29,0,7,3), 51=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,8,4), 52=>array(5,29,30,29,30,29,30,29,30,30,29,30,29,30,9,5), 53=>array(0,29,30,29,29,30,30,29,30,30,29,30,29,0,10,6), 54=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,1,7), 55=>array(3,29,30,29,30,29,29,30,29,30,29,30,30,30,2,8), 56=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,3,9), 57=>array(8,30,29,30,29,30,29,29,30,29,30,29,30,29,4,10), 58=>array(0,30,30,30,29,30,29,29,30,29,30,29,30,0,5,11), 59=>array(0,29,30,30,29,30,29,30,29,30,29,30,29,0,6,12), 60=>array(6,30,29,30,29,30,30,29,30,29,30,29,30,29,7,1), 61=>array(0,30,29,30,29,30,29,30,30,29,30,29,30,0,8,2), 62=>array(0,29,30,29,29,30,29,30,30,29,30,30,29,0,9,3), 63=>array(4,30,29,30,29,29,30,29,30,29,30,30,30,29,10,4), 64=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,1,5), 65=>array(0,29,30,29,30,29,29,30,29,29,30,30,29,0,2,6), 66=>array(3,30,30,30,29,30,29,29,30,29,29,30,30,29,3,7), 67=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,4,8), 68=>array(7,29,30,29,30,30,29,30,29,30,29,30,29,30,5,9), 69=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,6,10), 70=>array(0,30,29,29,30,29,30,30,29,30,30,29,30,0,7,11), 71=>array(5,29,30,29,29,30,29,30,29,30,30,30,29,30,8,12), 72=>array(0,29,30,29,29,30,29,30,29,30,30,29,30,0,9,1), 73=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,10,2), 74=>array(4,30,30,29,30,29,29,30,29,29,30,30,29,30,1,3), 75=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,2,4), 76=>array(8,30,30,29,30,29,30,29,30,29,29,30,29,30,3,5), 77=>array(0,30,29,30,30,29,30,29,30,29,30,29,29,0,4,6), 78=>array(0,30,29,30,30,29,30,30,29,30,29,30,29,0,5,7), 79=>array(6,30,29,29,30,29,30,30,29,30,30,29,30,29,6,8), 80=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,7,9), 81=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,8,10), 82=>array(4,30,29,30,29,29,30,29,29,30,29,30,30,30,9,11), 83=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,10,12), 84=>array(10,30,29,30,30,29,29,30,29,29,30,29,30,30,1,1), 85=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,2,2), 86=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,3,3), 87=>array(6,30,29,30,29,30,30,29,30,30,29,30,29,29,4,4), 88=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,5,5), 89=>array(0,30,29,29,30,29,29,30,30,29,30,30,30,0,6,6), 90=>array(5,29,30,29,29,30,29,29,30,29,30,30,30,30,7,7), 91=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,8,8), 92=>array(0,29,30,30,29,29,30,29,29,30,29,30,30,0,9,9), 93=>array(3,29,30,30,29,30,29,30,29,29,30,29,30,29,10,10), 94=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,1,11), 95=>array(8,29,30,30,29,30,29,30,30,29,29,30,29,30,2,12), 96=>array(0,29,30,29,30,30,29,30,29,30,30,29,29,0,3,1), 97=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,4,2), 98=>array(5,30,29,29,30,29,29,30,30,29,30,30,29,30,5,3), 99=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,6,4), 100=>array(0,30,30,29,29,30,29,29,30,29,30,30,29,0,7,5), 101=>array(4,30,30,29,30,29,30,29,29,30,29,30,29,30,8,6), 102=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,9,7), 103=>array(0,30,30,29,30,30,29,30,29,29,30,29,30,0,10,8), 104=>array(2,29,30,29,30,30,29,30,29,30,29,30,29,30,1,9), 105=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,2,10), 106=>array(7,30,29,30,29,30,29,30,29,30,30,29,30,30,3,11), 107=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,4,12), 108=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,5,1), 109=>array(5,30,30,29,29,30,29,29,30,29,30,29,30,30,6,2), 110=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,7,3), 111=>array(0,30,29,30,30,29,30,29,29,30,29,30,29,0,8,4), 112=>array(4,30,29,30,30,29,30,29,30,29,30,29,30,29,9,5), 113=>array(0,30,29,30,29,30,30,29,30,29,30,29,30,0,10,6), 114=>array(9,29,30,29,30,29,30,29,30,30,29,30,29,30,1,7), 115=>array(0,29,30,29,29,30,29,30,30,30,29,30,29,0,2,8), 116=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,3,9), 117=>array(6,29,30,29,30,29,29,30,29,30,29,30,30,30,4,10), 118=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,5,11), 119=>array(0,30,29,30,29,30,29,29,30,29,29,30,30,0,6,12), 120=>array(4,29,30,30,30,29,30,29,29,30,29,30,29,30,7,1) ); $cdate_zodiacarray=array("null","Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Sheep","Monkey","Rooster","Dog","Pig"); $cdate_zodicdescrptionarray[1] = "Ratte"; $cdate_zodicdescrptionarray[2] = "Bueffel"; $cdate_zodicdescrptionarray[3] = "Tiger"; $cdate_zodicdescrptionarray[4] = "Hase"; $cdate_zodicdescrptionarray[5] = "Drache"; $cdate_zodicdescrptionarray[6] = "Schlange"; $cdate_zodicdescrptionarray[7] = "Pferd"; $cdate_zodicdescrptionarray[8] = "Schaf"; $cdate_zodicdescrptionarray[9] = "Affe"; $cdate_zodicdescrptionarray[10] = "Hahn"; $cdate_zodicdescrptionarray[11] = "Hund"; $cdate_zodicdescrptionarray[12] = "Schwein"; $cdate_total=11; $cdate_cntotal=0; for ($y=1901;$y<$year;$y++){ $cdate_total+=365; if ($y%4==0) $cdate_total ++; } switch ($month){ case 12: $cdate_total+=30; case 11: $cdate_total+=31; case 10: $cdate_total+=30; case 9: $cdate_total+=31; case 8: $cdate_total+=31; case 7: $cdate_total+=30; case 6: $cdate_total+=31; case 5: $cdate_total+=30; case 4: $cdate_total+=31; case 3: $cdate_total+=28; case 2: $cdate_total+=31; } if ($year%4==0 and $month>2){ $cdate_total++; } $cdate_total = $cdate_total+($day-1); $myeardiff = $year-1900; for ($x=0;$x<=$myeardiff;$x++){ for ($y=1;$y<=13;$y++){ if ($cdate_cntotal<$cdate_total){ $cdate_cntotal+=$cdate_monthdata[$x][$y]; $cdate_cnyear = $x; $cdate_cnmonth = $y; } } } $cdate_zodiacnumber = $cdate_monthdata[$cdate_cnyear][15]; $cdate_zodiac = $cdate_zodiacarray[$cdate_zodiacnumber]; $cdate_zodicdescrption = $cdate_zodicdescrptionarray[$cdate_zodiacnumber]; Zitieren
Empfohlene Beiträge
Dein Kommentar
Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.