Forum Moderators: coopster

Message Too Old, No Replies

Code output Issue (Newbe)

         

TheLazyAce

5:07 am on Jan 21, 2011 (gmt 0)

10+ Year Member



Would some tell me what I have done on this code other then it is ugly? Also at the end of the code is my output. I am using the order to sort by office. That is why there are all the if statement.

$query="SELECT * FROM " . $dbtable ." WHERE BoardMem='Yes'";

$result=mysql_query($query);


$NumberOfRows = mysql_numrows($result);

while($Count < $NumberOfRows){
$TempStr = mysql_result($result,$Count,"active");
if ($TempStr > "0") {
$Last = mysql_result($result,$Count, "LastName");
$First =mysql_result($result,$Count, "FirstName" );
$email = mysql_result($result,$Count,"email" );
$Office = mysql_result($result,$Count,"BoardPosition" );
echo $Office;
if ($Office=="President") {
$Order = "1";
}
if ($Office=="President Elect") {
$Order ="2";
}
if ($Office=="Secretary") {
$Order="3";
}
if ($Office=="Treasurer") {
$Order="4";
}
if ($Office=="Community Service") {
$Order="5";
}
if ($Office=="Vocational Chair") {
$Order="6";
}
if ($Office=="International Chair") {
$Order="7";
}
if ($Office=="Sgt. at Arms") {
$Order="8";
}
if ($Office=="Club Service") {
$Order="9";
}
if ($Office=="Bulletin Editor") {
$Order="10";
}
if ($Office=="Past President") {
$Order="11";
}
echo $Count . " ". $Office . " ". $order . " " . $Last . "<br>";
$BoardMembers["$Order"] = $OpenMailToTag . $email . "\">" .$First . " ". $Last . "</a>" . " " . $Office . "<br>";

}

$Count++;

}

mysql_close();
$Order ="1";
while($Order < "12"){

Echo $order . " ". $BoardMembers["$Order"] . "<br>";
$Order++;
}






?>


echo result I get below:

Sergeant at Arms0 Sergeant at Arms BLACK
President6 President HITTLE
Treasurer9 Treasurer RENEAU
KARL HITTLE President



ELTON RENEAU Treasurer

I am looking for:
name president
name president elect......

Shingetsu

11:23 am on Jan 21, 2011 (gmt 0)

10+ Year Member



Did you use phpmyadmin to add the values? It might be the code you used to add them that got them in the wrong encoding.

TheLazyAce

12:18 pm on Jan 21, 2011 (gmt 0)

10+ Year Member



Yes, I did. I have made sure the data is in al the fields.

TheLazyAce

1:41 pm on Jan 21, 2011 (gmt 0)

10+ Year Member



Well I thought all the data was in the fields, I found I was overlooking that several records were null in the active field. Dumb Dumb Dumb, I hate it when I do this stuff. Being new to PHP not to coding I should have know better, I just wanted to assume it we my coding because of the lack of knowledge.

Thanks for the input again it made think and look harder.

Ed

rocknbil

5:20 pm on Jan 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An aside, are you doing all this to order your output? If so, you'd be much better off adding a field for the positions to order by. Let's call it sequence.

alter table yourtable add sequence int(4) default 0;

Then you can do

$query="SELECT * FROM $dbtable WHERE BoardMem='Yes' order by seqence asc";

And dispense with a lot of the difficult work.

TheLazyAce

10:22 pm on Jan 21, 2011 (gmt 0)

10+ Year Member



Thank you for the reply. I gave it some thought but I for saw major problems. This is being done for my local Rotary Club with 78 members. I do not mind investing 100's of hours designing the code, becasue I have been learning PHP. I have programed for years in VB and Filemaker DBs. PHP is just different. The point being I just don't want tot he do all the input and updates in DB and the Website.

I am working on all this code so everything can be dymanic seeing there are office elections every year, members change, ect....

I want information always the same so I am using drop down boxes. I was thinking about when the user pick the officer from the dropdown box it would set a veriable in the DB but I figure it would require just as much code.

Am I wrong in my thoughts here? I don't mind someone showing me the light.

Thanks

Ed

Shingetsu

2:45 am on Jan 22, 2011 (gmt 0)

10+ Year Member



How about something like this
Form:

Code for drop boxes... Each one of them sends a different value into the receiver...

Mysql info:
You have these rows:
ID
Function
Person first name
Person family name
Person full name
Currently applicable
(for the last 3 use) fname, lname, and aname (all name)
make the primary key into ID, and currently applicable should be a small integral. 1 for yes and 0 for no.
Receiver:

Function show($status)
{
$con = connect to mysql code;
If(!con) {
Die('failed to connect');
}
$db = database name;
mysql_select_db($db);
If(!$db) {
Die('failed to connect');
}
$qry = " SELECT * FROM table_name WHERE Function=$status";
Result = Mysql_query($con,$qry);
Echo $result;
mysql_close();

Or something of the sort... I do not suggestmyou use this (this isnfar from perfect) but simply use as an example onto how to structure it :D

TheLazyAce

5:58 am on Jan 22, 2011 (gmt 0)

10+ Year Member



I see that with more thought to this I could have cleaned up my code. The post I have received helped teach me more. Thank you for give me a concept to improve my code.

Ed

Mikett

2:45 am on Jan 26, 2011 (gmt 0)

10+ Year Member



Have you tried to use 0 instead of "0", and/or using the trim() function when you compare? It is often a good thing to try this when comparing values if your script works, but doesn't return the proper result.