[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

stupid questions thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 27
Thread images: 2

File: icon.php.png (25KB, 710x710px) Image search: [Google]
icon.php.png
25KB, 710x710px
I'm just learning PHP.
Say I have a database about memes. There is one page index.php which displays all memes.
And there is another page meme.php which shows details about specific meme.
So I want every photo on index.php to be a link to meme.php page.
I do it like this:
<a href="meme.php?id=$_POST['id']">
<img.../>
</a>

And in meme.php
$_GET['id']
tells me which meme details to display.
I get this, but is there a better way to do this? Seems just strange.
>>
>>60530719
Sudo apt-get gentoo
>>
>>60530751
please don't meme, i'm new
>>
Can anyone please tell me if I can have 1 hard drive running windows 7 and 1 hard drive running windows 10, have them dual-boot, and switch between them without having to restart my computer. Google has been no help at all in this. Also, I don't want linux on this computer.
>>
Why are your a hrefs using $_POST? Does your index.php have a form on it? This setup doesn't make sense.
>>
>>60530838
oh yeah you're right. It should be some variable which contains row from database instead of $_POST
>>
>>60530719
Use the MVC approach, on your index your href will be like "/meme/32", which will be routed to a controller called Meme in a private directory to its main function with the argument "32" passed. The controller calls the model (not mandatory, you can just perform your db queries in your controller function but it's bad practice) by passing the argument "32" which is the id of your meme in the meme table. The model retrieves all the meme data from the db and returns it to the controller, which eventually loads the meme.php view with its specified data.
>>
>>60530719
>>60530892
then yes, this is the basic way of doing it
>>
>>60530719
you have a database somwhere that maps a number to your meme-dataentry. so something like idk

$res = $mysqli->query("SELECT * FROM memes");
foreach ($res AS $entry) {
list($id, $image, $text) = $entry;
echo "<a href=\"meme.php?id=$id\">
<img src=\"$image\"/>
</a>";
}

You dont need post.
You can then check if $_GET['id'] is set to a value, you can display the detail version instead.

I am newfag, dont know how to code-format.
>>
>>60530766
$_POST['this'] for forms and $_GET['this'] for test.html?this=1

Seriously do not forget to do this:
$number=intval($_GET['this']);

or else people will try sqlinjection
>>
It hurts to see people still use PHP like that.
>>
>>60533786
That's exactly what it was made for.
>>
>>60533805
Yes. And yet it's one of the worst ways you could possibly make a web application.
>>
>>60530977
tl;dr on MVC architecture?
>>
>>60530719

dude - use PHP to grab data only - don't fuse it within your html files

spit out your data in your .php file into JSON format, then use javascript to bind it to your html files

its the modern and easier way to do things
>>
>>60530719
>I'm just learning PHP.
why.jpg
>>
>>60531837
Do people really do this?
You should not be injectable even if you dont sanitize your inputs.
>>
>>60533867
Just watch an introduction video or read a tl;dr about Ruby on Rails or Laravel.
>>
File: tempchk.png (137KB, 1365x1081px) Image search: [Google]
tempchk.png
137KB, 1365x1081px
>>60533883
this
works like a charm and the api can be used for other applications as well
>>
>>60533883
let him learn one thing at a time
also see >>60533805
>don't fuse it within your html files
this is literally what PHP was created for and if you don't want to do that then there's no reason to use that language anymore
>>
Don't laugh...
I am learning to create websites. I just jumped from writing them in plain html/css and started using bootstrap and javascript.

Still, I have this wierd sensation that something is still getting over my head, people mention this creates static webpages.

So I suppose there are dynamic ones. Exactly how are they created?
I've read you can create pages with Java, exactly how can you do that? Is this what they mean with dynamic? Can you explain a bit these two terms? Thanks.
>>
>>60531756
>mysqli
kill yourself desu
>>
>>60535174
drink bleach noob?
>>
>>60530790
>Can anyone please tell me if I can have 1 hard drive running windows 7 and 1 hard drive running windows 10, have them dual-boot, and switch between them without having to restart my computer. Google has been no help at all in this. Also, I don't want linux on this computer.

You're Going to have to restart anon, both of those RansomOS's have different drivers and shit they need to load on boot
>>
>>60535081
Static pages are premade HTML documents that the server just grabs and sends to the browser that requests them.
Dynamic pages are generated on the server after each request. This means that the request data sent by the browser can be used as an input to the procedure that does the generation.

the distinction is a little less useful nowadays since static pages can have dynamic content by making an ajax request for data and injecting that data into html. and all of this happens after the page had been loaded in the browser.

>I've read you can create pages with Java, exactly how can you do that?
For example here:
https://jcp.org/en/jsr/detail?id=5
The id = 5 is a GET parameter that can be user by the server to determine of which entity the user wants to see the details of. In Java or any other language it would look something like:
1. Have a method that gets called to generate the page when the request path is /en/jsr/detail and the request method is GET
2. Get value of parameter "id" from the request parameters
3. Query the database for data of the entity with id 5
4. Load the needed template and fill placeholders for data in the template with the data just retrieved from the database. Now you have a HTML document.
5. Respond to the request with the just generated document

Now you can technically have this with static pages, because you can make the JS loaded in the user's browser do a similar thing. Steps 1. and 2. would be a bit different, step 3. would contact an API that provides data instead of contacting a database directly. Then you would perhaps load a template compiled within the JS file, fill it with data and insert it all by modifying a part of the HTML document (or the DOM to be more correct)
>>
>>60530719
This is kind've a nit-pick considering you're right at the beginning of php, but never call GET and POST variables directly. Always filter them first.

$id = filter_input(INPUT_GET, "id", FILTER_SANITIZE_INT);
>>
>>60535571
Very informative, thanks a lot!
Thread posts: 27
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.