Jump to content

lowe_22

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lowe_22's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yea typo, meant to read "static". I realise that static variables and functions don't work in PHP4 - but thats the point i'm trying to make, how can I create a similarly working script without use of 'static'?
  2. Hi, I have recently written this class to create drop down select boxes using PHP 5. I then discovered that my webhost runs only PHP4. The probelm is, I dont' know the differences between PHP4 and PHP5 thus I have no idea how to get this class working in PHP4! If anyone has any ideas, please do let me know! Code below. <?php //Define Dates class DateViewHelper { static $MONTHS = array( "January", "Febreuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ); satic $DAYS = array( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); static function yearPulldown ($from, $to, $selected ){ $ret = ""; for ( $x = $from; $x <= $to; $x++ ) { $ret .= "<option"; $ret .= ($x == $selected )?' selected="selected"':""; $ret .= ">$x</option>\n"; } return $ret; } static function monthPulldown( $selected ) { for ( $x=1; $x <= 12; $x++ ) { $ret .= "<option value=\"$x\""; $ret .= ( dateViewHelper::$MONTHS[$x-1] == $selected )?' selected="selected"':""; $ret .= ">".dateViewHelper::$MONTHS[$x-1]."</option>\n"; } return $ret; } static function dayPulldown ( $selected ) { for ( $x=1; $x <= 31; $x++ ) { $ret .= "<option value=\"$x\""; $ret .= ($x == $selected )?' selected="selected"':""; $ret .= ">$x</option>\n"; } return $ret; } } ?>
  3. Hi, I've got a table in my database which has a user name then three other columns, each column is the number of first/second/third place wins in a competetion (respectively). I want to be able to have some kind of running total column that adds up all the numbers from each preceding column for each member. I know this is not possiuble in MySQL as it is a not a dynamic language. My end results, however, is to output (via PHP) the membername with the most wins - starting with the most first place wins, then the second wins then the third. Understand? So its not just a case of the person with the most placings wins - butthe person with the highest number of 1st place, tehn 2nd place, then 3rd place wins? Any ideas?
  4. Yea, that helps a lot. thanks very much. There was one other thing that I could do with some help on. that is as follows: For every 10 images of a certain kind, a different image is displayed instead. So, if the member had 14 1st place wins, the browser should print one 10wins image followed by four 1stwins images. Understand? Any ideas? Thanks
  5. Hi, I've run into a spot of difficulty whilst trying to code a script - I want to display 3 different images x number of times, where x is a number stored in a database. I'll tell you the context: I have a database of tournament wins with 4 columns: MemberID (which member has the wins...), 1st Places wins, 2nd place wins, 3rd place wins. A number is stored in each of the columns representing the number of each place won. I basically want to display an image for each one: 1image for 1st place, 1 image for second etc.. but I want to display that image however many times depending on the number in the database. For example, a member has 3 1st place wins, I want to display the image for a first place win 3 times on the page. How could I go about doing this? Thanks.
  6. I have one select statement retrieving values from a database of members. On of these values is a field called "masterID". This will return the ID number of another member in the database. Basically, I need to select, say the "memberName", "memberInitials" and "masterID" from one member, then use another select statement, using that value of "masterID" to obtain some information from that member. Do you see what I mean? Something like this, only this doesn't work! [code] <?php $sql = "SELECT * FROM tblmembers WHERE memberActive='1' LIMIT 1"; if ($result = mysql_query($sql)) {   while($row = mysql_fetch_array($result)) { $memberName = $row['memberName']; $memberRank = $row['memberRank']; $memberStarColor = $row['memberStarColor']; $memberInitials = $row['memberInitials']; $memberMasterID = $row['memberMasterID']; ?> <br /> <br /> <br /> <?php   $sql1  = "SELECT * FROM tblmembers WHERE memberID='$memberMasterID'"; if($result1 = mysql_query($sql1)) {     while(mysql_fetch_array($result1)) { $masterInitials = $row['memberInitials']; $masterStarColor = $row['memberStarColor']; $masterName = $row['memberName']; }   } }               } ?>[/code] See what I mean? I've tried a combination of registering the masterID from the first statment to a Session, and placing various bits of code inside other while loops, but I don't seem to have got there yet! Cheers.
  7. I found the problem. mySQL didnt like me trying to select from a Session variable on this line: [code] <?php // Get the ID of member's matser $sql = "SELECT * FROM tblmembers WHERE memberName=".$_SESSION['master']; ?> [/code] so ther value for masterId was not populating correctly... etc :D
  8. Ok, ive changed my code. But it still doesnt work! I've no idea why not! Here is the script in its entirity to see if it helps!!! All the session variables are passed to this script from a user posted form in a previous script. This scrpt is supposed to check to see that the data they entered is correct (which works) then enters the necessary detaisl into the database, depending on whther certain fileds have been fillled out or not (sort of woks, minus the master ID thing...) Its driving me insane... [code] <?php session_start(); include('../inc/inc.php'); checklogin(); if (isset($_POST['yes'])) { $nickname=$_SESSION['nickname']; userindb($nickname); if ($indb==true) { $error = "Error: That member is already in the database!"; }else{ $memberActive = "1"; $memberBanned = "0"; // No Master... if ($_SESSION['master']=="No Master"){ //add info to DB without master... $sql = "INSERT INTO tblmembers (memberName, memberRank, memberStarColor, memberInitials, memberActive, memberBanned, memberEmail, memberRealName) VALUES ('" . $_SESSION['nickname'] . "', '" . $_SESSION['rank'] . "', '" . $_SESSION['starcolor'] . "', '" . $_SESSION['initials'] . "', '" . $memberActive . "', '" . $memberBanned . "', '" . $_SESSION['email'] . "', '" . $_SESSION['realname'] . "')"; if ($result = mysql_query($sql)) { header('Location: add.php?action=added'); } } elseif (($_SESSION['starcolor']=="-- No Color --") || ($_SESSION['initials']=="")){ // No star color or intials // Get the ID of member's matser $sql = "SELECT * FROM tblmembers WHERE memberName=".$_SESSION['master']; if ($result = mysql_query($sql)) { $row = mysql_fetch_array($result); $masterID = $row['memberMasterID']; $_SESSION['masterID'] = $row['memberMasterID']; } //add info to DB without star color or initials $sql = "INSERT INTO tblmembers (memberName, memberRank, memberMasterID, memberActive, memberBanned, memberEmail, memberRealName) VALUES ('" . $_SESSION['nickname'] . "', '" . $_SESSION['rank'] . "', '" . $masterID . "', '" . $memberActive . "', '" . $memberBanned . "', '" . $_SESSION['email'] . "', '" . $_SESSION['realname'] . "')"; if ($result = mysql_query($sql)) { header('Location: add.php?action=added'); } }else{ // convert to master to a member ID to get their star colours etc... $sql = "SELECT memberID FROM tblmembers WHERE memberName = ".$_SESSION['master']; if ($result = mysql_query($sql)) { $row = mysql_fetch_array($result); $masterID = $row['memberMasterID']; $_SESSION['masterID'] = $row['memberMasterID']; } // insert info into database $sql = "INSERT INTO tblmembers (memberName, memberRank, memberStarColor, memberInitials, memberMasterID, memberActive, memberBanned, memberEmail, memberRealName) VALUES ('" . $_SESSION['nickname'] . "', '" . $_SESSION['rank'] . "', '" . $_SESSION['starcolor'] . "', '" . $_SESSION['initials'] . "', '" . $masterID . "', '" . $memberActive . "', '" . $memberBanned . "', '" . $_SESSION['email'] . "', '" . $_SESSION['realname'] . "')"; if ($result = mysql_query($sql)) { header('Location: add.php?action=added'); } } } } if (isset($_POST['no'])) { header('Location:add.php'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>LightSaber SithElite - Members Admin - Add</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css" media="screen"> /* <![CDATA[ */ @import url(../../style.css); /* ]]> */ </style> <!--[if IE 6]> <style> #navigation ul {padding-top:9px; margin:-1px -2.1px 0 -3px;} #navigation ul li a {padding:1.2em 1.7em 1.42em 1.7em;} .first {margin-left:-0.3em;} </style> <![endif]--> </head> <body> <div id="wrapper">   <div id="logo"></div>   <div id="toplinks">     <ul>       <li><a href="../../index.php">Home</a></li>       <li><a href="http://ehonu.com/lsforum">Forum</a></li>       <li><a href="../../contact.php">Contact</a></li>     </ul>   </div>   <div id="banner"> <img src="../../images/banner2.jpg" alt="Banner"/> </div>   <div id="navContainer">     <div id="navigation">       <ul>         <li><a href="../../index.php">home</a></li>         <li><a href="../../../lsforum">forum</a></li>         <li><a href="../../about.php">about</a></li>         <li><a href="../../news.php">news</a></li>         <li><a href="../../members.php">members</a></li>         <li><a href="../../servers.php">servers</a></li>         <li><a href="../../tournaments.php">tournaments</a></li>         <li><a href="../../los.php">league of sith</a></li>         <li><a href="../../downloads.php">downloads</a></li>         <li><a href="../../allies.php">allies</a></li>         <li class="last"><a href="../help.php">help</a></li>       </ul>     </div>   </div>   <div id="content">     <div id="mainContent">       <h1>site<span class=red>admin</span> - confirm</h1>       <div id="news">         <? if (isset($error)) {   echo "<p class=err>".$error."</p>";   }   ?>         <? if ($_GET['action']=="add") { echo "<p class=ok>Thank you. Please confirm that the information you have chosen is correct.</p><br/>"; echo "Nickname: " . $_SESSION['nickname'] . "<br />"; echo "Email: ".$_SESSION['email']."<br />"; if (empty($_SESSION['realname'])){ echo    "Real Name: Not Specified.<br />"; }else{ echo "Real Name: ".$_SESSION['realname']."<br />"; } echo "Master: ".$_SESSION['master']."<br />"; echo    "Rank: ".$_SESSION['rank']."<br />"; if (in_array($_SESSION['rank'], $highranks)){ echo "Star Color: ".$_SESSION['starcolor']."<br />"; }else{ echo "Star Color: Not Required<br />"; } if (in_array($_SESSION['rank'], $highranks)){ echo "Initials: ".$_SESSION['initials']."<br />"; }else{ echo "Initials: Not Required<br />"; } echo "<br><p>Is this information correct?</p><br /><br />"; echo "<form name=\"form2\" action=" . $_SERVER['PHP_SELF'] . " method=\"POST\" class=\"register-form\" id=\"form1\">"; echo "<input type=\"hidden\" value=\"\" /><span style=\"display:inline;\"><input type=\"submit\" name=\"yes\" class=\"btn\" value=\"Yes\">"; echo "<input type=\"submit\" name=\"no\" class=\"btn\" value=\"No\"></span>"; echo "</form>"; } ?>         <br />         <br />         <? if (isset($error)){ echo "<p class=\"err\">This member is already in the database!</p><br />"; } ?>         <p> <br />           <br />       </div>     </div>     <div id="sidebar">       <div id="adminlinks">         <ul>           <li><a href="../../main.php">Home</a></li>           <li><a href="add.php">Add Member</a></li>           <li><a href="change.php">Promote / Demote Member</a></li>           <li><a href="edit.php">Edit Member</a></li>           <li><a href="delete.php">Delete Member</a></li>           <li><a href="logout.php?logout=true">Logout</a></li>         </ul>       </div>     </div>   </div>   <div id="footer">     <p>copyright &copy; LightSaber SithElite 2006. design by b0ss.</p>   </div> </div> </body> </html> [/code]
  9. I have a script to put members into a database This part is supposed to select the auto_incremented field memberID from the database when the member name is a user defined Session - $_SESSION['master']. For some reason, it is not inserting the masterID into the database! I dont know why! Here is the code: [code]$sql = "SELECT memberID FROM tblmembers WHERE memberName=".$_SESSION['master']; if ($result = mysql_query($sql)) { list($masterID)= mysql_fetch_row($result); $_SESSION['masterID']=$masterID; } userindb($_SERVER['nickname']); if ($indb==true) { $error = "Error: That member is already in the database!"; }else{ //add info to DB without star color or initials $sql = "INSERT INTO tblmembers (memberName, memberRank, memberMasterID, memberActive, memberBanned, memberEmail, memberRealName) VALUES ('" . $_SESSION['nickname'] . "', '" . $_SESSION['rank'] . "', '" . $masterID . "', '" . $memberActive . "', '" . $memberBanned . "', '" . $_SESSION['email'] . "', '" . $_SESSION['realname'] . "')";[/code]
  10. Ahhh... Cheers. The previous post I made regarding this script was with a different aspect, and so i felt I needed to post again as it was a separate problem. Many thanks for saving my ass twice!
  11. Right, I've written script that is basically a simple error checking system for a webform that allows a user to enter a new member into a database. The form consits of three imptortant fields (and several others that are irrelevant to this problem): Rank Star Colour Initials. The member may only have a star colour and initials if he is of a certain rank or higher. Therefore, when checking the form, if the selected  rank is not high enough, and star colour or initials have been selected, an error message occurs. Similarly if the rank is high enough, but star colour and initials have not been selected, an error occurs. Ok? Right i think my problem comes when the user actually does things right! i.e.they slecet a high enough rank and a star colour, yet for some reason the star colour does not seem to be assigning to the variable I have set for it. I have checkd this by printing the variable assigned to each field. Here is the relevent bits of code: [code] <?php // Define Rank arrays. $highranks[] = "ES*"; $highranks[] = "ES**"; $highranks[] = "SM*"; $highranks[] = "SM**"; $highranks[] = "SL*"; $highranks[] = "SL**"; $highranks[] = "SS*"; $highranks[] = "SS**"; $highranks[] = "SC*"; $highranks[] = "SC**"; $highranks[] = "SCF"; $highranks[] = "RCM"; $highranks[] = "SOL"; if ($_POST['btnAdd']) { // Make sure form has been posted before error checking! $nickname=$_POST['nickname']; $email=$_POST['email']; $realname=$_POST['realname']; $master=$_POST['master']; $rank=$_POST['rank']; $starcolor=$_POST['starcolor']; $initials=$_POST['initials']; $error = FALSE; // check up variable $err_nickname = FALSE; $err_rank = FALSE; $err_email = FALSE; $err_master = FALSE; $err_starcolor = FALSE; $err_initials = FALSE; // Check for correct input in star color and initials //starcolor if(!in_array($rank, $highranks) and ($starcolor!="-- No Color --")) { $error=true; $err_starcolor="The member is not of sufficient rank for a star color!"; } // Makes sure that user hasnt selected a star color when member isnt of high enough rank. if ((in_array($rank, $highranks)) and ($starcolor="-- No Color --")){ $error=true; $err_starcolor="Please select a star color!"; } //initials if(!in_array($rank, $highranks) and (!empty($initials))) { $error=true; $err_initials="The member is not of sufficient rank for initials!"; } if ((in_array($rank, $highranks)) and (empty($initials))){ $error=true; $err_initials="<span class=error>Please enter some initials!</span>"; } // the form... ?> <form name="form2" action="<?=$_SERVER['PHP_SELF']?>" method="POST" class="register-form" id="form1"> <div>             <label for="rank"><strong>Rank*</strong></label>             <select name="rank"> <?php if(isset($err_rank)){ echo "<option value=$rank selected=selected>$rank</option>"; }else{ echo "<option value=\"-- Select a Rank --\" selected=\"selected\">-- Select a Rank --</option>"; } ?>               <?php foreach($rankslist as $val) { echo "<option value=" . $val . ">" . $val . "</option>"; } ?> <option value="-- Special Ranks --" disabled=disabled>-- Special Ranks --</option> <?php foreach($specialrankslist as $specialval) { echo "<option value=" . $specialval . ">" . $specialval . "</option>"; } ?>             </select>             <?php echo "<span class=error>".$err_rank."</span>"; ?></div>           <div> <br />             <p>Please Note: The following feilds are only required if the members rank is ES* or above.</p>             <br />             <div>               <label for="starcolor"><strong>Star Color*</strong></label>               <select name="starcolor">                 <?php if(isset($err_rank)){ echo "<option value=$starcolor selected=selected>$starcolor</option> <option value=\"------\" disabled=disabled>-----</option> <option value=\"-- No Color --\">-- No Color --</option>"; }else{ echo "<option value=\"-- No Color --\" selected=\"selected\">-- No Color --</option>"; } ?> <? foreach($starlist as $val) { echo "<option value=\"" . $val . "\">" . $val . "</option>"; } ?>               </select>               <?php echo "<span class=error>".$err_starcolor."</span>"; ?> </div>             <div>               <label for="initials"><strong>Initials*</strong></label>               <input type="text" name="initials" id="initials" class="text" value="<?=$initials?>" />               <?php echo "<span class=error>" . $err_initials . "</span>"; ?> </div>               <input type="submit" name="btnAdd" class="btn" value="Add">           </div>         </form> [/code] I am at a loss as to what the problem could be. As far as I'm aware, the error checking "if" statements are correct and are checking the right values... I just dont know. Any help?
  12. Oh, ok. Thanks, I didn't realise that. I thought you had to use the register_session() function to initiate the variable... Im guessing you can just define it straight away then! cheers.
  13. Hmm, It doesn't keep the same value... You know in a standard input field, you can assign the value to keep what the user just entered incorrcetly, eg] [code] <input type="text" name="initials" class="text" value="<? if ($initials_err) {echo $initials; } ?>" />[/code] Basically, I need the same thing to happen but for a select box.
  14. Use sessions. You must have [code]session_start();[/code] at the top of the page you want to define or call sessions or you will get some nice errors... Then, simply register assign your session to a variable. Eg : [code] <? session_start(); $name="Olly"; session_register('name'); $_SESSION['name'] = $name; ?> [/code] Then you can use the value assigned to $name on any page by calling [code]$_SESSION('name');[/code] eg, [code] <? session_start(); echo "Name:" . $_SESSION['name']; // Prints: // Name: Olly ?> [/code]
  15. Hi, I'm having some trouble with a select box in PHP so that if tere is an error with the selected item, the form keeps the selected item selected to stop the user making the same mistake again. Here is the validation code for the select box: [code]if(!in_array($rank, $highranks) and ($starcolor!="-- Select a Color --")) { $error=true; $err_starcolor="<span class=error>The member is not of sufficient rank for a star color!</span>"; }[/code] Here is the code im using as the select box: [code]<select name="starcolor">   <option value="-- Select a Color --">-- Select a Color --</option>   <? foreach($starlist as $val) { echo "<option value=" . if ($err_starcolor){ echo $starcolor } . ">" . $val . "</option>"; } ?>             </select> <? echo "<span class=error>".$err_starcolor."</span>"; ?>[/code] I know that won't even work in principle, but I don't know how to do it! Many thanks.
×
×
  • 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.