Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. WTF? Why would you even think that would work? It would not be a valid XML file anymore, would it. I gave you a very explicit example on how you could test whether or not you could dynamically generate the XML file and you apparently chose not to follow it. I don't know what more I can do to help you if you can't follow simple instructions. Take one line from an existing, working file and replace it with an echo of the exact same content. For example, replace this line <settings> With this <?php echo "<settings>\n"; ?> If the site still works, then you know you can generate the file dynamically - but it must be a validly formatted XML file.
  2. Research, build, test . . repeat Do some searching and you will find some resources on the web. Build some test email and check what they look like in various email clients. If you want the email to look "exactly" right your only option will be to create the email out of images. If you have "advanced" styles in the email you are goingto be struggling to get it to look right in various email clients (especially web-based ones). I'd suggest going with a clean, simple design.
  3. I assume you want the "Name" "Email" and "Display_Photo" for the friend and not the user. based on these requirements I would NOT use COUNT() since you need the additional info. You can just use mysql_num_rows() to get the count and your results will have all the data. Try this (may need to modify the filed names as appropriate) $query = "SELECT u.Name, u.Email, u.Display_Photo FROM TBL_User_Friends AS uf LEFT JOIN TBL_Users_Online AS uo ON uf.Sender_ID = uo.User_ID JOIN TBL_Users AS u ON uo.User_ID = u.User_ID WHERE uf.Reciever_ID = '{$UserID}'";
  4. You should NEVER run queries in loops. Learn to do JOINs. I think your problem is that you are running a query for each friend and then checking the count (which I would assume is 1 or 9(. But, you should run one query for all the friends. $query = "SELECT COUNT(uo.User_ID) as online_count FROM TBL_User_Friends AS uf JOIN TBL_Users_Online AS uo ON uf.Sender_ID = uo.User_ID WHERE uf.Reciever_ID = '{$UserID}'"; $result = mysql_query($query); $friends_online = mysql_result($result, 0);
  5. You should take an existing, working file and simply replace one line with an echo to try an make it work. If you try to make too big a modification you don't know if the problem is that you can't make it dynamic or if there was a problem with what you did.
  6. No, I don't think so. It sounds as if they engineered the application to get the XML data from a php file for the specific purpose of allowing the XML data to be dynamic. If you can find the place n the application where the file is used I am guessing you will see it used within something such as file_get_contents() (which would get the result of the parse php code) as opposed to something like include() which would run that PHP code internally. Have you even tried to create the XML file using PHP? As a simple test, just replace a few of the lines in the current hard-coded file with echo statements, <?xml version="1.0" encoding="UTF-8"?> <?php echo "<settings>\n"; ?> <params>....</params> .... down to line 700.... </settings>
  7. Can you specify a php file for the config file? If so, just do that and put all your logic into that PHP file to query the database and produce the XML output. You may need to also set the appropriate headers. Aside from that you may have to add XML files to those tat will be processed for PHP logic. If you're on a shared host you won't be able to do this.
  8. That is why you use debugging. Debugging doesn't fix your problem, it only helps to determine where the problem is. I already gave you advice on how you can add some debugging code. Here is a more illustrative example: Put this right before the first if() statement in your method to display the links echo "Var totalPages = {$totalPages}<br>\n"; echo "Var currentPage = {$currentPage}<br>\n"; echo "Var loopStart = {$loopStart}<br>\n"; echo "Var loopEnd = {$loopEnd}<br>\n"; Those are all the variables that appear to be used in that method for conditional testing. If that doesn't help you to determine the problem, then ut some echo's inside the if() statements so you can determine which ones, if any, are running. For example, change this if ($totalPages < 1 || $totalPages == 1){ return null; } if ($totalPages < 1 || $totalPages == 1){ echo "[1]<br>\n"; return null; } use a different number in each branch. Then run you rpage and check the debugging info that is displayed.
  9. Not at all. There are specific differences between single quoted stings and double quoted strings that are clearly described in the manual. The biggest difference is that certain "elements" will be interpreted inside double quoted string. For example $foo = 'bar'; echo 'Foo:\t$foo'; Will output the literal text "Foo:\t$foo" because neither the escaped tab character nor the variable $foo will be interpreted inside the string. However, if you used a double quoted string: $foo = 'bar'; echo "Foo:\t$foo"; The output would be: because both the escaped tab character and the variable $foo will be interpreted. More info here: http://php.net/manual/en/language.types.string.php
  10. Although codeprada's statements are correct - you are doing it wrong! There is a built-in PHP function called nl2br() which will convert any line breaks in a string into BR tags. besides, what you had above was unnecessary. You could have done an explode() immediately followed by an implode using '<br>' as the glue.
  11. Font tags? Really? Anyway, have you checked the HTML source to see if there is anything output in the navigation section? Are you getting at least the containing DIV and UL elements? If no, then this condition is probably the reason why if ($totalPages < 1 || $totalPages == 1){ return null; } [Note: why didn't you just use $totalPages <= 1 or $totalPages < 2 ?] If you are getting the conatining DIV and UL elements . . . I see that all of the output created in that method is defined within if() conditions. So, all of those must be resulting in false. In either of the two cases you will want to do some debugging. Echo out the variables used in the if90 conditions just before the if() statement to see what they contain.
  12. @Kira, The proper way to check a checkbox is with checked="checked" $checked = ($IPCheck) ? "checked='checked' "; : ''; echo "<input type='checkbox' name='ip_automatic_login' id='ip_automatic_login' value='1' {$checked}/>";
  13. As my sig states, I do not always test my code. I expect that the person that I am providing code to will at least take a minimum of effort to resolve typos. In this case it should be obvious that the $errorMsg variable wasn't being output - it was simply included in HTML. Use this <div style="color:red;"><?php echo $errorMsg; ?></div> Also, this //If no format errors, check if there is a match if(count($errors)) Should be: //If no format errors, check if there is a match if(count($errors)==0)
  14. That tells me nothing. What problems/errors did you experience. Besides, I specifically stated
  15. Reliable? Well, it won't be efficient which could lead to some problems. Do ONE query to insert all your records. You can use the loop to "build" the query. Do not pass a value to determine how many subjects are being passed. Instead, create the subject input fields as an array Subject 1: <input type="text" name="subjects[]"> Subject 2: <input type="text" name="subjects[]"> Subject 3: <input type="text" name="subjects[]"> ... Then in your processing logic, loop over the array and determine if a value was passed. If so, add it to your insert data, otherwise skip it. I would also advise sending the data as POST values, but you can use GET if absolutely necessary. But, you will want to urlencode()/urldecode() if you do that. Sample code session_start(); require_once("conf.php"); mysql_select_db('site'); $username = mysql_real_escape_string(trim($_SESSION['user'])); $values = array(); foreach($_POST['subjects'] as $subject) { $subject = mysql_real_escape_string(trim($subject)); if(!empty($subject)) { $values[] = "('{$subject}', '{$username}', 'F.Y.B.Sc')"; } } $query = "INSERT INTO Subjects (`Subjects`, `User`, `Classs`) VALUES " . implode(', ', $values); $result = mysql_query($query) or die("Cannot Store subjects ".mysql_error());
  16. Your description is a little too general to really provide a good example, but here is an example (only need ONE query) $field2value = mysql_real_escape_string(trim($_POST['value2'])); $field3value = mysql_real_escape_string(trim($_POST['value3'])); $query = "UPDATE table2 SET field2='{$field2value}', feild3='{$field3value}' WHERE table2.field1 IN (SELECT field2 FROM table1)"; This is just an example. May need to modify the sub-query
  17. You should have your form page POST back to itself. The page should check if data was posted (so as not to do validations the first time the user access the page). If data was posted, validate the data. If an errors are found display an error message and repopulate the form with the data the user entered so they only have to fix the fields in error. If validation passes, then include() the page that will process the submitted data. So, you should make changes on the prior page to do the validations. By the way, the logic, as you've explained it will be problematic if you have two people with the same name. The sample code below does NOT take that problem into consideration. This is just a rough framework to use as a starting point <?php //Set values for populating form $fname = ''; $lname = ''; //error tracking variable $errors = array(); //Check if form was posted if($_SERVER['REQUEST_METHOD']=='POST') { //Validate input $fname = trim($_POST['fname']); $lname = trim($_POST['lname']); if(empty($fname)) { $errors[] = "First name is required."; } if(empty($lname)) { $errors[] = "Last name is required."; } //If no format errors, check if there is a match if(count($errors)) { $fnameSQL = mysql_real_escape_string($fname); $lnameSQL = mysql_real_escape_string($lname); $query = "SELECT * FROM Customer_Registration WHERE Firstname = '$fnameSQL' AND Lastname = '$lnameSQL'"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)<1) { //No record found $errors[] = "No user found with the name '{$fname} {$lname}'"; } else { //Include the page to update the user. //Use the results of this query to populate the form include('update-user.php'); exit(); } } } $errorMsg = ''; if(count($errors)) { $errorMsg .= "The following errors occured:"; $errorMsg .= "<ul>"; foreach($errors as $err) { $errorMsg .= "<li>{$err}</li>"; } $errorMsg .= "</ul>"; } ?> <html> <body> <div style="color:red;">$errorMsg</div> <form action="" method="post"> First Name: <input type="text" name="fname" value="<?php echo $fname; ?>"><br> Last Name: <input type="text" name="lname" value="<?php echo $lname; ?>"><br> <button type="submit">Check Name</button> </form> </body> </html>
  18. This really isn't the right scenario for preg_match(). Instead use preg_replace to remove all non-numeric characters (i.e. not digits or decimals). //Remove all non numbers/decimals $capitalrequested = preg_replace('#[^\d.]#', '', $_POST['capitalrequestedas']); //If a valid number, round to whole nuber, else set to 0 $capitalrequested = (is_numeric($capitalrequested)) ? round($capitalrequested) : 0; If the value can be negative, then the regular expression would need to be modified to retain the negative symbol.
  19. I think it would be a poor idea to have to manually update that value. If someone makes changes to the data for a user, that value will be out of sync. Instead, create a function to calculate the power. Then, find any instances where you create/update those records. Use the function to calculate the value and use that value when you INSERT/UPDATE the records.
  20. You almost had it right. You would use the record ID, but you don't need JavaScript or anything fancy like that. YOu don't have to pass the event data at all - only the ID. In the code that creates the calendar, you need to create logic for the events to provide a link. You can get fancy and put a link on the TD cells for the days with events, but if you have multiple events for a single day you wouldn't know which one to open. I would simply display the text description for the event in the TD cell as a hyperlink. The URL should look something like this <a href="show_event.php?id=5">Party at the Hard Rock</a> For each event you create the same link, but using the id of that event as the parameter for the URL. Then you just need to build that page (show_event.php) to access that value on the $_GET array, do a DB query to get the event details and display the info.
  21. Show the code you are currently using. Edit: Bah! I see what I did. Just change this $output .= "<td>{$row['id']}</td>\n"; $output .= "<td>{$row['logonname']}</td>\n"; $output .= "<td>{$row['locationname']}</td>\n"; To this: $output .= "<td>\n"; $output .= "{$row['id']}<br>\n"; $output .= "{$row['logonname']}<br>\n"; $output .= "{$row['locationname']}<br>\n"; $output .= "</td>\n";
  22. Well, I'm not going to make any definitive assertions without proof. Not after that awkward dirty dancing incident. *shudder*
  23. OK, so Total Power is a calculated value. And, $totalpower is the calculated value for the current user. So, think about what you were doing. The query would have looked something like SELECT `Username` FROM members ORDER BY 56000 That makes no sense, right? So, if this is a calculated value for each user, you then need to calculate the value for each user and sort by that. With all those fields it won't be a pretty query. In fact, I don't think it is a good idea to "hard-code" the multipliers in the code (i.e. * 70, * 110, * 200). I would put those in a separate table of the database. After looking a your calculations, here is what I have come up with. I can't grantee it will work since I don't have your database, but I did test the logic on a database of mine. Note that you need to change "userid" to whatever the unique id field is called in your table (used in three places) SELECT members.Username, ((calc_table.sum_total/100*30)+calc_table.sum_total) as total_power FROM members JOIN (SELECT userid, (ounit1*50 + ounit2*70 + ounit3*110 + ounit4*200 + ounit5*150 + ounit6*300 + ounit7*500 + ounit8*450 + ounit9*650 + ounit10*350 + ounit11*600 + ounit12*1000 + dunit1*50 + dunit2*70 + dunit3*110 + dunit4*200 + dunit5*150 + dunit6*300 + dunit7*500 + dunit8*450 + dunit9*650 + dunit10*350 + dunit11*600 + dunit12*1000 + baselevel*3000) as sum_total FROM members ) as calc_table ON members.userid = calc_table.userid ORDER BY total_power Another option, would be to change your insert/update scripts to calculate the total power and store that value as part of the record.
  24. NEVER RUN QUERIES IN LOOPS. Database transactions are one of the most expensive operations you can have. I have seen an entire site slow to a crawl because someone tried to generate a report that was built using looping queries. Here is the process you should follow: 1. Query ALL the records for the time period you are going to display. Let's say a month. Order the results by date (ascending). 2. Get the current (i.e. first) record from the result set. 2. Build logic in PHP to build the calendar for the entire month 3. In the logic to create each "day" in the calendar, check if the current record retrieved from the result set is for that current day. If so, use it in the output for that day and get the next record. Also, check if the next record is for the current day and repeat until either there are no more records from the result set or the current record is not for the current day.
×
×
  • 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.