Jump to content

Nethox

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Everything posted by Nethox

  1. Ok I figured out what doesn't work and it seems to be an AR issue.. I redid the mysql syntax manually and adding brackets where required.. AR does not seem to do that automatically for some reason. Here is the appropriate SQL for those looking for an answer to this problem. SELECT * FROM (`videos`) WHERE `category` IN ('6', '7', '8', '9', '11', '12', '13') AND (`video_name` LIKE '%test%' OR `username` LIKE '%test%' OR `description` LIKE '%test%' OR `tags` LIKE '%test%')
  2. Need help with Active Record: using where_in and like and or_like at the same time does not work out... Here is my code : <?php // Making sure categories are visible $visible_cats = $this->get_all_visible_cats(); $cat_array = array(); foreach($visible_cats as $cat) { $cat_array[] = $cat['id']; } $match = $this->input->post('search'); $clean_match = $this->security->xss_clean($match); $this->db->like('video_name',$clean_match); $this->db->or_like('username',$clean_match); $this->db->or_like('description',$clean_match); $this->db->or_like('tags',$clean_match); $this->db->where_in('category', $cat_array); $query = $this->db->get('videos'); $videos = $query->result_array(); ?> and this is the get_all_visible_cats() method (which works very well in other instances where I'm using where_in but not like and or_like at the same time) <?php function get_all_visible_cats() { $this->db->select('id, category'); $this->db->where('visible', 1); $query = $this->db->get('categories'); $categories = $query->result_array(); return $categories; } ?> Here is the SQL query that it generates: <?php SELECT * FROM (`videos`) WHERE `category` IN ('6', '7', '8', '9', '11', '12', '13') AND `video_name` LIKE '%test%' OR `username` LIKE '%test%' OR `description` LIKE '%test%' OR `tags` LIKE '%test%' ?> In another method that I have, I use it like this and it works perfectly: <?php // Making sure categories are visible $visible_cats = $this->get_all_visible_cats(); $cat_array = array(); foreach($visible_cats as $cat) { $cat_array[] = $cat['id']; } // db query (id needs to be last for array_pop to work at the end) $this->db->select('thumbnail, video_name, description, category, views, date, username, tags, id'); $this->db->order_by("date", $sort); $this->db->where_in('category', $cat_array); $query = $this->db->get('videos', $num, $offset); $videos = $query->result_array(); ?> Any help is appreciated! Thank you. I forgot to mention what doesn't work. The like() and or_like() functions work well, I get the search results correctly. What doesn't work is the where_in.. It gives me all categories including the ones that are not even in the array (see SQL query up here, even though '10' is not in the array, it returns rows with category 10...) The last bit of code that I posted does not return these non-visible categories.. That is the goal but I have to use like and or_like for my search in this case...
  3. Hi, I'm looking to create a PHP script that converts video files to MP4, WebM and OGG but I don't know where to start. I've been searching on google and on these forums for that type of information but I didn't find anything. Is there any website or PHP library/framework that I should look at in order to find that kind of information? Any help is appreciated!
  4. Thanks for all the help, I've fixed everything following your tips!
  5. Hi, I have a small CMS I coded and developped on my local WAMP server and everything worked fine but when I decided to export everything to my hostgator server I realized that the constants I define in some of my includes are not being defined.. Here is one of the errors I get : Fatal error: require_once() [function.require]: Failed opening required 'LIB_PATHDSdatabase.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/nethox/public_html/photo_gallery/includes/photograph.php on line 2 You can see that LIB_PATH is not defined and even the .DS. is not working.. Here is a sample of the code I made : <?php // Defining core paths // Defining them as absolute paths to make sure that require_once works as expected // DIRECTORY_SEPARATOR is a PHP pre-defined constant // (will do \ for Windows, / for Unix) defined('DS') ? null : define('DS', '/'); defined('SITE_ROOT') ? null : define('SITE_ROOT', 'http://www.lemontree-designs.com'.DS.'photo_gallery'); defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.'/includes'); defined('LOG_PATH') ? null : define('LOG_PATH', SITE_ROOT.DS.'logs'); defined('PUBLIC_AREA') ? null : define('PUBLIC_AREA', 'http://www.lemontree-designs.com'.DS.'photo_gallery'.DS.'public'); // Load config file first require_once(LIB_PATH."/config.php"); // Load basic functions next so that everything after can use them require_once(LIB_PATH.DS."functions.php"); // Load core objects require_once(LIB_PATH.DS."session.php"); require_once(LIB_PATH.DS."database.php"); require_once(LIB_PATH.DS."pagination.php"); // Load database-related classes require_once(LIB_PATH.DS."user.php"); require_once(LIB_PATH.DS."photograph.php"); require_once(LIB_PATH.DS."comment.php"); ?> Any help is appreciated! EDIT : For the sake of debugging, I've changed the defined value of DS to '/' instead of DIRECTORY_SEPARATOR to see if it's what caused an issue..
  6. Hey guys, this is just a general question. I read about late static binding and started developing with it on my local server but I noticed that hostgator still runs on 5.2.. Should I use late static binding? (im planning to code an open source CMS)
  7. I'm not sure exactly of what you're trying to do but why don't you put both buttons in the elseif? Wouldn't it show both buttons then?
  8. ROFL, would never have guessed that... Thanks alot you saved me alot of time!
  9. Hey guys. I keep getting this error and I can't find what's wrong with the SQL syntax. I do know that you're not supposed to put single quotes around integers but I don't think it's what's causing the issue. I made a script that echoes the SQL syntax when there's an error for debugging : Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod) VALUES ('', 'nethox2', '89671260714cbd0eff69a9b6e0ae4c45b2efd67a', 'max', '' at line 1 Last SQL query: INSERT INTO users (id, username, hashed_password, first_name, last_name, admin, mod) VALUES ('', 'nethox2', '89671260714cbd0eff69a9b6e0ae4c45b2efd67a', 'max', 'lab', '1', '0')
  10. Can you post the new code? I'm not sure where exactly you've inserted your user verification script.
  11. Alright, well I already understand the basics of OO PHP and MVC so I think I already have a grasp on how frameworks work. I'll just have to learn the methods/controllers I guess. Thanks!
  12. Thank you, Thorpe. I've read the post. I understand the role a framework can play into programming but how much time does one have to put into learning a framework and using it efficiently? Do you want me to ask this on that other topic?
  13. Hi, I recently finished some online PHP courses from lynda.com (basic php + OOP) and I'm planning to code a whole advanced opensource CMS. I know I have the capabilities to do it but I read that using a framework can be very benificial. I've been looking at codeigniter and it looks great but I'm wondering if it's worth investing my time into learning. How long (hours) does it take to learn how to use a framework such as codeigniter and is it worth investing my time? Should I just stick to using snippets and coding the rest myself? Thanks for any input.
  14. $name1 .= "<br>Name is empty."; $email1 .= "<br>Email is empty."; $message1 .= "<br>User Message is empty."; if(isset($_POST['submit']) && trim($_POST['email']) != $email1 && trim($_POST['name']) != $name1 && trim($_POST['message']) != $message1) { $emailconfirm = $_POST['emailconfirm']; $name = trim($_POST['name']); $visitor_email = trim($_POST['email']); $user_message = trim($_POST['message']); if(empty($name)){ $name1 .= "<br>Name is empty."; } if(empty($visitor_email)){ $email1 .= "<br>Email is empty."; } if(empty($user_message)){ $message1 .= "<br>User Message is empty."; } I think something like this would do it. EDIT: Well actually you'd need to change the name of the variables at the top so they don't appear in the form lol...
  15. did you make your query method static? if so I think you need to call it like this sql::query() instead (assuming it IS part of a class) EDIT : Also, I think you should change your query to : $q = "SELECT COUNT(id) AS user_exists FROM `mp_users` WHERE uid=".$uid." LIMIT 1;";
  16. you need a table with : id (auto_increment) uid (user id) pid (post id, video id, whatever the item is) ip (ip address of the user, so no one can make multiple accounts to like/dislike) When a user clicks "like" you need to record his id + the id of the item he liked + his IP and put that in the DB to fetch all the things that a user has liked, you do an SQL query with WHERE uid = $user_id and with a loop echo everything he liked. to fetch all the "likes" or "dislikes" on an item you do WHERE pid = $item_id with a "count" function to have the number. and you make an IF statement that detects if ($current_user_id == $db_id || $current_user_ip == $db_ip) to make sure he didnt already vote that's the basic approach of doing it. EDIT: I guess you also need to remove the "like" if that same user decides to change his vote to "dislike", keep that in mind too. You'll have to do an SQL query removing his like from the "likes" table and an SQL query adding the dislike to the "dislikes" table. You'll have to check that in the processing part of your PHP (if he's already voted like or dislike).
  17. Im not sure how you coded or which variables you've been using but here is an example of a code I made for a photo gallery that displays images in a simple div from left to right. <?php foreach($photos as $photo): ?> <div style="float: left; margin-left: 20px;"> <a href="view.php?id=<?php echo $photo->id; ?>"> <img src="<?php echo $photo->image_path(); ?>" width="200" /> </a> <p><?php echo $photo->caption; ?></p> </div> <?php endforeach; ?> Just change the variables where there are echos to whichever variables you're using. I'm using OOP so my variables appear as $photo->id so perhaps yours would be a simple $id instead.
  18. What do you get if you try this : $sql="SELECT * FROM updates_all WHERE id='$subscripPID' ORDER BY querydate DESC LIMIT 1"; $rs=mysql_query($sql); while($row=mysql_fetch_array($rs)) { echo $row['member'].'<br>'; echo '<hr>'; //} //$sql_ups = "SELECT * FROM updates_all "; //$rs_ups = mysql_query($sql_ups); //while($rowups = mysql_fetch_array($rs_ups)) { $id = $row['id']; //if (in_array($id, $subscripPID)){ echo $row['member'].' - '; echo $row['id']; echo ' '.$row['date_time'].' | '.$row['querydate']; echo '<br />'; //} }
  19. If by making PHP "secret" you mean hiding it from the end users then no worries, PHP is pre-processed so once your page loads if someone tries to see the source they won't see any PHP, just HTML. If you mean removing the processing part of the PHP from that file, then a simple require_once would suffice. Just put all that processing PHP in another file and save it, for example, processing.php and then on the form page at the beginning add this : <?php require_once('processing.php'); ?>
  20. EDIT : Actually I think I found a much better solution, lemme work on it. EDIT2 : Try changing this line : $sql_ups = "SELECT * FROM updates_all ORDER BY querydate DESC"; with this : $sql_ups = "SELECT * FROM updates_all ORDER BY querydate DESC LIMIT 1";
×
×
  • 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.