-
Posts
261 -
Joined
-
Last visited
Everything posted by Stefany93
-
Hello folks, I got married, so I had to change my website, since I changed my last name and the location, hehe. Here it is -> www.stefanynewman.info Please tell me what you think. I also made it responsive, so if you can also check it on your mobile phones, I will be very grateful. Thank you very much in advance to anyone to checked it out!
-
Moving from Java to PHP .... A good career move?
Stefany93 replied to venkatdabri's topic in Miscellaneous
+1. The more languages you know, the more valuable you will be. -
Howdy colleagues, I got married in the US, and obviously now I am living here. It is a very nice country I am wondering, how do my fellow freelancers handle the IRS stuff? For example, say I have a client who wants a website and I quote 500$ for the website. I receive the 500$ and then what? Some people have told me that you just need to declare the money you receive as a freelancer four times per a year to the IRS and pay some % of taxes on them. Is this what you guys do? Also, to be a freelancer from home, do I need a special permit or would my work permit would be enough? Many Thanks for you help!
- 1 reply
-
- freelancer
- usa
-
(and 1 more)
Tagged with:
-
Also, this is cleaner: while ($row_first = mysqli_fetch_assoc($result_first)){ extract($resut_first); // Your other code here } That way the keys of the assoc array will become variable names without needing to set them each time with $var = $result_first['var']; The extract function is awesome
-
Yeah dude, what are you trying to accomplish? if you want to put some vars to global you don't need a func for that o_O
-
PHP PDO how to bind values to varibale contains concatenated string
Stefany93 replied to kslakhani's topic in PHP Coding Help
All I see is a big ass query. In PDO Prepared Statements, you bind the values separated with bindParam or bindValue. It is unclear what you are trying to accomplish could you give more details? -
Doctrine fetches 160 results from a table when 3 are present
Stefany93 replied to Stefany93's topic in Third Party Scripts
Solved it. Apperantly, Doctrine stores all the queries it makes in the variable that made it, in my case protected $queryBuilder; Thats why it displays so many rows. I executed the displayComment function before DisplaySIngle Post and again, the single post ones had too many rows, since it memorized the executed stuff from displayComment So, what I did was to mimic the behaviour of $queryBuilder into a method inside the class like this: public function newQuery() { return $this->queryBuilder = $this->db->createQueryBuilder(); } So every time we call $query_Builder, it gets $this->db->createQueryBuilder(); brand new, like this: public function displayComment() { $row = []; $query = $this->newQuery() ->select('*') ->from('reactions') ->where('topic_id = '.$this->topicId) ->execute(); // echo $sql=$query->getSQL(); while($row = $query->fetch(PDO::FETCH_ASSOC)) { $row2[] = $row['id']; } var_dump( $row2 ); } And the whole Posts.php class: <?php class Posts { protected $db; protected $queryBuilder; protected $topicId = 1; public function __construct($db) { $this->db = $db; } public function newQuery() { return $this->queryBuilder = $this->db->createQueryBuilder(); } public function listTopics() { $query = $this->queryBuilder ->select('posts_id, posts_title, posts_date, author_id') ->from('posts') ->where('posts_categories_id = 1') ->execute(); return $query->fetchAll(); } public function countComments() { $query = $this->queryBuilder ->select('comments_id') ->from('comments') ->where('comments_topic_id = 1') ->execute(); return $query->fetchAll(); } public function displaySingleTopic() { $query = $this->newQuery() ->select('*') ->from('posts') ->where('posts_id = '.$_GET['id']) ->execute(); return $query->fetchAll(); } public function insertComment($comment_data) { // extract($comment_data); $user_id = 1; $query = $this->newQuery() ->insert('reactions') ->values( array( 'comment' => '?', 'user_id' => '?', 'topic_id' => '?', 'date_posted' => "STRFTIME('%s','now')" ) ) ->setParameter(0, $comment) ->setParameter(1, $user_id) ->setParameter(2, $this->topicId) ->execute(); } public function displayComment() { $row = []; $query = $this->newQuery() ->select('*') ->from('reactions') ->where('topic_id = '.$this->topicId) ->execute(); // echo $sql=$query->getSQL(); while($row = $query->fetch(PDO::FETCH_ASSOC)) { $row2[] = $row['id']; } var_dump( $row2 ); } } Remember people, always use a fresh variable for multiple queries if you are using the QueryBuilder of Doctrine DBAL. @requinix, many thanks for your help. -
Doctrine fetches 160 results from a table when 3 are present
Stefany93 replied to Stefany93's topic in Third Party Scripts
Thank you for the reply. Yes, I went to PhpLiteAdmin, and it showed three rows with the above query. The spooky thing is, that even if it is a bug of Doctrine, why the same query works excellent with the posts table but freaks out with the reactions one? Maybe you are right, Doctrine internal bug. Idk what to do, tho. -
Please note this is a DEV version, so I know there are security glitches. I am currently developing it. Okay, so I have this DB table reactions and I want to fetch all the records inside that match a certain topic_id column. I am using Doctrine DBAL I am using SQLite as a DB. So I wrote this code: public function displayComment() { $row = []; $query = $this->queryBuilder ->select('*') ->from('reactions') ->where('topic_id = '.$this->topicId) ->execute(); // echo $sql=$query->getSQL(); while($row = $query->fetch(PDO::FETCH_ASSOC)) { $row2[] = $row['id']; } return $row2; } I set $topic_id to always equal 1 for testing purposes. And the freaking thing display me 96 results, even tho there are only three in the DB! Array ( [0] => 35 [1] => 36 [2] => 34 [3] => 35 [4] => 36 [5] => 34 [6] => 35 [7] => 36 [8] => 34 [9] => 35 [10] => 36 [11] => 34 [12] => 35 [13] => 36 [14] => 34 [15] => 35 [16] => 36 [17] => 34 [18] => 35 [19] => 36 [20] => 34 [21] => 35 [22] => 36 [23] => 34 [24] => 35 [25] => 36 [26] => 34 [27] => 35 [28] => 36 [29] => 34 [30] => 35 [31] => 36 [32] => 34 [33] => 35 [34] => 36 [35] => 34 [36] => 35 [37] => 36 [38] => 34 [39] => 35 [40] => 36 [41] => 34 [42] => 35 [43] => 36 [44] => 34 [45] => 35 [46] => 36 [47] => 34 [48] => 35 [49] => 36 [50] => 34 [51] => 35 [52] => 36 [53] => 34 [54] => 35 [55] => 36 [56] => 34 [57] => 35 [58] => 36 [59] => 34 [60] => 35 [61] => 36 [62] => 34 [63] => 35 [64] => 36 [65] => 34 [66] => 35 [67] => 36 [68] => 34 [69] => 35 [70] => 36 [71] => 34 [72] => 35 [73] => 36 [74] => 34 [75] => 35 [76] => 36 [77] => 34 [78] => 35 [79] => 36 [80] => 34 [81] => 35 [82] => 36 [83] => 34 [84] => 35 [85] => 36 [86] => 34 [87] => 35 [88] => 36 [89] => 34 [90] => 35 [91] => 36 [92] => 34 [93] => 35 [94] => 36 [95] => 34 ) If I change the query to fetch the data from the posts table with the ID number of one, it works perfectly. I have no idea why it is being such a baby for the reactions table. Schema for the reactions table: BEGIN TRANSACTION; ---- -- Table structure for reactions ---- CREATE TABLE "reactions" ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'comment' TEXT, 'user_id' TEXT, 'topic_id' INTEGER, 'date_posted' INTEGER); ---- -- Data dump for reactions, a total of 3 rows ---- INSERT INTO "reactions" ("id","comment","user_id","topic_id","date_posted") VALUES ('34','qwdqdqdqwdqdqdqdqdqdqdqdqdqdqwdqdq','1','1','1447356567'); INSERT INTO "reactions" ("id","comment","user_id","topic_id","date_posted") VALUES ('35','qdwdqwdqwdqwdqwdqdqwdqwd','1','1','1447357049'); INSERT INTO "reactions" ("id","comment","user_id","topic_id","date_posted") VALUES ('36','qdwdqwdqwdqwdqwdqdqwdqwd','1','1','1447357054'); COMMIT; And now the whole Posts class: <?php class Posts { protected $db; protected $queryBuilder; // private $topicId = $_GET['id']; protected $topicId = 1; public function __construct($db) { $this->db = $db; $this->queryBuilder = $this->db->createQueryBuilder(); } public function listTopics() { $query = $this->queryBuilder ->select('posts_id, posts_title, posts_date, author_id') ->from('posts') ->where('posts_categories_id = 1') ->execute(); return $query->fetchAll(); } public function countComments() { $query = $this->queryBuilder ->select('comments_id') ->from('comments') ->where('comments_topic_id = 1') ->execute(); return $query->fetchAll(); } public function displaySingleTopic() { $query = $this->queryBuilder ->select('*') ->from('posts') ->where('posts_id = '.$_GET['id']) ->execute(); return $query->fetchAll(); } public function insertComment($comment_data) { extract($comment_data); $user_id = 1; $query = $this->queryBuilder ->insert('reactions') ->values( array( 'comment' => '?', 'user_id' => '?', 'topic_id' => '?', 'date_posted' => "STRFTIME('%s','now')" ) ) ->setParameter(0, $comment) ->setParameter(1, $user_id) ->setParameter(2, $this->topicId) ->execute(); } public function displayComment() { $row = []; $query = $this->queryBuilder ->select('*') ->from('reactions') ->where('topic_id = '.$this->topicId) ->execute(); // echo $sql=$query->getSQL(); while($row = $query->fetch(PDO::FETCH_ASSOC)) { $row2[] = $row['id']; } return $row2; } } single_topic.php where I am calling the method: <?php include 'html/header.php'; $profile = new Profile($conn); // Select all from a single post $post = new Posts($conn); // Turn the array keys into variables like ['title'] => $title extract($post->displaySingleTopic()[0]); $profile->author_id = $author_id; if(isset($_POST['comment'])) { $post->insertComment($_POST); } echo '<pre>'; print_r($post->displayComment()); ?> <!-- Post data --> <script> window.onload = function() { var height_of_topic = document.getElementById('general_topic').offsetHeight; document.getElementById('poster_info').style.height = height_of_topic+'px'; } </script> <article id="general_topic"> <h1 id="single_topic"><a href="post/{$posts_id}-$post_title" class="title_link"><?php echo $posts_title ?></a></h1> <section id="poster_info"> <ul> <li> <a href="profile.php?id=<?php echo $author_id?>"> <img src="<?php echo AVATAR_DIR.$profile->avatar();?>" width="140" height="130" /></li> </a> <li> <a href="profile.php?id=<?php echo $author_id?>"> <?php echo $profile->username(); ?> </a> </li> <li><?php echo $profile->country(); ?></li> <li><?php echo $profile->number_of_posts(); ?></li> </ul> </section> <!-- <hr></hr> --> <ul id="post_data"> <li id="post_date"> <a href="#"><?php print date('M d Y',$posts_date); ?></a> </li> <hr> <li id="post_category"> <a href="category/<?php //echo $categories_id ?>-<?php //echo clean_url($categories_name); ?>"><?php //print $categories_name ?></a> </li> <li id="post_comments"> <a href="/post/<?php //echo $posts_id ?>-<?php //echo $posts_title?>#comments_post_id<?php //echo $posts_id ?>"> <?php //echo $display_number_comments ?> </a> </li> </ul> <p> <?php echo nl2br($posts_contents); ?> </p> <!-- End of post data --> </article> <!-- Comment form --> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <form method="post" action="" id="comment_form" > <fieldset> <?php if(!$profile->isLoggedIn()) { ?> <label> Name:<span>*</span> <input type="text" class="long_input_field" name="commentator" id="text_name" maxlength="50" /> </label> <label> Website: <input type="text" class="long_input_field" name="website" id="text_name" maxlength="50" /> </label> <?php } ?> <label> What's your opinion...:<br /> </label> <textarea rows="10" cols="50" id="text_comment" name="comment"></textarea> <br> <input type="submit" name="commented" id="comments_button" value="Publish Comment" /> <!-- <input type="hidden" name="post_id" value="<?php //print $this_fuking_post; ?>" /> --> <label for="" class="secret"> Do not populate this field<input type="text" name="url" /></label> </fieldset> <!-- End of comment form --> <?php /* Start the foreach loop to display all comments related to the article. The function display_comments is in functions.php document. The function returns an array that holds absolutely all comments for that article. */ /* if(is_array(display_comments_data($post_id, $db ))) { foreach(display_comments_data($post_id, $db ) as $comment) {*/ ?> <div class="comment" id="comments_post_id<?php //print $comment['comments_post_id'] ?>"> <h3> <?php /*echo $comment['comments_commentator'];*/ ?> </h3> <h5><?php /*echo date('d F Y',$comment['comments_date']);*/ ?></h5> <p> <?php /*echo $comment['comments_comment'];*/ ?> </p> </div> <?php /* } }*/ ?> </form> <?php include 'html/footer.php'; ?> Thank you SO MUCH in advance! Please help!
-
If you keep writing queries with mysql_query, everything will be bad, lol.
-
Doctrine looks really cool! OMG I got very excited. I didn't know you weren't suposed to write your own DB abstraction layers, I thought that was a rule only for the encryption, datetime, hashing, and a few others.
-
Oh, is this what i was doing a DB abstraction layer? I thought it was wrappers, lol. Yes I am aware of the SQL injection risks, but it is currently under development. Thank you I am looking into Doctrine now. I'd prefer abstractions of SQL since otherwise I'd have to write every single SQL query and that would make my life very difficult. Thank you so much!
-
Howdy, I am writing a forum from scratch because I like to play with fire. Moving on, I can't think of the best way to store table and column names in either variables or constants. And where to store them? Maybe in a new config.php file? I thought about it and not one sane idea entered my head. I really don't like to write them each time in my DB wrapper methods since if i change the name of a table or a column, the whole thing will fall apart. Currently i have it set like this: <?php class Posts extends DB { public function list_topics_based_on_category() { return $this->select_from_table_condition('posts_id, posts_title, posts_date, author_id', 'posts', 'posts_categories_id = 1'); } public function display_contributor_name_by_id($user_id_array) { $contributor_name = $this->select_from_table_condition_user_input('username', 'users', 'id = ', $user_id_array); return $contributor_name[0]['username']; } public function count_comments($topic_id) { return count($this->select_from_table_condition_user_input('comments_id', 'comments', 'comments_topic_id = ', $topic_id)); } public function select_single_topic($topic_id) { return $this->select_from_table_condition_user_input('*', 'posts', 'posts_id = ', $topic_id)[0]; } } Please help! Thank you very much!
-
Don't bother sending attachments with the native mail() function, use PHPMailer. http://www.sitepoint.com/sending-emails-php-phpmailer/
- 1 reply
-
- 2
-
Will do so, asap. I counted on CTRL + Z, but you are right, because my projects have gotten bigger and even tho I upload them to the cloud every evening for back-up, it's not the same as have VC. I have been wanting to learn Git for a long time anyways and you and scootstah have given me another very good reason to do so, thank you guys PS - good idea also for the back-up in Bitbucket didn't think of that, lol.
-
Good idea, but I am scared of VPS-es, I am not a good network admin. I will probably screw up the installation of PHP totally ...
-
Yes, just display the freaking results, you don't need to store them in a variable and use them "later" that makes using AJAX completely pointless.
-
Yes, break down the various functions into modules, that makes life way easier.
-
Yes, but it is not working here, obviously. Either change the function, OR look in the PHP.ini whether you have file uploads allowed. Also check the $_POST vars max size in php.ini Some hosts has those settings turned off by default.
-
You need to use move_uploaded_file -> http://php.net/manual/bg/function.move-uploaded-file.php
-
Php only countdown with action to follow when countdown time reach 0
Stefany93 replied to cobusbo's topic in PHP Coding Help
Yes, your only chance is with AjAX if you want to make it strictly PHP. Another solution is to make the timer with JS and have the JS script active an AJAX function that would active the PHP script once the timer has passed. -
Hello friends, I am a programmer and sometimes clients would come to me without ready-made designs. By that, I mean PSD files. Also, more often than not, my clients would require a logo and unless they are looking for a pen drawn sun that I proud myself with, I can't offer them any better. So I am looking for a designer to help me. Bear in mind that I'd want someone who is, most of all, a friendly person, even if they are not that experienced. Also, an easy to talk to and most of all, honest person. Skills come second, but it would be super awesome if the designer in question has a portfolio to show me That's all for now. Please add me on skype to talk age_of_empires3 Cheers!