andyellen Posted October 25, 2015 Share Posted October 25, 2015 this is my website http://www.mytestingvlog.co.nf/post.html I want that when someone types into text area and submits the text via ask button that post will be submitted to http://www.mytestingvlog.co.nf/feed.html the two arrows on the rights sides will be votes. the one with most votes will moved higher Please help me how do i do this? thank you all Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/ Share on other sites More sharing options...
benanamen Posted October 25, 2015 Share Posted October 25, 2015 What have you tried? What was the result? Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524303 Share on other sites More sharing options...
hansford Posted October 25, 2015 Share Posted October 25, 2015 You are going to have to use Ajax calls if you want to dynamically shift the questions up or down based on vote clicks. As far as initially displaying the page. <form action="feed.php" method="post"> <textarea required="" name="question" placeholder="Write Something..." id="text" cols="30" rows="10"></textarea> <input type="submit" name="submit" value="ask"> </form> feed.php if ( ! isset($_POST['question'])) { // give error or send them back to the page etc. exit; } // here is where your database will come in // based on the number of votes you display the page html Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524304 Share on other sites More sharing options...
andyellen Posted October 25, 2015 Author Share Posted October 25, 2015 I havent tried anything yet. I am new to php/mysql Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524305 Share on other sites More sharing options...
andyellen Posted October 25, 2015 Author Share Posted October 25, 2015 feed.php if ( ! isset($_POST['question'])) { // give error or send them back to the page etc. exit; } // here is where your database will come in // based on the number of votes you display the page html Thank you sir. can you please tell me that when I write something on post.php http://www.mytestingvlog.co.nf/post.html then that post should be displayed similarly to http://www.mytestingvlog.co.nf/feed.html same design and style Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524307 Share on other sites More sharing options...
benanamen Posted October 25, 2015 Share Posted October 25, 2015 (edited) I havent tried anything yet. I am new to php/mysql Have you gone through any tutorials? Edited October 25, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524308 Share on other sites More sharing options...
andyellen Posted October 25, 2015 Author Share Posted October 25, 2015 Have you gone through any tutorials? yes I did but I am not getting them exactly and also some tuts are very old. All I want to start with post.html. can you please tell me when a user post on http://www.mytestingvlog.co.nf/post.html how do I display that text into http://www.mytestingvlog.co.nf/feed.html with same style and design its in that page. thanks in advanced Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524309 Share on other sites More sharing options...
benanamen Posted October 25, 2015 Share Posted October 25, 2015 I assume you don't want to just display it, but also have each post stay on the page. That will be sending you to database territory. You will need to learn up on form handling http://www.w3schools.com/php/php_forms.asp And MySQL http://www.w3schools.com/php/php_mysql_intro.asp Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524310 Share on other sites More sharing options...
Jacques1 Posted October 25, 2015 Share Posted October 25, 2015 Don't use w3schools as a reference. This site is infamous for spreading wrong information, dangerous code and plain nonsense. They seem to have improved their tutorials a bit, but they still output unescaped variables and display internal error messages all over the place. A much better resource for anything HTML-related is the Mozilla Developer Network. Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524316 Share on other sites More sharing options...
andyellen Posted October 26, 2015 Author Share Posted October 26, 2015 my index.php <?PHP include('db.class.php'); $bdd = new db(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <title>Voting System</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" type="text/css"> <script type="text/javascript" src="jquery/jquery-1.10.1.min.js"></script> <style> .arrow_up a { display: block; background: url("voteup.png") no-repeat; width: 26px; height: 13px } .arrow_up a:hover { background-position: 0 -13px; width: 26px; height: 13px } .arrow_up_voted { display: block; background: url("votedown.png") no-repeat; width: 26px; height: 13px } .arrow_down a { display: block; background: url("votedown.png") no-repeat; width: 26px; height: 13px } .arrow_down a:hover { background-position: 0 -13px; width: 26px; height: 13px } .arrow_down_voted { display: block; background: url("votedown.png") no-repeat; width: 26px; height: 13px } .number { font-size: 18px; color: #818185; padding: 7px 0 7px 0; } .voting_table { margin-right: 20px; } </style> </head> <body> <div class="container"> <div class="row"> <div class="col-md-12"> <?php $articles = $bdd->getAll('SELECT * FROM tc_tuto_voting_system'); // Select the article list foreach($articles as $article) { // Loop - for each article... $cookie_name = 'tcVotingSystem'.$article['id']; // Set up the cookie name echo '<div class="panel panel-default">'; echo '<div class="panel-heading">Article '.$article['id'].'</div>'; // Article name + id echo '<div class="panel-body">'; echo '<table class="voting_table pull-left">'; echo '<tr>'; echo '<td align="center">'; if( isset($_COOKIE[$cookie_name]) ) { // If the cookie exists (means if we have already voted for this article) echo '<div class="arrow_up_voted"></div>'; // We display a simple "arrow up", not clickable } else { ?> <!-- else we display the clickable "arrow up". We call a function and pass the arguments article ID and the value +1 --> <div class="arrow_up" id="arrow_up<?php echo $article['id']; ?>"><a href="#" id="arrowUp" onclick="vote(<?php echo $article['id']; ?>, '+1'); return false;"></a></div> <?php } echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td align="center">'; echo '<div class="number" id="number'.$article['id'].'">'.$article['total'].'</div>'; // We display the number of click echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td align="center">'; if( isset($_COOKIE[$cookie_name]) ) { // Same for the "arrow down": if the cookie exists (means if we have already voted for this article) echo '<div class="arrow_down_voted"></div>'; // We display a simple "arrow down", not clickable } else { ?> <!-- else we display the clickable "arrow down". We call a function and pass the arguments article ID and the value -1 --> <div class="arrow_down" id="arrow_down<?php echo $article['id']; ?>"><a href="#" id="arrowDown" onclick="vote(<?php echo $article['id']; ?>, '-1'); return false;"></a></div> <?php } echo '</td>'; echo '</tr>'; echo '</table>'; echo '<span id="message'.$article['id'].'"></span>'; // Display message "Thank you for voting" echo 'Up branch to easily missed by do. Admiration considered acceptance too led one melancholy expression. Are will took form the nor true. Winding enjoyed minuter her letters evident use eat colonel. He attacks observe mr cottage inquiry am examine gravity. Are dear but near left was. Year kept on over so as this of. She steepest doubtful betrayed formerly him. Active one called uneasy our seeing see cousin tastes its. Ye am it formed indeed agreed relied piqued.'; echo '</div>'; echo '</div>'; } ?> </div> </div> </div> <script type="text/javascript" src="tuto-voting-system.js"></script> </body> </html> my db.class.php <?php class db { private $conn; private $host; private $user; private $password; private $baseName; private $port; private $Debug; function __construct($params=array()) { $this->conn = false; $this->host = 'localhost'; //hostname $this->user = 'root'; //username $this->password = ''; //password $this->baseName = 'db'; //name of your database $this->debug = true; $this->connect(); } function __destruct() { $this->disconnect(); } function connect() { if (!$this->conn) { try { $this->conn = new PDO('mysql:host='.$this->host.';dbname='.$this->baseName.'', $this->user, $this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); } catch (Exception $e) { die('Erreur : ' . $e->getMessage()); } if (!$this->conn) { $this->status_fatal = true; echo 'Connection BDD failed'; die(); } else { $this->status_fatal = false; } } return $this->conn; } function disconnect() { if ($this->conn) { $this->conn = null; } } function getOne($query) { $result = $this->conn->prepare($query); $ret = $result->execute(); if (!$ret) { echo 'PDO::errorInfo():'; echo '<br />'; echo 'error SQL: '.$query; die(); } $result->setFetchMode(PDO::FETCH_ASSOC); $reponse = $result->fetch(); return $reponse; } function getAll($query) { $result = $this->conn->prepare($query); $ret = $result->execute(); if (!$ret) { echo 'PDO::errorInfo():'; echo '<br />'; echo 'error SQL: '.$query; die(); } $result->setFetchMode(PDO::FETCH_ASSOC); $reponse = $result->fetchAll(); return $reponse; } function execute($query) { if (!$response = $this->conn->exec($query)) { echo 'PDO::errorInfo():'; echo '<br />'; echo 'error SQL: '.$query; die(); } return $response; } } when I upload it on server. nothing shows up. please tell me how do i fix this Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524322 Share on other sites More sharing options...
maxxd Posted October 26, 2015 Share Posted October 26, 2015 First and foremost, php won't be parsed on pages with an .html extension unless the server is specifically set up to do so, which is a waste of resources as then every .html page will be passed through the php parser. So, if you're going to be dynamically building output, you'll need to change the extension to .php. As for the previous post, add the following error_reporting(-1); ini_set('display_errors',true); to index.php, before the line include('db.class.php'); and after the opening <?php tag and see what that has to say. Quote Link to comment https://forums.phpfreaks.com/topic/298825-need-to-convert-code-dynamically/#findComment-1524343 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.