Jump to content

Psycho

Moderators
  • Posts

    12,159
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. No, that is not the problem. The 0 is to set the index of the first question value to 0 (which is unnecessary). The questions and answers are indirectly "associated" via the parent array IDs. Which is one reason that is a poor implementation. The code he posted works as long as you set $num to the value of one of the available indexes. It is also a poor implementation because the code is using a custom function to randomize the answers instead of just using shuffle. The custom function is maintaining the index association, but it is not even used in the output so it is unnecessay overhead.
  2. I just copies all of the code you just posted and set $num to one of the values in the arrays and it works fine for me. Every time I refresh the page the answers are in a different order. Although that is a pretty poor implementation, IMHO.
  3. Is that how the data is formatted in the current hard-coded array? If so, how do you determine how many posts there are in a sub-category. Also, how are the sub-categories related to the main category - if it is by primary index then each main category could only have one sub-category. Please give exact details about the current format of the hard-coded array and how this data is obtained (from db query?).
  4. ^^ - In total agreement. Store all input in it's "native" format. Only transform it for display purposes at run time: i.e. nl2br(), date(), number_format(), etc.
  5. Furthermore, anything the user is viewing in a web page has already been downloaded to their computer! It's just sitting in their cache. What you are asking for is pointless. It would be like a library allowing people to check out books but trying to prevent them from copying the book. Just not possible. What IS possible is using means such as watermarks on images & video to make it difficult, but not impossible, for others to use your content and pass it off as their own.
  6. Some characters should always be escaped and some only need to be escaped sometimes. But, it doesn't cause a problem to escape a character when it doesn't need to be. So instead of having to put any though into it, I just escape some characters by default. Saves time - plus it makes the code more regression proof. What if some yahoo was modifying the code later and decided to define the pattern with single quotes rather than double quotes? My pattern would keep on working whereas if the single quotes were not escaped it would break. How is that similar? It *looks* like you are trying to match all characters between two single quotes. Which this would be the correct pattern: "%'(.*)'%" However, that will NOT work for what you want. For one it doesn't care where those quotes exist. Two it would not find the text in double quotes which I assume you want also. Third, and most importantly it finds the text from the first single quote to the LAST single quote. Also, preg_match() will stop after the first match instead of finding all matches. If this was your text: <a href='somesite1.com'>Some Site 1</a> <a href='somesite2.com'>Some Site 2</a> The regex above would return this: somesite1.com'>Some Site 1</a> <a href='somesite2.com Because the * modifier is "greedy" - it will match all characters until the last match. You could make it non-greedy by also using the ? after the *: "%'(.*?)'%" But, my understanding is that using that method is not efficient and you should use the method I described above of matching all characters that do not mathc the ending character: "%'([^']*)%"
  7. Here's a simple function for you <HTML> <HEAD> <script> function formatCurrency(fieldObj) { if (isNaN(fieldObj.value)) { return false; } fieldObj.value = '$ ' + parseFloat(fieldObj.value).toFixed(2); return true; } </script> </HEAD> <BODY> <input type="text" name="amount" onchange="formatCurrency(this);" /> </BODY> </HTML>
  8. Here is an explanation of the RegEx pattern: "/<a href=[\'\"]([^\'\"]*)[^>]*([^<]*)/" The pattern first looks for any string starting with "<a href=" Then it looks for a signle or double quote mark. Note, the quote marks need to be escaped using a backslash to indicate it is not the end of the pattern: [\'\"] Then it uses parenthesis to mark mathing text that should be returned. And it matches any character that is NOT a single or double quote ( the ^ indicates not within the square brackets). The asterisk tells it to match as many characters as possible (so it will get all of the text up until the next quote mark.: ([^\'\"]*) Next it mathes every character up until the closing braket for the opening A tag: "[^>]*" Lastly, it captures every character that is NOT a '<' which would presumably be the opening for the closing A tag: "([^<]*)"
  9. There's no way someone can teach you RegEx in a forum post. There are a lot of tutorials out there. Although, I consider RegEx to be one of the more abstract areas of programming and I struggle with it on occasion. So I understand your difficulty. Here is a pattern to get the results you asked about above. I noticed that you had some urls in single quotes and some in double quotes. This will work on both: $text = "<a href='somesite1.com'>Some Site 1</a> <a href=\"somesite2.com\">Some Site 2</a> <a href=\"somesite3.com\">Some Site 3</a>"; preg_match_all("/<a href=[\'\"]([^\'\"]*)/", $text, $matches); print_r($matches[1]); Output: Array ( [0] => somesite1.com [1] => somesite2.com [2] => somesite3.com ) Although, this might prove more useful as it will get the URLs and the text descriptions for the links: <?php $text = "<a href='somesite1.com'>Some Site 1</a> <a href=\"somesite2.com\">Some Site 2</a> <a href=\"somesite3.com\">Some Site 3</a>"; preg_match_all("/<a href=[\'\"]([^\'\"]*)[^>]*([^<]*)/", $text, $matches); print_r($matches[1]); print_r($matches[2]); ?> Output: Array ( [0] => somesite1.com [1] => somesite2.com [2] => somesite3.com ) Array ( [0] => >Some Site 1 [1] => >Some Site 2 [2] => >Some Site 3 )
  10. New and improved verision. I've made it into a function so you only have to call the function with the region name: <?php function getRegionData($region) { $domain = "http://wiki.eveonline.com/"; $url = "{$domain}en/wiki/Category:{$region}_%28Region%29"; $content = file_get_contents($url); //Process the data preg_match( "/<td>Name<\/td><td>\s*([^<]*)/s", $content, $nameMatch); preg_match( "/<td>Average.*?<\/td><td>\s*([^<]*)/s", $content, $avgMatch); preg_match( "/<td>Number of constellations<\/td><td>\s*([^<]*)/s", $content, $constMatch); preg_match( "/<td><a[^>]*>Sovereignty<\/a><\/td><td>\s*<a href=\"([^\"]*)[^>]*>([^<]*)/s", $content, $sovMatch); preg_match( "/<td>Adjacent Regions<\/td><td>\s*<ul>(.*?)<\/ul>\s*<\/td>/s", $content, $regionsList); preg_match_all( "/<li>\s*<a href=\"([^\"]*)[^>]*>([^<]*)/s", $regionsList[1], $regionsMatch); $appendDomain = create_function('&$item, $key, $domain', '$item = $domain.$item;'); array_walk( $regionsMatch[1], $appendDomain, $domain ); //Add data to array $regionData = array(); $regionData['name'] = trim($nameMatch[1]); $regionData['average'] = trim($avgMatch[1]); $regionData['constellations'] = trim($constMatch[1]); $regionData['sovereignty'] = trim($sovMatch[2]); $regionData['sovereignty_url'] = $domain . trim($sovMatch[1]); $regionData['regions'] = array_combine($regionsMatch[2], $regionsMatch[1]); return $regionData; } //Call function with region name $regionData = getRegionData('Everyshore'); echo "<pre>\n"; print_r($regionData); echo "\n<pre>"; ?>
  11. OK, here you go. This script will pull all the values from the table on that page and dump into an associative array $url = 'http://wiki.eveonline.com/en/wiki/Category:Aridia_%28Region%29'; $content = file_get_contents($url); $data = array(); //Process the data preg_match( "/<td>Name<\/td><td>\s*([^<]*)/s", $content, $nameMatch); preg_match( "/<td>Average.*?<\/td><td>\s*([^<]*)/s", $content, $avgMatch); preg_match( "/<td>Number of constellations<\/td><td>\s*([^<]*)/s", $content, $constMatch); preg_match( "/<td><a[^>]*>Sovereignty<\/a><\/td><td>\s*<a href=\"([^\"]*)[^>]*>([^<]*)/s", $content, $sovMatch); preg_match( "/<td>Adjacent Regions<\/td><td>\s*<ul>(.*?)<\/ul>\s*<\/td>/s", $content, $regionsList); preg_match_all( "/<li>\s*<a href=\"([^\"]*)[^>]*>([^<]*)/s", $regionsList[1], $regionsMatch); //Add data to array $data['name'] = trim($nameMatch[1]); $data['average'] = trim($avgMatch[1]); $data['constellations'] = trim($constMatch[1]); $data['sovereignty'] = trim($sovMatch[1]); $data['sovereignty_url'] = trim($sovMatch[2]); $data['regions'] = array_combine($regionsMatch[2], $regionsMatch[1]); echo "<pre>\n"; print_r($data); echo "\n<pre>"; Output: Array ( [name] => Aridia [average] => 0.244786045 [constellations] => 11 [sovereignty] => Amarr Empire [sovereignty_url] => /en/wiki/Category:Amarr_Empire_%28Faction%29 [regions] => Array ( [solitude] => /en/wiki/Category:Solitude_%28Region%29 [Khanid] => /en/wiki/Category:Khanid_%28Region%29 [Fountain] => /en/wiki/Category:Fountain_%28Region%29 [Delve] => /en/wiki/Category:Delve_%28Region%29 [Kor-Azor] => /en/wiki/Category:Kor-Azor_%28Region%29 [Genesis] => /en/wiki/Category:Genesis_%28Region%29 ) )
  12. This will get the first three values from the table. I'd do the other two but I have a meeting preg_match( "/<td>Name<\/td><td>\s*([^<]*)\s*/", $content, $nameMatch); $name = $nameMatch[1]; preg_match( "/<td>Average.*?<\/td><td>\s*([^<]*)\s*/", $content, $avgMatch); $avg = $avgMatch[1]; preg_match( "/<td>Number of constellations<\/td><td>\s*([^<]*)\s*/", $content, $constMatch); $contellations = $constMatch[1];
  13. There are better methods that will work with this and be less error prone. I think using regular expressions and/or the DOM XML parser would make more sense. For example, to get the Name you could do this: $url = "[url=http://wiki.eveonline.com/en/wiki/Category:Aridia_%28Region%29]http://wiki.eveonline.com/en/wiki/Category:Aridia_%28Region%29[/url]"; $content = file_get_contents($url); preg_match( "/<td>Name<\/td><td>\s*([^<]*)\s*/", $content, $nameMatch); $name = $nameMatch[1]; echo $name;
  14. Just to add to ialsoagree, storing the ids as a comma separated list defeats the who purpose of having a relational database. For a normalized database you would need three tables: tbl_cart tbl_services tbl_cartSvcs The first tables stores just the cart information, the second stores the service types and the third stores the associations between the carts and services. You then access/manipulate the information using appropriate JOINs. By the fact that you are gathering the comma separated list, and then looping through it to do additional queries leads me to believe you aren't familiar or comfortable using JOINs. You should never do queries within loops unless there is absolutely no other way (and that is almost never the case). Whit small databases/usage you will not notice much. But as soon as you start putting more records and more users on the system these looping queries will bring your application to a crawl. I suggest looking for some tutorials on MySQL JOINs
  15. Right, if users can be assigned to a department, but not a sub-department, then you pretty much need separate associative tables. However, that is based upon the fact that departments and sub-departments are logically different objects. For example, if departments records need to store information such as department head, office number, phone, etc. and sub-department records need to store totally different information you need those separate tables. However, based upon TapeGun007's last post that is apparently not the case and he will be storing the exact same information for departments and subdepartments, so his approach of one table for both should work as well. Here is the query I would use with a single table for departments and sub departments as illustrated above: SELECT u.User_Name as name, d.Dept_Name as department, dp.Dept_Name as parent FROM Users u JOIN User_Dept ud ON ud.User_ID = u.User_ID JOIN Departments d ON d.Dept_ID = ud.Dept_ID JOIN Departments dp ON dp.Dept_ID = d.Parent_Dept_ID It all depends on whether departments and sub-departments should be logically different entities. If you are capturing all the same information for both, then the three tables will suffice.
  16. There wre a couple of minor typos, but you should have received errors on them. Anyway, I have made those corrections and also added a "basic" form to the bottom. If you merge the form and your processing code in this manner you can repopulate the form with what the user entered when there is a validation error. Give it a try <?php if (isset($_POST['submit'])) { $to = "ainurdesign@gmail.com"; //Trim all the values foreach($_POST as $key => $value) { $_POST[$key] = trim($value); } //Check for missing data $errors = array(); if(empty($_POST['Email'])) { $errors[] = "You have not entered an email, please return and try again"; } if(empty($_POST['Company'])) { $errors[] = "You have not entered a company name, please return and try again"; } if(empty($_POST['Contact'])) { $errors[] = "You have not entered a contact name, please return and try again"; } if(empty($_POST['Phone'])) { $errors[] = "You have not entered a phone number, please return and try again"; } if(empty($_POST['Street'])) { $errors[] = "You have not entered a street address, please return and try again"; } if(empty($_POST['City'])) { $errors[] = "You have not entered a city, please return and try again"; } if(empty($_POST['State'])) { $errors[] = "You have not entered a state, please return and try again"; } if(empty($_POST['Zip'])) { $errors[] = "You have not entered a zip code, please return and try again"; } if(empty($_POST['Interest'])) { $errors[] = "You have not entered your selection for drop-shipping or wholesale, please return and try again"; } if(empty($_POST['Agree'])) { $errors[] = "You have not selected Yes to the agreement, please return and try again"; } if (count($errors)>0) { //There was missing data echo "The following errors occured<br>\n"; echo "<ul>\n"; foreach($errors as $error) { echo "<li>{$error}</li>\n"; } echo "</ul>\n"; } else { //No validation errors, create the email content //Data fro email #1 $subject1 = "Retailer Form Information"; $headers1 = "From: $from"; $body = "Wholesaler info is as follows:\n\n"; $bodyfields = array('Company', 'Contact', 'Email', 'Phone', 'Street', 'City', 'State', 'Zip', 'Interest', 'License', 'Business', 'URL', 'Comments', 'Agree'); foreach($bodyfields as $field) { $body .= sprintf("%20s: %s\n", $field, $_POST[$field]); } //Data for email #2 $subject2 = "Thank you for contacting GrowFrame"; $autoreply = "Thank you for contacting us. Someone will get back to you as soon as possible, usually within 48 hours. If you have any immediate questions, please feel free to call our Sales Manager, Traci Elliott, at 1 (805) 407-3471."; $headers2 = "From: Trevor @ GrowShow/GrowFrame.com"; //Send the emails $send = mail($to, $subject1, $body, $headers1); $send2 = mail($_POST['Email'], $subject2, $autoreply, $headers2); if(!$send || !$send2) { //Errors in sending the emails echo "We encountered an error sending your email, please confirm your address is correct and try again."; } else { //No errors returned header( "Location: http://thegrowframe.com/return.html" ); exit(); } } } ?> <html> <body> <form name="" action="" method="POST"> * Email: <input type="text" name="Email" value="<?php echo $_POST['Email']; ?>" /><br /> * Company: <input type="text" name="Company" value="<?php echo $_POST['Company']; ?>" /><br /> * Contact: <input type="text" name="Contact" value="<?php echo $_POST['Contact']; ?>" /><br /> * Phone: <input type="text" name="Phone" value="<?php echo $_POST['Phone']; ?>" /><br /> * Street: <input type="text" name="Street" value="<?php echo $_POST['Street']; ?>" /><br /> * City: <input type="text" name="City" value="<?php echo $_POST['City']; ?>" /><br /> * State: <input type="text" name="State" value="<?php echo $_POST['State']; ?>" /><br /> * Zip: <input type="text" name="Zip" value="<?php echo $_POST['Zip']; ?>" /><br /> * Interest: <input type="text" name="Interest" value="<?php echo $_POST['Interest']; ?>" /><br /> License: <input type="text" name="License" value="<?php echo $_POST['License']; ?>" /><br /> Business: <input type="text" name="Business" value="<?php echo $_POST['Business']; ?>" /><br /> URL: <input type="text" name="URL" value="<?php echo $_POST['URL']; ?>" /><br /> Comments: <input type="text" name="Comments" value="<?php echo $_POST['Comments']; ?>" /><br /> * Agree: <input type="text" name="Agree" value="<?php echo $_POST['Agree']; ?>" /><br /> <button type="submit">Submit</button><br /><br /> * required fields <input type="hidden" name="submit" value="true" /> </form> </body> </html>
  17. Well, there are still some unanswered questions. Can a user be associated with a department BUT not associated with any sub-department? If the answer is no then you would need the following tables: - Users - Departments - Sub_Departments - Dept_SubDept (associate sub departments to departments) - User_Sub_Dept (associate users to sub departments) In that example, since users are associates to sub-departments and sub-departments are associated with departments, you don't need a table to associate users to departments as it is inferred. BUt, in my example in the previous post that was only about users and departments, here is what the query would look like to get a list of users and their associated departments using the three tables: SELECT u.User_Name, d.Dept_Name FROM Users u JOIN User_Dept ud ON ud.User_ID = u.User_ID JOIN Departments d ON ud.Dept_ID = d.Dept_ID The results would look like this User_Name | Dept_Name ====================== Bob Music Bob History Jane Music Alex Business
  18. Your HTML is all messed up, so there is no telling how the browser will render it. Here are just a few problems I saw before I stopped looking: 1. You have DIV tag between an opening TABLE tag and an opening TR tag. You cannot put content inside anything other than a TD/TH tag within a table. 2. There is a TD with nothin in it except SCRIPT code. There are so many embedded tables and the code is not formatted to show logical structure so it is really difficult to follow. My guess is that there are some problems with the table structure and/or trying to apply the class to a div in-between table objects is causing the problem. Assign the noprint class on the "tables" you don't want printed. Well, ideally you would get rid of tables for the layout entirely (except the table of records) and use CSS for layout. Sorry, but I just don't have the time to dig through all of that mess. When I am creating a page such as that I will create an empty page: just a template of the sections: header, menu, content, footer, etc. Then before I actually start putting content into those sections, apply the styles and such. Following that appraoch it would be easy to apply the noprint class to a particular section. Then start adding the content.
  19. No, it is completely different. You suggested adding two fields to the user table for department and sub-department. However, as per the requirements there is a many-to-one relatinship between users and departments/sub-departments. So, you need a secondary table to associate the users with 0 to many departments/sub-departments. That is database design 101, read up on database normalization. The suggestion I made was totally different. The current structure has users and departments tables (where the users are associated with departments via a foreign key in the departments table. However, this is not normalized as the department names are duplicitive data. The Departments should be unique records and have their own table. So, you would use a third table to associate departments to users. This gives a greater flexibility over the data. For example, if you need to change a department name, you just change one record in the Department table. The current design would require you to update all the association records because the department name is assigned to each user not a foreign key: Here is an example structure of what I am talking about Table: Users (One record for each user) User_ID | User_Name 1 Bob 2 Jane 3 Alex Table: Departments (One record for each Dept) Dept_ID | Dept_Name 8 Music 9 Business 10 History Table: User_Dept (Record for each User/Dept assoc) User_ID | Dept_ID 1 8 1 10 3 9 2 8 You should be able to see that the user "Bob" is associated with both Music and History.
  20. In the original description TapeGun007 declared that the user would be associated with mutiple departments and multiple sub-departments. Trying to jam the department associations into the user table would be a very poor method. The only change *I* would make is to have separate tables for the Department and Sub-department names. Then in the current tables you only need the user ID and the department/sub-department ID to make the association. But, let's go with what you have: One thing that does not make sense is that there is no association between the sub-departments and either the department or the user. Isn't there a Department_ID field in the Sub_Department table to identify which sub-departmtents belong to which department? Also, should the sub-departments be associated with the users or is it assumed that a user is associated with all the sub-departments of any departments they are associated with?
  21. That is not the HTML output - that is the PHP script. Run the script by pointing your browser at the page to load it from the web server. Then get the source of the rendered page. As I stated your problem is something to do with the HTML code and trying to figure out exactly what your HTML would look like while reading all the echo statemetns will be a pain in the a**. Although you state you only want the table to be in the printout, so why are you applying the noprint class to the div that contains the table? <div class="noprint"> <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 class="th-a">
  22. First off, have you tested the query in phpmyadmin to ensure it is returning results? For testing purposes you should always be validating that your query is running correctly and, if not, checking the errors. You're not even checking for errors. Also, whay are you querying fields and using AS to give them the same name they already have? You only need to do that if you are pulling two fields with the same name so thay have unique names in the result set. Or, you might do that if the value is being used in the script for a different purpose than the name would apply. In this query it is just making it difficult to read. however there is an error in your query. You are pulling three values in the SELECT clause and there is no comma between the second and third values. Here is what I would suggest $query = "SELECT ecb.bookingdate, ecb.location, els.name FROM `efed_content_booking` AS ecb INNER JOIN `efed_list_shownames` AS els ON ( ecb.event_id = els.id ) WHERE ecb.status_id = '3' ORDER BY ecb.bookingdate LIMIT 5"; So, now that you have a query that is more likely toi work, you should include proper error handling. This is just an example: $result = mysql_query($query); if (!$result) { echo "The query failed!<br /><br />"; echo "Query:<br />{$query}<br />"; echo "Error:<br />" . mysql_error(); } else if (mysql_num_rows($result)==0) { echo "No results returned"; } else { //Process and display the results } Even if the query works now, try changing it so it will fail and you can see the error details that will be displayed. By the way, this IF statement will always return true. A single equal sign is used for an assignment. So, since the processor will have no problem assinging a 0 to the variable $rows it will always return true. You need to use double equal signs for comparison. if ($rows = 0)
  23. There is definitely something wrong with your query. SELECT ecb.status_id AS statusid, ecb.bookingdate AS bookingdate, ecb.location AS location FROM `efed_content_booking` AS ecb INNER JOIN `efed_list_shownames` AS els ON ecb.event_id = els.id WHERE ecb.event_id = '$id' AND ecb.status_id = '3' ORDER BY ecb.bookingdate LIMIT 5 You are joining the `efed_list_shownames`, but you are not using it - at all. There are no values from that table selected in the SELECT clause, there are no values used by that table in the WHERE clause and no values from that table in the ORDER by clause. In other words, that JOIN does absolutely nothing. There are also other problems in the logis to process/display the query results. But, assuming this is a homework problem I don't want to provide too much help.
  24. The logic is messed up if(!$result = mysql_query ($query)) if(mysql_num_rows($result) == 0){ Basically, that is saying IF the query fails then check IF the number of results equals 0. If the query fails you can't check if any results were returned. You need to fix that logic as well as fix your query (which is failing).
  25. Your problem is an HTML/CSS one, not a PHP problem (moving to appropriate forum). It is difficult for me to understand what/where the problem is. Please post the HTML output of the script and I can help further.
×
×
  • 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.