Programming › Re: Please How Do I Print This Data From MY Database. MYSQL, PHP by kudaisi(m): 11:21am On Jan 03, 2017*. Modified: 10:55am On Jan 05, 2017 |
I'm not really sure what you want, but I made a rough code based on what you've described and I hope it meets your requirement. Attached is a screenshot of the resulting output looks like and here is the code: <html> <head><title>Memories</title> <style> .memory-comment,.memory-content{display:block;padding:9.5px;font-size:13px;color:#333}.memory-content{margin:0 0 10px;background-color:#ABD0BC;border:1px solid #ccc;border-radius:2px}.memory-comment{margin:10 0 10 40px;background-color:#f5f5f5;border:1px solid #ccc;border-radius:2px}.memory-author{color:#000;background:#DCF2B8;border:1px solid #9EC068;padding:2px 6px;margin:6px 0}#container{margin:0 auto;width:640px} </style> </head> <body> <div id="container"> <?php $db = new mysqli('localhost', 'root', '', 'memory');
if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } $sql = " SELECT m.id,m.content, m.time, concat(u.first_name,' ', u.last_name) as author FROM memories m LEFT JOIN user u ON u.id = m.author_id";
if(!$memories = $db->query($sql)){ die('Unable to run Query "' . $db->error.'"' ); } // Write all memories with author name // Note: From the query the user's first name and last name is included with a join and concatenated as author while($row = $memories->fetch_assoc()){ echo "<div class='memory-content'>".$row['content'] . " by <span class='memory-author'>".$row['author']."</span></div>"; // For each memory in the loop find its comments $sql = "SELECT * from comments WHERE memory_id =".$row['id']; while($comment = $comments->fetch_assoc()){ echo "<div class='memory-comment'>".$comment['content']."</div>"; } } ?> </div> </html> Disclaimer: Use the code at your own risk.
|
Programming › Re: Friendosphere.com is there for you, developer-inclined website by kudaisi(m): 11:45am On Dec 22, 2016 |
DanielTheGeek: Forked a GitHub project and remodelled it, improved the algorithms and totally engineered the back end. So basically, Yes. The front-end is just some random bootstrap template you can find anywhere. Nice one bro, I was going to say it looks a lot like Question2Answer open source project. http://www.question2answer.org/ |
Programming › Re: Friendosphere.com is there for you, developer-inclined website by kudaisi(m): 10:29am On Dec 22, 2016 |
It looks pretty good. One question though, did you develop Frendosphere yourself ? |
Programming › Re: Create Self-Signed Certificate by kudaisi(m): 7:06am On Dec 19, 2016 |
lordZOUGA: It is pretty straightforward. Read through this document (https://help.ubuntu.com/12.04/serverguide/certificates-and-security.html) First create certificate key and signing request with the code below. (You will be asked some questions when you run the second command)
openssl genrsa -out server.key 2048 openssl req -new -key server.key -out server.csr Then create your self-signed certificate with the following command (expires after 365 days):
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt This should put your certificate in a file named "server.crt" in the current directory. You should read that document linked above for best practices with certificates. Same command works on windows if you have OpenSSL installed. |
Programming › Re: Do Boring Things With Python (PDF File Downloader) by kudaisi(m): 10:46am On Dec 15, 2016 |
Nice one bro. I think you should add functions this to your TODO - Allow users to select the particular PDFs to download In other words, when I search I expect to see a list of available PDFs. After which I can check the items I am interested in downloading. - Allow users to specifiy download based on file size.( i.e download only files > or < xMB) |
Programming › Re: Need Help With Python Server Side Programming by kudaisi(m): 12:12pm On Dec 13, 2016 |
lordZOUGA: If you are interested in returning HTML from a server just like most webservers, then you can just create a server listening to a port and return a bunch of strings from the server (sounds easy right?).
The problem is that you also have to build HTTP headers and manage I/O between server and clients (this is unbelievably complex).
Frameworks are helpful because they have already implemented most of these features reliably.
I encourage you to try building a webserver from scratch, it will make you appreciate the usefulness of Frameworks. The environment variable his server has to cater for (and this is just a tip of the iceberg) REQUEST_METHOD The HTTP request method, such as "GET" or "POST" . This cannot ever be an empty string, and so is always required. SCRIPT_NAME The initial portion of the request URL's "path" that corresponds to the application object, so that the application knows its virtual "location". This may be an empty string, if the application corresponds to the "root" of the server. PATH_INFO The remainder of the request URL's "path", designating the virtual "location" of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash. QUERY_STRING The portion of the request URL that follows the "?" , if any. May be empty or absent. CONTENT_TYPE The contents of any Content-Type fields in the HTTP request. May be empty or absent. CONTENT_LENGTH The contents of any Content-Length fields in the HTTP request. May be empty or absent. SERVER_NAME , SERVER_PORT When combined with SCRIPT_NAME and PATH_INFO , these two strings can be used to complete the URL. Note, however, that HTTP_HOST , if present, should be used in preference to SERVER_NAME for reconstructing the request URL. See the URL Reconstruction section below for more detail. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required. SERVER_PROTOCOL The version of the protocol the client used to send the request. Typically this will be something like "HTTP/1.0" or "HTTP/1.1" and may be used by the application to determine how to treat any HTTP request headers. (This variable should probably be called REQUEST_PROTOCOL , since it denotes the protocol used in the request, and is not necessarily the protocol that will be used in the server's response. However, for compatibility with CGI we have to keep the existing name.) HTTP_ Variables Variables corresponding to the client-supplied HTTP request headers (i.e., variables whose names begin with "HTTP_" ). The presence or absence of these variables should correspond with the presence or absence of the appropriate HTTP header in the request. |
Programming › Re: Need Help With Python Server Side Programming by kudaisi(m): 9:31am On Dec 13, 2016 |
However, you can still reduce the overhead of implementing every bit of the specification by yourself (I strongly suggest you understand it though) by using existing libraries. One of such is Werkzeug - The Python WSGI Utility Library, and it's the most popular that I know of. There are other option asides Werkzeug so you might want to check them out too, a little googling should help. http://werkzeug.pocoo.org/ |
Programming › Re: Need Help With Python Server Side Programming by kudaisi(m): 9:23am On Dec 13, 2016 |
If you must do web development without a framework in python, you will need to implement the Web Server Gateway Interface (WSGI. According to Wikipedia It is a specification for simple and universal interface between web servers and web applications or frameworks for the Python programming language. PEP3333 is the most recent version of this specification available on the python official website; The document specifies a proposed standard interface between web servers and Python web applications or frameworks, to promote web application portability across a variety of web servers. Here's a quote from the "Original Rationale and Goals (from PEP 333)" Python currently boasts a wide variety of web application frameworks, such as Zope, Quixote, Webware, SkunkWeb, PSO, and Twisted Web -- to name just a few [1] . This wide variety of choices can be a problem for new Python users, because generally speaking, their choice of web framework will limit their choice of usable web servers, and vice versa.
By contrast, although Java has just as many web application frameworks available, Java's "servlet" API makes it possible for applications written with any Java web application framework to run in any web server that supports the servlet API.
The availability and widespread use of such an API in web servers for Python -- whether those servers are written in Python (e.g. Medusa), embed Python (e.g. mod_python), or invoke Python via a gateway protocol (e.g. CGI, FastCGI, etc.) -- would separate choice of framework from choice of web server, freeing users to choose a pairing that suits them, while freeing framework and server developers to focus on their preferred area of specialization.
This PEP, therefore, proposes a simple and universal interface between web servers and web applications or frameworks: the Python Web Server Gateway Interface (WSGI). https://www.python.org/dev/peps/pep-3333/ |
Programming › Re: Need Help With Python Server Side Programming by kudaisi(m): 9:35pm On Dec 12, 2016 |
ProNdubuisi: Hello world, does anyone here write sever side code with python? just learnt the language and want to go into web dev with it, but all i see is Django tutorials online, i dislike frame works. Do you know how i can hard code Python like you hard code php, html css and the rest? i need someone who has done it before to walk me through [b]Do I have to use a web framework? [/b]Whether or not you use a web framework in your project depends on your experience with web development and what you're trying to accomplish. If you are a beginner programmer and just want to work on a web application as a learning project then a framework can help you understand the concepts listed above, such as URL routing, data manipulation and authentication that are common to the majority of web applications.
On the other hand if you're an experienced programmer with significant web development experience you may feel like the existing frameworks do not match your project's requirements. In that case, you can mix and match open source libraries such as Werkzeug for WSGI plumbing with your own code to create your own framework. There's still plenty of room in the Python ecosystem for new frameworks to satisfy the needs of web developers that are unmet by Django, Flask, Pyramid, Bottle and many others.
In short, whether or not you need to use a web framework to build a web application depends on your experience and what you're trying to accomplish. Using a web framework to build a web application certainly isn't required, but it'll make most developers' lives easier in many cases. |
Programming › Re: Who Knows About Pypyodbc Or Pyodbc? by kudaisi(m): 3:52am On Dec 11, 2016 |
Here's a snapshot of pyodbc documentation page and it clearly gives examples for SQL Server, Oracle......
I expected that you would have checked each libriaries documentation before asking such though.
|
Programming › Re: Data Encryption With Python-how To Encrypt A Textfile Using Python by kudaisi(m): 1:25pm On Dec 08, 2016 |
Nice Post, Caesar Cipher. I just have a couple of questions: 1. What are the cons of this encryption method ? 2. Can it be used in a production environment (do u encourage it) ? |
Programming › Re: Lets Start A Thread For Solving Problems From Projecteuler.net by kudaisi(m): 8:39am On Dec 04, 2016 |
|
|
Programming › Re: Help- My Wordpress Website Forum Text Is Overlapping On Mobile Device by kudaisi(m): 10:38am On Dec 02, 2016 |
Mrfidelk: just change your theme to a mobile responsive one..if you more help, contact me via my signature Looking at the picture, it seems to me that the theme is responsive. But I'm guessing the issue might be as a result of some uncleared floats within one of the media queries. |
Programming › Re: Need Step On How To Hide Javascript Source Code. by kudaisi(m): 10:30am On Nov 30, 2016 |
Alternatively, you can download http://javascriptobfuscator.com/ GUI and install. If you don't already have Node.js. FYI: There are some beautifiers out there that can reverse obfuscation.. Maybe not to it's original state, but to a state that is more readable. |
Programming › Re: Need Step On How To Hide Javascript Source Code. by kudaisi(m): 10:29am On Nov 30, 2016 |
Oladg2: Please how do i go about this ? You need to install Node.js, Then install UglifyJS with NodeJS package manager npm install uglify-js -g To obfuscate a file say scripts.js for example run the command uglifyjs --compress --mangle scripts.js or simply uglifyjs --mc scripts.js as earlier mentioned by @chido4real What you need mostly is the --mangle (--m) option, according to the documentation it Mangle names/pass mangler options. The --compress option also makes it hard to read, but the effect can easily be reversed with a beautifier. |
|
Programming › Re: SQL Server by kudaisi(m): 2:26pm On Nov 26, 2016 |
benzics: Well I use mysqli at times and also use PDO.. Surprise! They all work! So I don't know where the base of your argument comes from!! You use mysqli with Microsoft SQL Server...it's alright, and I'm the one shaming my self on the internet? I guess it's no point getting into this conversation with you in the first place. Enjoy you successful programming career. |
Programming › Re: SQL Server by kudaisi(m): 2:14pm On Nov 26, 2016 |
benzics: Please if you don't know much about something, I advice you keep it to yourself instead of shaming yourself on the internet... SQL takes Mysqli, PDO and others, they are just extensions of SQL... SQL Server as in Microsoft SQL Server. Just so you know, this on that you're being hasty to diss me. |
Programming › Re: SQL Server by kudaisi(m): 2:12pm On Nov 26, 2016 |
benzics: Please if you don't know much about something, I advice you keep it to yourself instead of shaming yourself on the internet... SQL takes Mysqli, PDO and others, they are just extensions of SQL... mysqli (it is an extension no dispute) is specific to MySQL, PDO can generically access most database supported by PHP. Why the heck would you want to user mysqli on SQL Server when you have PDO and a SQL Server specific extension ...i.e mssql |
Programming › Re: SQL Server by kudaisi(m): 1:13pm On Nov 26, 2016 |
benzics: Don't get MySQL and SQL Server are two different products. |
Programming › Re: SQL Server by kudaisi(m): 9:53am On Nov 26, 2016 |
benzics: Are you using OOP mysql or procedural? Are you sure you've created the database you want to connect to? Connecting using procedural mysqli... $mconn=mysqli_connect(server, user, pass, database) ;if(!mconn) {die(mysqli_connect_error($mconn) ;}
Make sure you've already created the said database  SQL Server => mysqli  |
Programming › Re: Whats The Use Of Java Language??.. by kudaisi(m): 8:24pm On Nov 25, 2016 |
What's the use of every other programming language ? |
Programming › Re: Need Step On How To Hide Javascript Source Code. by kudaisi(m): 11:32am On Nov 25, 2016 |
SeunLanLege: I load my js asynchronously. So ctrl+u won't show you my code,except you check your network requests in your console. That's the best way I know to hide your js code. It also optimizes page loads. Like I said, AJAX is an option. |
Programming › Re: Need Step On How To Hide Javascript Source Code. by kudaisi(m): 9:18pm On Nov 24, 2016 |
Oladg2: Need step on how to hide javascript source code . There's really no perfect way to absolutely protect you JavaScript source from a user that is determined to see it and experienced enough to know how to go about it. However, I know that you can make it harder for user to view your javascript source (hopefully hard enough to discourage the viewer) . Some methods include referencing the scripts from external files...i.e breaking the code into bits and pieces within separate files which are equally referencing other files, you can also retrieve some of the scripts via Ajax calls. Additionally, you can obfuscate you code to make it unreadable without hassle. It's important to note however that I rarely find it necessary to make my javascript secret (its not like I have my database password hardcoded somewhere within the script). Its mostly about getting the script to work at optimum performance. |
Programming › Re: Nancy Fx: How To by kudaisi(m): 2:54pm On Nov 23, 2016 |
Sorry this is coming late, I hope it can still help. I didn't finish the implementation (tried re-code at fresh without NHibernate) but went as far as time permitted. My hands a tied at the moment. But I believe if you go through the sample you should get a better understanding. Will try to round it up soonest (if you still need me to). https://yemikudaisi@bitbucket.org/yemikudaisi/nancyfx-crud-sample.git Oh!, I tend to use Domain-Driven Pattern a lot so don't mind the overkill (models, repositories, factories......) Happy Coding!!! |
|
|
|
Programming › Re: Nancy Fx: How To by kudaisi(m): 11:26am On Nov 22, 2016 |
Note that I first of heard NancyFX from you (i.e last night). But the documentation is quite straight-forward. I was able to code a simple CRUD over the night using NHIbernate ORM with SQLite, I don't know if that will help. Another option is share the link to the sample in mongodb. I might be able to give some pointers or modify it to suit you need in my spare time.
In my opinion though, if the service is going to be transferring data in JSON format then MongoDB might not be an overkill since mongo is already a JSON friendly database. |
Programming › Re: Nancy Fx: How To by kudaisi(m): 12:33am On Nov 22, 2016 |
Your question is a little bit confusing. Do you know how to use nancyfx ? Do you know how to read data from sqlite in .Net ? Answering this question will shed more light on how to help you. |
Programming › Re: Can Not Post Data Into Database by kudaisi(m): 3:18pm On Nov 21, 2016*. Modified: 8:22pm On Nov 21, 2016 |
usman4people: Hello, Thanks for your kind response, I am looking for how to insert array of data with checkbox into mysql database. Your question is not clear, but let me try from what I understand: I imagine you have a tables as so: student_subjects Table Structure ___________________________ | id | subject_id | student_id | ------------------------------------ |___|__________|___________| |___|__________|___________| You have an array variable say $check that holds all the subject that were checked And another variable $student_id which holds the ID of the student in context of your code. Then the $conn variable which I assume is a mqsqli connection to your database A code as simple as below should do the trick (note the code is without error checking or performance considerations). <?php $check_count = count($check); for($i=0; $i < $check_count; $i++) { $sql = "INSERT into student_subjects (subject_id, student_id) VALUES ('".$check[$i]."','".$student_id."' ) " ; $conn->query($sql) } ?> |