[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

ORDER BY doesn't work in RIGHT JOIN

Asked by lericson in PHP and Databases, MySQL Server

Tags: mysql

I'd like to sort the database outcome by "matrikel.MedlemsNr". It sorts instead by "Efternamn".
Anyone who can tell me how to get it right?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
<html>
<head>
<meta http-equiv="Content-Language" content="sv">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><? echo $batklubbens_namn; ?></title>
<style type="text/css">
.style36 {
	font-family: Verdana;
	color: #800000;
	font-size: 12pt;
}
 
.style37 {
	background-color: #f7c6c6;
}
a:link.vaktvisning36   {
	font-family: Verdana;
	color: #800000;
	font-size: 12pt;
	font-weight: bold;
	border-bottom: 1px #800000;
}
a:active.vaktvisning36   {
	font-family: Verdana;
	color: #800000;
	font-size: 12pt;
	font-weight: bold;
	border-bottom: 1px #800000;
}
a:visited.vaktvisning36   {
	font-family: Verdana;
	color: #800000;
	font-size: 12pt;
	font-weight: bold;
	border-bottom: 1px #800000;
}
a:hover.vaktvisning36   {
	font-family: Verdana;
	color: #808080;
	font-size: 12pt;
	font-weight: bold;
	border-bottom: 1px #808080;
}
.vaktvisning  {
  border-top: 1px solid #FFFFFF;
  border-bottom: 1px solid #FFFFFF;
  border-left: 1px solid #FFFFFF;
  border-right: 1px solid #FFFFFF;
 
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: x-small;
  font-style: normal;
  font-variant: normal;
  font-weight: bold;
  color: black;
}
.fetrubrik {
	font-family: Verdana;
	color: #000000;
	font-size: 14pt;
	font-weight: bold;
}
.vaktvisning36   {
	font-family: Verdana;
	color: #800000;
	font-size: 10pt;
	font-weight: bold;
	border-bottom: 1px #800000;
}
td   {
	font-family: Verdana;
	color: #000000;
	font-size: 10pt;
}
input {
	font-family: Verdana;
	color: #000000;
	font-size: 9pt;
	border: 1 solid #FFFFFF;
	background-color: #f7c6c6;
}
</style>
</head>
<body bgcolor="White">
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
include "../../dbconfig/dbconfig.php";
echo "<table width=\"1100\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\">
  <tr>
    <td colspan=\"18\" align=\"center\" class=\"fetrubrik\">Vaktdagar i både $varv_1_namn och $varv_2_namn bokade av medlemmar</td>
  </tr>
  <tr>
    <td align=\"center\">&nbsp;</td>
    <td>&nbsp;</td>
    <td align=\"center\">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align=\"center\">&nbsp;</td>
    <td>&nbsp;</td>
    <td align=\"center\">&nbsp;</td>
    <td>&nbsp;</td>
    <td align=\"center\">&nbsp;</td>
    <td>&nbsp;</td>
    <td align=\"center\">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class=\"vaktvisning36\" align=\"center\">Nr</td>
    <td>&nbsp;</td>
    <td class=\"vaktvisning36\"  align=\"center\">Medlemsnr</td>
    <td>&nbsp;</td>
    <td width=\"100\" class=\"vaktvisning36\" >F&ouml;rnamn</td>
    <td>&nbsp;</td>
    <td width=\"100\" class=\"vaktvisning36\" >Efternamn</td>
    <td>&nbsp;</td>
    <td width=\"50\" class=\"vaktvisning36\" >Skall gå</td>
    <td>&nbsp;</td>
    <td width=\"125\" class=\"vaktvisning36\"  align=\"center\">1:a dagen</td>
    <td>&nbsp;</td>
    <td width=\"125\" class=\"vaktvisning36\"  align=\"center\">2:a dagen</td>
    <td>&nbsp;</td>
    <td width=\"125\" class=\"vaktvisning36\"  align=\"center\">3:e dagen</td>
    <td>&nbsp;</td>
    <td width=\"125\" class=\"vaktvisning36\"  align=\"center\">4:e dagen</td>
    <td>&nbsp;</td>
    <td width=\"30\" class=\"vaktvisning36\" >Antal dagar bokade</td>
    <td>&nbsp;</td>
    <td width=\"90\" class=\"vaktvisning36\" >Att boka ytterligare</td>
    <td>&nbsp;</td>
 
  </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>";
if(file_exists("../../../dbconfig/dbconfig.php")) include "../../../dbconfig/dbconfig.php" ;
if(file_exists("../../dbconfig/dbconfig.php")) include "../../dbconfig/dbconfig.php" ;
if(file_exists("../dbconfig/dbconfig.php")) include "../dbconfig/dbconfig.php" ;
if(file_exists("dbconfig/dbconfig.php")) include "dbconfig/dbconfig.php" ;
@mysql_connect($host,$usr,$pwd)
or die("<p>Kan inte ansluta till databasservern.</p>");
  // Välj den databas PHP-skriptet ska arbeta med:
@mysql_select_db($db)
    or die("<p>Kan inte ansluta till databasen " . $db . ".</p>");
$SQL = " SELECT * FROM medlem RIGHT JOIN matrikel ON(matrikel.MedlemsNr = medlem.medlemsnr) ORDER BY 'matrikel.MedlemsNr' ASC";
$ret = mysql_db_query($db, $SQL, $cid);
if (!$ret) { echo( mysql_error()); }
else {
while ($row = mysql_fetch_array($ret)) {
        $id  = $row["id"];
        $fornamn = $row['Förnamn'];
        $efternamn = $row['Efternamn'];
        $medlemsnr = $row['MedlemsNr'];
        $medlemmstyp = $row['Medlemstyp'];
        $dag_bev1 = $row['dag_bev1'];
        $dag_bev2 = $row['dag_bev2'];
        $dag_bev3 = $row['dag_bev3'];
        $dag_bev4 = $row['dag_bev4'];
        $varv1 = $row['varv1'];
        $varv2 = $row['varv2'];
        $varv3 = $row['varv3'];
        $varv4 = $row['varv4'];
		$Bryggplats1 = $row['Bryggplats1'];
		$Vinterplats1 = $row['Vinterplats1'];
		$Bryggplats2 = $row['Bryggplats2'];
		$Vinterplats2 = $row['Vinterplats2'];
 
if($dag_bev1 && $varv1 == "$varv_1_namn") {  $dag_bev1 = "$dag_bev1<span style=\"color:#800000\"><strong>(H)</strong></span>"; }
if($dag_bev1 && $varv1 == "$varv_2_namn") {  $dag_bev1 = "$dag_bev1<span style=\"color:#008000\"><strong>(K)</strong></span>"; }
if($dag_bev2 && $varv2 == "$varv_1_namn") {  $dag_bev2 = "$dag_bev2<span style=\"color:#800000\"><strong>(H)</strong></span>"; }
if($dag_bev2 && $varv2 == "$varv_2_namn") {  $dag_bev2 = "$dag_bev2<span style=\"color:#008000\"><strong>(K)</strong></span>"; }
if($dag_bev3 && $varv3 == "$varv_1_namn") {  $dag_bev3 = "$dag_bev3<span style=\"color:#800000\"><strong>(H)</strong></span>"; }
if($dag_bev3 && $varv3 == "$varv_2_namn") {  $dag_bev3 = "$dag_bev3<span style=\"color:#008000\"><strong>(K)</strong></span>"; }
if($dag_bev4 && $varv4 == "$varv_1_namn") {  $dag_bev4 = "$dag_bev4<span style=\"color:#800000\"><strong>(H)</strong></span>"; }
if($dag_bev4 && $varv4 == "$varv_2_namn") {  $dag_bev4 = "$dag_bev4<span style=\"color:#008000\"><strong>(K)</strong></span>"; }
        $nummer++;
		$bgcolor = ( ++$counter & 1 ) ? 'E5EDF6' : 'FFFFFF';
 
//-- Bara hamnplats
if(!empty($Bryggplats1) &&  empty($Vinterplats1) && empty($Bryggplats2) &&  empty($Vinterplats2))	{  $antal_natter = "2";  }
//-- Hamnplats och vinterplats eller skjul
if(!empty($Bryggplats1) && !empty($Vinterplats1) && empty($Bryggplats2) &&  empty($Vinterplats2))	{  $antal_natter = "3";  }
//-- Hamnplats och vinterplats eller skjul
if(!empty($Bryggplats1) && empty($Vinterplats1) && empty($Bryggplats2) &&  !empty($Vinterplats2))	{  $antal_natter = "3";  }
//-- Hamnplats, vinterplats och skjul
if(!empty($Bryggplats1) && !empty($Vinterplats1) && empty($Bryggplats2) && !empty($Vinterplats2))	{  $antal_natter = "4";  }
//-- Bara vinterplats eller skjul
if( empty($Bryggplats1) && !empty($Vinterplats1) && empty($Bryggplats2) &&  empty($Vinterplats2))	{  $antal_natter = "1";  }
//-- Vinterplats och skjul
if( empty($Bryggplats1) && !empty($Vinterplats1) && empty($Bryggplats2) && !empty($Vinterplats2))	{  $antal_natter = "2";  }
 
echo "
  <tr>
    <td style=\"background-color: #$bgcolor\" >$nummer</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\" >$medlemsnr</td>
	<td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\" >$fornamn</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\" >$efternamn</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\" >$antal_natter</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\" >$dag_bev1</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\" >$dag_bev2</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\" >$dag_bev3</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\" >$dag_bev4</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>";
if($dag_bev1 < 1 && $dag_bev2 < 1 && $dag_bev3 < 1 && $dag_bev4 < 1)  { $antal_bokningar = "0"; }
if($dag_bev1 > 0 && $dag_bev2 < 1 && $dag_bev3 < 1 && $dag_bev4 < 1)  { $antal_bokningar = "1"; }
if($dag_bev1 > 0 && $dag_bev2 > 0 && $dag_bev3 < 1 && $dag_bev4 < 1)  { $antal_bokningar = "2"; }
if($dag_bev1 > 0 && $dag_bev2 > 0 && $dag_bev3 > 0 && $dag_bev4 < 1)  { $antal_bokningar = "3"; }
if($dag_bev1 > 0 && $dag_bev2 > 0 && $dag_bev3 > 0 && $dag_bev4 > 0)  { $antal_bokningar = "4"; }
$att_boka_ytterligare = ($antal_natter - $antal_bokningar);
if($att_boka_ytterligare == 0)  { $att_boka_ytterligare = "<span style=\"color:#800000; font-size: medium; font-weight: bold;\">".$att_boka_ytterligare."</span>";  }
if($att_boka_ytterligare > 0)  { $att_boka_ytterligare = $att_boka_ytterligare;  }
if($att_boka_ytterligare < 0)  { $att_boka_ytterligare = "<span style=\"color:#800000; font-size: x-small; font-weight: bold;\">Överbokat</span>";  }
echo"
	<td style=\"background-color: #$bgcolor\"  align=\"center\">$antal_bokningar</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
    <td style=\"background-color: #$bgcolor\"  align=\"center\">$att_boka_ytterligare</td>
    <td style=\"background-color: #$bgcolor\" >&nbsp;</td>
  </tr>";
}}
?>
</table>
</div>
</body>
</html>
[+][-]10/29/09 04:40 PM, ID: 25699221Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP and Databases, MySQL Server
Tags: mysql
Sign Up Now!
Solution Provided By: HainKurt
Participating Experts: 1
Solution Grade: A
 
[+][-]10/29/09 04:40 PM, ID: 25699226Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625