HartleySan
Members-
Posts
3047 -
Joined
-
Last visited
-
Days Won
243
Everything posted by HartleySan
-
If the line isn't already uncommented after installing PHP, then yes, you need to uncomment that line to use PHP with your Apache installation. That is the main line in your Apache config file that enables PHP. This might help: http://stackoverflow.com/questions/69768/how-do-you-configure-the-apache-server-which-ships-mac-os-x
-
Hello and welcome to the forums. mod_rewrite is a tricky thing that causes a lot of people problems. For testing purposes, start of with something very simple (e.g., RewriteRule a.html b.html), and make sure that works. If it does, then you know the problem is with your regexes. If it doesn't, then you know the problem is with your setup/configuration.
-
There are two ways to add null via a prepared statement: Dynamically generate the query, and add NULL as necessary; or Assign null to a variable, and then bind the variable. For example, your query could be: $query = "UPDATE pages SET cat_p_id = ?, tag_p_id = ?, user_id = ?, status = ?, title = ?, summary = ?, ingredient = ?, recipe = ?, tips = ?, filename = NULL, date_updated = NOW() WHERE page_id = $page_id;"; Or, you could set up the $file_name variable as follows: $file_name = $file_name ? $file_name : null; That make sense? As a side note, you may want to use a question mark for page_id as well, if $page_id is user-provided.
-
I don't think it's a percentage thing so much as a what-does-the-scenario-call-for thing. Switch statements are generally preferable when you have a bunch of string or number values that a variable can be, and you want to switch up the behavior based on what the current value is. If statements are generally more for making complex comparisons that aren't simply, "Is this variable equal to this value?" As a side note, an array or object (i.e., hash table) can often be used as a more efficient replacement of a switch statement. Please Google it for more details.
-
I know this isn't the case, but let's say that hypothetically the combination of m_id and type were always unique. That being the case, you can set up a unique index that spans those two columns (please see the documentation for how to create multicolumn indexes), and then you're SELECT queries would be like the following: SELECT * FROM listings WHERE m_id = ? AND type = ?; That make sense? With that said, if you know the l_id, which is the primary key, that will always be a quicker select because it's the primary key and essentially just a key-value lookup, but depending on how the table data is used in relation to other tables/data, the multicolumn index without the l_id column might make more sense.
-
That looks good, Cofa. My one comment is that for the listings table, if m_id combined with one or more other columns in the table is always unique, you can set that as your unique index, and probably get rid of the l_id column. With that said though, depending on how you're accessing the data, the l_id column could be beneficial. Well, if it works for ya, no complaints.
-
Your design is correct, but you are incorrect in that duplicate keys will be created. For example, let's imagine the following users and courses tables: users 1 Bill 2 Pam 3 Steve courses 1 Intro to Web Development 2 Advanced Web Development 3 Basket Weaving 4 Basketball Now, let's say that Bill wants to take both Intro to Web Development and Basketball. Then we'd enter the following two entries into the users_courses table (where the first number is the user ID and the second is the course ID): 1 1 1 4 Even though the user ID is the same, because the combinations of the user ID and course ID are unique, we're fine. In other words, DB integrity has been preserved. With the above design (i.e., your design), you could then run the following query to get all courses that Bill is taking: SELECT course_name FROM courses, users_courses, users WHERE courses.course_id = users_courses.course_id AND users_courses.user_id = users.user_id AND users.user_id = 1; Really, the important thing to note is that user_id by itself cannot be a primary key for the users_courses table. The "key" is to make a multicolumn key, which is very common. That make sense?
-
There's obviously something funky going on, so I think that further digging is required. As a first step, I'd turn error handling on, and then start echoing lots of info to the screen to try and discover what is wrong. I'd also start executing queries directly on the DB (as opposed through PHP), and see if you can find anything that way.