Hot answers tagged

3

Yes, there are many solutions. If with "recent entries" you mean "sorted by date" (or with sequential indexed IDs), all you need to do is : Define a variable called $last_id = 0; Use a SELECT statement with a LIMIT clause (i.e. "SELECT * from Table where ID > $last_id order by ID LIMIT 20" for a 20 items page) Save the last ID in a variable ($last_id = $...


3

The problem is really about host(smtp.fas.harvard.edu), I had the same problem and here is my decision: I created a new mailbox at gmail, and used it like this: /*Sends a message of $body with subject $subj to $to*/ function email($to, $subj, $body) { // create mail object and set some settings settings $mail = new PHPMailer(); $mail->...


3

I just wanna make sure, does extract() declare these variables as global variables? Not necessarily. The description of extract() reads, "Import variables from an array into the current symbol table." In other words, the extracted variables will be set in the current scope (at the point where extract() is called). This means that if you call extract() from ...


3

We all know that phpMyAdmin can be flaky sometimes. Unfortunately, I can't tell you how to fix it -- but I can tell you how to use mysql50 shell from the command line. Try stuff like this: mysql50 shell SHOW DATABASES; USE pset7; SHOW TABLES; DESCRIBE users; SELECT * FROM users; SELECT COUNT(*) FROM users; quit It's rock-solid and reliable, and it will ...


2

Toward the end of the last century (early 1990's) a common way for web servers to talk to programming languages was by using the Common Gateway Interface (CGI). CGI is very simple and works in a way that is very similar to the C programs we create in CS50. The network connection is is handled by the web server, like Apache or Microsoft IIS. The web server ...


2

When we submit form data to a URL or a page using either of these methods (i.e., GET and POST), how does this web page receive this data underneath the hood? GET and POST are two request methods of the Hypertext Transfer Protocol (HTTP), which defines how the content we call a "web page" is transferred over the internet. On a more general level, internet ...


2

First, for closed tags, if you open a tag, you should close it. I see you're not closing the <select> tag. More information about that tag maybe found here. Also, you have </div> within the body of your for each loop which means </div> will be there n times where n is the number of iterations that this loop will iterate. Next, you probably ...


2

Yes your logic is correct, and this is exactly the way the world works. Say I have $20. I buy a diamond for $10. So now I have $10 left. In a week from now, the same diamond, costs $5. But I still have $10 left, not $15. My current cash balance is not determined by the value of the things I bought at past. It stays the same. Now say I also buy this diamond. ...


2

If https://www.google.com/search?q=cs50 submits form data using GET to search, what is search? search is just a path that Google's web servers use as an entry point into the search engine. Behind the scenes the web server will redirect the request to a specific server instance, chosen from a cloud of servers, to handle the request. So search doesn't exist ...


2

here's a good link which shows you the differences: http://www.nutt.net/2004/12/09/php-benchmarking-echo-vs-print-vs-printf/


2

I figured it out. <%= ... %> is indeed the way you pass in arguments to _.template. When I watched the video in the problem set again the prof mentioned how this code operates similarly to the "%i" placeholder in printf in C. Essentially, you insert the column titles in your phpMyAdmin table into the <%= ... %> placeholder within the _.template TODO ...


2

Such a subtle thing. Your are inserting 3 columns (username, hash, cash). The computer thinks you are sending 4 values because of the comma in your cash amount. VALUES(?, ?, 10000,00)


2

From the pset instructions: Know that index.php is the file that’s loaded by default when you visit a URL like https://ide50-username.cs50.io/. ...which calls (redirects to) login.php (via config.php) if empty($_SESSION["id"]), which presumably it is when first called. Recall from the implemention of indexes() in pset6's server, how index.php or index....


2

You can achieve that using JavaScript: <div> <h1>SELECT A TOPIC</h1> <select id="select"> <option value="physics">physics</option> <option value="maths">maths</option> <option value="chemistry">chemistry</option> </select> <button type="button" id="submit" style="font-...


2

You've probably gotten used to using #include statements in C. The equivalent function in PHP is require(). If you have access to pset7 or pset8, just look at the distribution code provided. You'll definitely see require() (or its close relative require_once() near the top of files like index.php. Also, note that the correct permissions for PHP files are ...


2

Not all of them! $alphacount = 0 :)


2

To answer the specific question from your comment "why is :: used?" From the config section of the spec (That :: syntax just means that init is "inside of" an "object" called CS50. An object in PHP, meanwhile, is similar in spirit to, but more featureful then, a struct in C. The CS50 class is defined around line 70 of CS50.php. You'll find more info on ...


1

as you reach pset7, the first pset that you are going to interact with a database in it, you won't have to write your own code to connect with your database. instead, there is a query function provided by the staff that handles that for you. luckily, this function uses PDO underneath the hood. for more information, see functions!


1

The problem is your input data. Your query is expecting 12 values on every line. The first line in your example has 9. You "lost" the blank columns from the text file, presumably when you converted tab to comma. Your input file should look like this: I 💜 data


1

The problem is your insert query. You are inserting 12 columns, you have 12 ? placeholders, but you are sending 13 arguments. Also, beware: implode returns a string. So you $str_values[0] et. al. will the "individual" characters. fgetcsv returns an array, so $data should be the array you want in your insert.


1

recall that, assuming the query is syntactically correct, query returns an array of the resulting rows (if any) or an empty array otherwise. try print_r'ing $comment to learn about the structure of the contents!


1

Ignore this, It was actually fixed very easily by switching the order of the render function and the array loop. Doh!


1

the first argument that preg_match takes according to the documentation is a pattern. that is, a regular expression to test $destination against in this case. the forward slashes (i.e., /) at the start and the end of the pattern denote the start and the end of it. the ^http tests whether $destination starts with http. s? tests whether the http is ...


1

This is the answer from Kareem's link. Please do not vote on this. I just want to take this answered question out of the unanswered list. There are actually several approaches to do this. Some require more overhead than others, and some are considered better than others. In no particular order: Use AJAX to get the data you need from the server. Echo the ...


1

Try checking your index+ link on the Structure view. I deleted all my unique and primary keys, as well as any links to other tables. This solved the problem..thanks to Kareem .. and, I apologise for submitting a comment as an answer earlier. Frustrated newbie here, not paying attention!


1

Just like _POST your positions is an associative array. Just as you get $_POST["symbol"] you get $positions["price"]. If I understood correctly you want to do something like the following <?php $values = [ "name" => "GOOG", "price" => 3.5 ]; printf("Name: %s\nPrice: %f\n", $values["name"], $values["price"]); ?> ...


1

I made something simple but I think you can tinker further on your own: grad.html <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div> <table id="grad1"> <tr> <th>...


1

If I understand correctly you mean the path to php interpreter so that to use a #! to make it executable. It's #!/usr/bin/env php.


1

I think the simplest answer is php <filename>. So if you have a php file called hello.php that looks like this: <?php printf("Hello, world!\n"); ?> you would run php hello.php and you'd get Hello, world! as the output on the screen. Is that what you mean?


1

If you want to use the redirect() function provided in pset7 I'm not sure how, but in general you can do it like so: echo "<script type='text/javascript'> if (confirm('Want to redirect?')) { location.href = 'http://www.google.com/'; } </script>";


Only top voted, non community-wiki answers of a minimum length are eligible