Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. No that is NOT what you need to do. You need to look at the problem logically and proceed accordingly. You cannot submit a header() request after you have sent data to the browser. So, just do as has already been explained. Process the data first THEN either send to another page or output content from the current script.
  2. <?php $qres = mysql_query("SELECT * FROM `$clubprefix"."_player` WHERE id='$id'"); //Start table and create table headers $results = "<table>\n"; $results .= "<tr>\n"; $results .= "<th>Forehand/Backhand</th>\n"; $results .= "<th>Fitness/Movement</th>\n"; $results .= "<th>Serve/Return</th>\n"; $results .= "<th>Volley</th>\n"; $results .= "<th>Special Shots</th>\n"; $results .= "<th>Playing Style</th>\n"; $results .= "<th>Tournament Experience</th>\n"; $results .= "</tr>\n"; //Output the data WHILE ($row = mysql_fetch_array ($qres, MYSQL_ASSOC)) { $results .= "<tr>\n"; $results .= "<td>{$row['FB']}</td>\n"; $results .= "<td>{$row['FM']}</td>\n"; $results .= "<td>{$row['SR']}</td>\n"; $results .= "<td>{$row['Vol']}</td>\n"; $results .= "<td>{$row['SS']}</td>\n"; $results .= "<td>{$row['PS']}</td>\n"; $results .= "<td>{$row['TE']}</td>\n"; $results .= "</tr>\n"; } //Close the table $results .= "</table>\n"; ?> <html> <head></head> <body> <div id="tableOutput"> <?php echo $results; ?> </div> </body> </html> I put the results in a variable as it is better form to include the logic at the top of your page and display the results in the body of the page.
  3. Just create a function function clearZero($value) { return ($value==0) ? '' : $value; } Then use that function when assigning the values to your variables: $variable = clearZero($_POST['fieldName']);
  4. Change this echo " <a href='{$_SERVER['PHP_SELF']}?&pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?&pagenum=$last'>Last ->></a> "; To this: echo " <a href='{$_SERVER['PHP_SELF']}?gid={$gid}&pagenum={$next}'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?gid={$gid}&pagenum={$last}'>Last ->></a> ";
  5. You mean "find a class or some third-party plug-in"? http://lmgtfy.com/?q=php+edit+word+doc
  6. Yeah, teamtonic is right. You happened to pick one very unique case where using curly braces would not give you what you were looking for. In that particular case, you could omit the curly braces to get the output you were after. Here is an example where you would want to use the curly braces. Example: Let's say the application uses the user's first and last name with an underscore between them to autogenerate a folder name to store a user's data. If you wanted to display the folder name on the screen, this would not work: $first = 'Dave'; $last = 'Smith'; echo "$first_$last"; //Output: Smith That would try to echo the variables $first_ and $last. The variable $first_ doesn't exist and you would only be displaying the last name. Instead you could do this: $first = 'Dave'; $last = 'Smith'; echo "{$first}_{$last}"; //Output: Dave_Smith
  7. Use double equals for comparison. A single equal sign is used for assignment
  8. It depends on hos the position is defined and what you are really after. If you have specified the position using in-line CSS properties OR if you have defined the CSS property using javascript, then you can get the value using javascript. If, however, the property is defined in a stylesheet, then javascript cannot get the value. You could probably write some really complext code to get the class or ID from the element and then read the stylesheet to find the appropriate class, and finally parse the properties of the class to find the position. But, that would be a lot of work. Also, if the position is not even defined in the style properties and you are just trying to get the position that can be done, but there are browser compatability issues to contend with. There are some freely available scripts that can do this if you do a littel searching. Anyway, here is an example script that gives four different examples of how the left property is defined. The sample javascript function can obtain the left position for two, but not the other two. <html> <head> <style> #div3 { position: absolute; left:400px; } </style> <script> function test(divID) { var divObj = document.getElementById(divID); alert( divObj.style.left ); } </script> </head> <body> <div id="div1" style="">One - No position defined</div> <div id="div2" style="position:absolute; left:150;">Two - Defined In Line</div> <div id="div3">Three - Defined in style sheet</div> <div id="div4" style="position:absolute;">Four - Defined via javascript</div> <br /><br /><br /> <button onclick="test('div1');">One</button><br /> <button onclick="test('div2');">Two</button><br /> <button onclick="test('div3');">Three</button><br /> <button onclick="test('div4');">Three</button><br /> <script type="text/javascript"> document.getElementById('div4').style.left = '600px'; </script> </body> </html>
  9. Word docs are not plain text documents. You can't simply "write" text to the dcoument. Prior to Office 2007 word docs were stored in a proprietary format. Starting with 2007 they are being stored in an XML format. You will need to write the data in a format that is appropriate to the document you have. I think your only option is going to be to find a class or some third-party plug-in that allows you to modify word documents.
  10. Yeah, I use both single and double as my preference depending on the context. If I want to include variables in the string I alomst always use double quotes and include the varaibles within curly braces to make it apparent that the value is a variable. The braces also prevent the variable from being misinterpreted if other characters must reside right next to the variable. $salutaion= "Hello {$username}!"; However, if there are no variables in the string, and especially if it will have HTML tags, I will use single quotes so I don't have to escape the double quotes int he HTML code $img= "<img src="pathtofile/logo.gif" />";
  11. Personal preference. There are also the heredoc and nowdoc methods of defining variables. I suggest you take a look at this page: http://php.net/manual/en/language.types.string.php
  12. You can put whatever you want into the variables. Whatever you put in it will get used. If you know how to write the HTML code for an image, just include it into the testimonial string. The only thing to watch for is quotation marks. If you define a string with double quotation marks and you want to use double quotation marks in the string, you will need to escpe them (same goes for single quotation marks: $testimonials = array( "<h3><a href=\"http://www.eastindia.com\">Mr Kibir Rahman T/A East India Trading Company</a></h3> <img src=\"http://www.eastindia.com\logo.gif\"> <P>'Since opening our 5 restaurants you have really helped us.'<P>", "<h3>Steve Bird T/A 1 Stop Magic Carpets</h3><p>'I would like to thank your member of staff for helping me'<P> ", );
  13. Well, it worked for me. I actually tested that code before I posted. Since you didn't take the time to post the actual error (with the line numbers) and the relevant code, there's nothing I can do to help.
  14. siric is correct, there is no reason you cannot put a loop within another loop. However, in this case, the inside WHILE loop is completely unnecessary and is just a complete waste. The loop is processign the exact same records every time. I think you meant to get the sub-category options respective to each parent option. But, the real reason you are not getting any results is you are using the first query when you meant to run the second query $result2 = dbQuery($sql); //<< you menat to use $sql2 But, you can get all the data you need with a single query - which would be a much better approach.
  15. Fixed typo: function convertBase(input, input_base, output_base) { var inputInDec = parseInt(input, input_base); var output = inputInDec.toString(output_base); return output; }
  16. Try this function convertBase(input, input_base, output_base) { var inputInDec = parseInt(input, input_base); var output = inputInDec.toString(ouput_base); return output; }
  17. Why don't you start by explaining what you want to achieve? Your first post was only regarding the NaN error you were receiving. I can "assume" you are trying to convert a base 10 number to a base 2, but that is only a guess since you've never stated that. Your last post you state you see no errors but don't state what you want the script to do and what it is doing differently.
  18. I think you are misunderstanding the purpose of the second parameter for parseInt(). If you specify the radix to be 2, then the value to be parsed must be in the format of a binary number, e.g. "1101" (which would be parsed to the decimal value of 13).
  19. Psycho

    Pages...

    That is not what you requested. You stated you wanted to show the 5 pages before and the 5 pages after the current page. I only hard coded the current page for illustrative purposes. It is your responsibility to define the current page, the max pages (i.e. limit) and the span (which you already stated would be 5, but the code will allow for different values if you wish. This foum uses more complex functionality to include, possibly, the very first and very last pages and ellipses as needed. You did not ask for that, so I did not provide it.
  20. Psycho

    Pages...

    <?php $current_page = 9; $span_pages = 5; $start_page = (($current_page-5) < 1) ? 1 : ($current_page-5); $end_page = (($current_page+5) > $limit) ? $limit : ($current_page+5); for($page=$start_page; $page<=$end_page; $page++) { if($page==$current_page) { echo "| <b>{{$page}}</b> | "; } else { echo "| <a href=\"?start={$page}\">{$page}</a> | "; } } ?>
  21. I think you need a NAME for your input fields. Don't think jsut an ID will work
  22. Here's something I have laying around <?php //bbcode $patterns = array( //BB Code "/\[[b]\](.*?)\[\/b\]/is", "/\[[i]\](.*?)\[\/i\]/is", "/\[[u]\](.*?)\[\/u\]/is", "/\[[s]\](.*?)\[\/s\]/is", "/\[marquee\](.*?)\[\/marquee\]/is", "/\[url\](.*?)\[\/url\]/is", "/\[url=(.*?)\](.*?)\[\/url\]/is", "/\[img\](.*?)\[\/img\]/is", "/\[quote\](.*?)\[\/quote\]/is", "/\[code\](.*?)\[\/code\]/is", "/\[(size|color)=(.*?)\](.*?)\[\/\\1\]/is", "/\[br\]/i", //Emoticons "/ \:\) /", "/ \:\( /", "/ \ /", "/ \ /", "/ \:\| /", "/ \ /", "/ \:\? /", "/ \;\) /"); $replacements = array( //BB Code "<b>\\1</b>", "<i>\\1</i>", "<u>\\1</u>", "<s>\\1</s>", "<marquee>\\1</marquee>", "<a href=\"\\1\">\\1</a>", "<a href=\"\\1\" target=\"_blank\">\\2</a>", "<img border=\"0\" src=\"\\1\">", "<div><b>Quote:</b> <i>\\1</i></div>", "<br /><b>Code:</b><br /><div style=\"overflow:auto;\"><xmp>\\1</xmp></div><br />", "<font \\1=\"\\2\">\\3</font>", "<br />", //Emoticons " <img src=\"smilies/happy.gif\" border=\"0\"> ", " <img src=\"smilies/angry.gif\" border=\"0\"> ", " <img src=\"smilies/omg.gif\" border=\"0\"> ", " <img src=\"smilies/tounge.gif\" border=\"0\"> ", " <img src=\"smilies/dry.gif\" border=\"0\"> ", " <img src=\"smilies/biggrin.gif\" border=\"0\"> ", " <img src=\"smilies/confused.gif\" border=\"0\"> ", " <img src=\"smilies/wink.gif\" border=\"0\"> " ); $string = "[b]This is bold text[/b] [i]this is italic text[/i] [b][i]This is bold, italic text[/b][/i]"; $result = preg_replace($patterns,$replacements,$string); echo $result; ?>[/ode]
  23. One quick thing I don't understand.....below where the HTML form comment is and there is a form method post statement.... <form method="post" action="">addTournament2.php How come the .php file is outside of the form method brackets?? How does that work? Everything else for the most part makes sense and its definitely in a hell of a lot more organized fashion. Perhaps as I become better at this I will be able to produce something similiar. Sigh. Sorry, bout that. I removed the file name from the action so I could have the page POST to itself for testing purposes. You can replace that value or leave it blank if the page is supposed top post to itself. // PROCESS FORM ON SUBMIT $response = ''; if (isset($_POST['tourneyName'])) No, no relation. In that code, I simply define $respons as an empty string in case it doesn't get defined later. The IF statement is there to process the data only if data was posted.
  24. There were a lot of problems with your code aside from the date issues. Here is a complete rewrite in a more logical fashion. This has been tested <?php // START SESSION require_once('includes/session.inc.php'); // CONNECT TO DATABASE require_once('includes/connect.inc.php'); // PROCESS FORM ON SUBMIT $response = ''; if (isset($_POST['tourneyName'])) { //Create array var to capture errors $errors = array(); //Validate the submitted data $tourneyName = trim($_POST['tourneyName']); $tourneyDate = trim($_POST['gameDate']); if(empty($tourneyName)) { $errors[] = "Tournament name is required."; } if(empty($tourneyDate)) { $errors[] = "Tournament date is required."; } else if(!$tourneyDate = strtotime($tourneyDate)) { $errors[] = "Tournament date is not in a valid format."; } if(count($errors)>0) { //There were validation errors, prepare error message $response = "<span style=\"color:red;\">"; $response .= "The following errors occured:\n"; $response .= "<ul>"; $response .= '<li>' . implode('</li><li>', $errors) . '</li>'; $response .= "</ul>\n"; $response .= "</span>\n"; } else { //No validation errors, save the data to database $tourneyName = mysql_real_escape_string($tourneyName); $tourneyDate = date('Y-m-d', $tourneyDate); $query="INSERT INTO `tournaments` (`tourneyName`, `gameDate`) VALUES ('{$tourneyName}', '{$tourneyDate}')"; $result = mysql_query($query); if (!$result) { $response = "No record was added. Please try again."; $response .= "<br />\n$query<br />".mysql_error(); } else { $response = "The record has been added."; } } } //Get current records to display $query = "SELECT * FROM `tournaments`"; $result = mysql_query($query); //Validate there were records if(mysql_num_rows($result) == 0) { $records = "Sorry, no records were found!"; } else { // START OF TABLE, HEADERS, ETC $records = "<table border=\"1\">\n"; $records .= "<tr><th>TID</th><th>Name</th><th>Date</th></tr>\n"; //LOOP THE DATABASE TO DISPLAY THE RECORDS while ($myrow = mysql_fetch_array($result)) { //PRINT RESULTS $date = date('Y-m-d', strtotime($myrow['gameDate'])); $records .= "<tr>"; $records .= "<td>{$myrow['tourneyID']}</td>"; $records .= "<td>{$myrow['tourneyName']}</td>"; $records .= "<td>{$date}</td>"; $records .= "</tr>\n"; } $records .= "</table>\n"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Admin MySQL Database For The Bomb Island Raiders</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="css/admin.css" rel="stylesheet" type="text/css"> </head> <body> <div id="navigation"> <?php include_once('includes/admin_nav.inc.php'); ?> </div> <div id="content"> <h1>Add </h1> <br /> <div><?php echo $response; ?></div> <!--HTML FORM--> <form method="post" action="">addTournament2.php <table border=1 RULES=NONE FRAME=BOX> <tr> <td>Tournament Name</td> <td><input type="text" name="tourneyName" size="24"></td> </tr> <tr> <td>Game Date:</td> <td><input type="text" name="gameDate" size="24"></td> </tr> </table> <br /> <input type="submit" value="Submit" name="submit"> <input type="reset" value="Reset Values"> </form> <br /> <?php echo $records; ?> </body> </html>
  25. Exactly "HOW" are the testimonials stored in that file? I would suggest that in that include file you put the testimonials into an array and add a line to define a testimonial randomly. testimonials.php <?php $testimonials = array( "It's Great! - Robert Thomas", "Never leave home without it - Bob Johnson", "It's a piece of Crap. Don't buy it!!! - Mr. Negativity." ); $testimonial = $testimonials[array_rand($testimonials)]; ?> Then on the pages where you need a testimonial, include the file as you are now. Then in the content echo $testimonial where you need it: <div class="main-subcontent"> <div class="subcontent-unit-border-orange"> <div class="round-border-topleft"></div><div class="round-border-topright"></div> <h1 class="orange">header</h1> <p><?php echo $testimonial; ?></p> </div> <div class="subcontent-unit-border-green"> <div class="round-border-topleft"></div><div class="round-border-topright"></div> <h1 class="green">content</h1> <p>content</p> </div> </div>
×
×
  • 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.