Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Not sure what you mean. You already have a while loop to process all the records in the result set. You will need to provide more information. Are you getting errors? What is the output like now and how do you want it different? You are using a custom class for some of the functionality so we have no idea what $progress6->makeBar() is even doing.
  2. The merits of how best to include "content" has been debated many times that I have seen. There's even several threads on the merits of using single quotes vs. double quotes. Personally, I hate seeing a lot of code that jumps in and our of PHP to output HTML. And, I really like the ability to easily include variables in the output without having to break into and out of PHP tags. So, I typically use php echo statemetns with double quotes. But, that is only int he code where I must generate very dynamic content. I usually have a page or more that develops the majority of the dynamic content as PHP variables. Then I'll use a template type page that is mostly HTML with some placeholders for the content variables. Makes it very easy to "see" the structure of the page without the mess of all the PHP logic. In the end it is primarily a personal preference issue.
  3. To explain the problem: Each time you call the function it is within context of the last time you called the function. When the function returns something it is returning it to the instance from where it is called. So, on the 30th iteration of your original function it was returning the value of $s (a 31 character string). But, it was returning that string to the 'instance' where it was called, which was the 29th iteration of the function. Since the function didn't expect any value to be returned in the else condition the returned value wasn't used. With the change PaulRyan made, the 30th iteration of the function will return the value to the 29th iteration, which will then return that value to the 28th and so on until the value is returned to the original line that called the function - the echo line. Recursive functions have their place, but in many instances there are usually better alternatives. Although the above is obviously just an exercise, for something like that a class would be better suited, IMHO. You can then call the function recursively and apply the changes to a property of the class and not need to continually pass the value to each call of the function.
  4. You had it right the first time. You have a one-to-many relationship between users and venues. You need a third table that will make those associations. You only need two columns: one for the ptdata.id and one for the venopt.id. You don't give much specifics over how you want the SELECT this data to put in a drop down - there could be several scenarios. But, let's say you wanted to get a list of the venues selected by a particular user. You would at least need their user ID. Then it is a simple matter of joining the tables. So, let's assume the new table is called pt_ven_assoc and the fields are called ptdata_id and venopt_id (By the way I tend to give my "ids" unique names instead of just "id" and use the exact same name in the table where it is a primary key and where it is a foreign key. It makes things much easier to keep track of and you can also use USING() to easily JOIN your tables). The query might look something like this: SELECT id, venue FROM venopt JOIN pt_ven_assoc ON venopt.id = pt_ven_assoc.venopt_id WHERE pt_ven_assoc.ptdata_id = $userID
  5. I assume you are entering the data via PHPMyAdmin. If so, you cannot enter a line break into the input field if you use the Insert Record form. Change the field type to "TEXT" instead of VARCHAR and you should be able to enter line breaks
  6. For what purpose are you doing this. There is most definitely a better solution than populating the database with almost a billion entries.
  7. Well, your question aside, you have some problems in the current logic. You already run a query to get the total posts - but you are running a query to get all fields from all records!!! Then only using mysql_num_rows. 1) Only query for the fields you need (i.e. don't use '*' for your select. 2) if you only need the number of rows then use COUNT() in the query so the database doesn't have to get all the data - it will calculate the count for you. There are tons of tutorials on how to implement pagination correctly - there is even one on this site (http://www.phpfreaks.com/tutorial/basic-pagination). You are also not sanitizing the user input and are open to SQL Injection attacks. Plus, you should be using the value of all the records to determine the maximum pages and using that to also validate the user selected page. Anyway, once you have the total records you simply divide that number by the records per page to get the number of pages - of course you need to use ceil() on that value to round up though.
  8. Different email servers use different criteria for detecting spam. It has nothing to do with using the mail() function. The spam filters look at things such as the headers of the email, the subject, and the message itself which includes the structure of the message. Does the message contain links and are they properly formatted, are there links to executables. Are there any "red flag" words in the subject or message. Words related to loans, penis/breast enlargement, Nigerian bankers, etc. etc. could be triggering the spam program. Also, the receiving email server may be doing a reverse lookup based on the "from" address. If you are sending an email as from "me@mydomain.com" but it is actually being sent from the email server myhostdomain.com that could be causing it. There are many things you can do to try and prevent your email from being flagged as spam. But, there are no guarantees. If the methods to circumvent spam filters was public knowledge those filters would become useless since every spammer would employ those methods
  9. This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=346609.0
  10. This is not a PHP issue, it is an HTML/CSS issue. Do not try and design through PHP. Create a flat-file HTML page with some sample data. Tweak the HTML and CSS code until you get the look you want. THEN create the PHP code that will generate the HTML code in the format you want. Moving this to the CSS forum. I suggest you repost the HTML source code that is generated along with the CSS code for the classes used.
  11. Well, you should echo the query to the page to see exactly what it is. We can only guess at what the result is since we don't know the values of "MEMBER_PROFILE_TABLE" or "$MemId". BUt, you are doing this the hard way. You only need ONE query based upon your current logic. Simply run the UPDATE query with an additional parameter on the WHERE clause for 'Group'=4, then check the result of the updated rows to determine the correct response. Also, NEVER use "*" in your select queries unless you actually need all the columns. And NEVER EVER use user input directly in a database query without sanitizing it first. if ($_GET['CODE'] == '2') { $user_id = intval($_GET['memid']); //make the value safe for DB query $query = "UPDATE ".MEMBER_PROFILE_TABLE." SET `Group` = '3' WHERE user_id='{$user_id}' AND `Group` = '4'"; $result = mysql_query($query); if(!$result) { //Only for debugging purposes echo "Query: $query<br>Error: " . mysql_error(); } elseif(!mysql_affected_rows()) { echo "Your Account is already completely Registered.<br><br>"; } else { echo "Congratulations. You are now fully Registered. Click <a href='./index.php?act=login&CODED=0'>Here</a> to Login.<br><br>"; } }
  12. If the data is in a database, then you definitely want to go that route. You don't state what you DB structure is, but I would think you should have one table to hold the basic order info and then an associative table to hold the order details (i.e. the line items). But, you also don't state how you are going to use this value. If you are going to query the DB for the complete order details to display on the page, then you can just calculate the total as you process the line items. However, if you just need a process to display just the order info (not the line items) along with a total, then you should do that with a query using SUM() and GROUP BY.
  13. OK, I tried the last query and am getting the same error - as I said I didn't have the database I used to test the original query to validate it. But, I went back to the first version and it still works. I am on version 5.0.24a so I don't think the version is a problem. Looking at the error message you got I'm wondering, do you have a 'points' column in the "test_teams" table? Here are the details of the table structures I used for testing. CREATE TABLE `test_teams` ( `teamid` tinyint(4) NOT NULL auto_increment, `team` varchar(10) collate latin1_general_ci NOT NULL, `selectiongroup` tinyint(2) NOT NULL, PRIMARY KEY (`teamid`) ) CREATE TABLE `test_team_points` ( `teamid` smallint(10) NOT NULL, `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `points` varchar(10) collate latin1_general_ci NOT NULL ) I'm sure you have more fields than those, but those are the ones that seemed pertinent to your needs. So, there must be something in your table structure that is different that is causing the failure.
  14. Odd, it worked for me. Could be due to different versions of MySQL. try providing the appropriate table name before each field name. I don't have the DB I used to test this on this machine, so I can't be sure, but this should be right (although I don't know if it will solve your problem) SELECT teams.team, sum(points1.points) as total_points, points2.last_five FROM test_teams AS teams LEFT JOIN test_team_points AS points1 ON test_teams.teamid = points1.teamid LEFT JOIN (SELECT ttp.teamid, SUM(dt.points) as last_five FROM test_team_points AS ttp JOIN (SELECT t1.teamid, t1.points, t1.date, COUNT(t2.teamid) AS rank FROM test_team_points t1 LEFT JOIN test_team_points t2 ON t1.teamid = t2.teamid AND t1.date < t2.date GROUP BY t1.teamid, t1.date HAVING rank < 5) AS dt USING (ttp.teamid, dt.date) GROUP BY ttp.teamid) as points2 ON test_teams.teamid = points2.teamid GROUP BY test_teams.teamid
  15. http://dev.mysql.com/doc/refman/5.0/en/any-in-some-subqueries.html OK, not sure what you are getting at. That was my intention. If it was some_value <> any (1, 2, 3) that would ALWAYS result in true, because if you are comparing if one value is not equal to two or more values, the original value could only equal one of the target values at most, so it would always not be equal to N or N-1 values (where N is the number of target values) No, it doesn't. I ran a test as follows: User table userID name 1 One 2 Two 3 Three 4 Four 5 Five 6 Six 7 Seven 8 Eight Battles table voter win lose 1 2 3 1 4 5 So, user 1 has selected users 2, 3, 4, & 5. When I run the query above without the LIMIT clause I get 1, 6, 7, & 8 which are the user IDs that user 1 has not used (I suspect you also want to exclude the user's own ID though). When I use the LIMIT clause I get two values from that set. You seemed to be saying you only wanted to exclude IDs that were not used for both the win and the lose columns. That doesn't make sense. You could have two ids that were both used for lose. If the user gets those two, they cannot make a selection that doesn't create a duplicate entry for user 1 in the lose column.
  16. It would have been VERY helpful if you had given some details about the tables and the fields. I will assume that in your example above you area ctaully storing the ID of the users and not the username. Because, if you are doing otherwise you are doing it wrong. Anyway, the following query will get you two random records that the user has not submitted a vote for. NOTE: Using ORDER BY RAND() will be problematic if you have a LOT of records. If you think you will have a lot of users, then do the research to get random records quickly. SELECT `userID` FROM `users` WHERE `userID` NOT IN (SELECT `win` FROM `battles` WHERE `voter` = '$thisUserID') AND `userID` NOT IN (SELECT `lose` FROM `battles` WHERE `voter` = '$thisUserID') ORDER BY RAND() LIMIT 2
  17. Like I said in my example, you would define different variables as needed. You could either define different variables for different "cases" of the name or you could programatically change the case in the code where those variables are displayed. Example #1 //Include file logic if($site=='red') { $sitenameLowercase = 'red'; $sitenameLowercase = 'RED'; $sitenameSentenceCase = 'Red'; $siteURL = 'myredsitelogo.jpg'; } else { $sitenameLowercase = 'blue'; $sitenameLowercase = 'BLUE'; $sitenameSentenceCase = 'Blue'; $siteURL = 'mybluesitelogo.jpg'; } Then just use those variables in the appropriate places on your pages Example #2 //Include file logic if($site=='red') { $sitename = 'red'; $siteURL = 'myredsitelogo.jpg'; } else { $sitename = 'blue'; $siteURL = 'mybluesitelogo.jpg'; } //Page logic echo "Welcome to the " . ucwords($sitename) . " site."; //Output: Welcome to the Blue site.
  18. Like I said, it all depends on how the data would or could be used. But, most of the time I would simply use mysql_real_escape_string() before storing the data. If I did have a specific purpose where I needed to restrict certain input, then I would implement that as part of the validation logic. If there was something not kosher in the input I would not accept the input and provide an error back to the user. It is never, ever a good idea IMO to modify user input without their knowledge. For example, someone might think they are being smart to strip out any non-numeric characters for a phone number input. But, what if the user used letters in the phone number - which is perfectly valid from a human interpretation. If the phone number was simply for display purposes, then I would let them use letters. But, if the phone number was going to be used by some automated dialing application that only accepted numbers, then I would only allow numbers. There is also another problem with modifying the user input - the database field length. Many processes to modify input to make it safe will increase the character length. So, if you made the input field 20 characters, you might need to make your DB field much bigger to accept the 'escaped' input.
  19. It is very important to ensure user submitted data does not "damage' your site. But, you need to analyze what you are doing and how you are using the data to determine WHEN and HOW you will do that sanitation. For example, you used FILTER_SANITIZE_STRING for all of the values - why didn't you use FILTER_SANITIZE_EMAIL for the email! But, that is really beside the point. You need to be very careful when imposing any arbitrary methods that will actually modify the user input. There are plenty of way to make the input safe without changing the 'intent' of the input. Rule #1 is that you always escape the input before using in a query. But, it gets trickier to determine what validations/escaping you should do for XSS, HTML tags, etc. The approach I almost always take is to simply store the code exactly as the user submitted it. Then when I retrieve the code I will 'escape' it as needed. If I am using the content in a web page I will use either htmlspecialcharacters() or htmlentities() to make it safe to be displayed in the web page. But, you never know how else you may need the data in the future. Maybe an RSS feed, output to an XML file, or ??? So, if you modify the data before you store it you make it difficult, if not impossible, to re-purpose the data for other purposes.
  20. Why do you think you need to use FILTER_SANITIZE_STRING to prevent SQL Injection?
  21. I would take a slightly different approach. Instead of calling the same include() file over and over, have a script that defines a variables or variables (no need to run the same code over and over). Most likely you will really need more than just a single name to be different. You may need to define different images, singular/plural differences, different cases of the name. different URLs, etc. So, have a script that determines the current domain and defines all those variables. Then simply use those variables where you need them. You should be able to use $_SERVER['SERVER_NAME'] to determine the site.
  22. Have you read the manual for those two functions? The information you need is right there http://php.net/manual/en/function.htmlspecialchars.php http://us.php.net/manual/en/function.mysql-real-escape-string.php The manual will do a better job of giving you the basics of those two functions (including their purpose) than we can do in a forum post. if you have a specific question regarding them after reading the documentation, then just post back with your specific question
  23. Ah, yes. That block to close the last row (if needed) should go after the foreach() loop. Right before this comment //Close table
  24. And where is the query. Do you expect us to sift through that code to try and guess what the query is?
  25. Don't know what to tell you, there is no "list" code in there. But, perhaps it has something to do with the classes you are using.
×
×
  • 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.