php function that gets information -
I'm trying to create it, so it shows the latest announcements in a link with the title I tried to do it And now I'm trying to return it to the variable and it will not be ...
functions.fp
& lt; Php is required ("common.php"); Function getAnnouncements () {$ query = "Select from announcements"; Try {global $ db; // database $ stmt = $ db- & gt; Execute the query against the ready ($ query); $ Result = $ stmt-> carry about (); $ Result reward ['title']; } Hold (PDOException $ ex) {// Note: On a production website, you get output $ ex- & gt; GetMessage () should not be. // This is an attacker can provide useful information about your code. Dead ("Failed to run query:" $ Ex-> getMessage ()); }}? & Gt;
index.php
& lt; Div class = "declaration" & gt; & Lt; Div class = "container" & gt; Latest announcements: & lt ;? Php getAnnouncements (); Echo "& lt; a href = '' & gt; & lt; / a & gt;" ? & Gt; & Lt; / Div & gt; & Lt; / Div & gt;
Yes, I am also including the file at the top and there are no spelling errors in it. First of all, make sure that $ db
is started with:
$ db = new PDO ("mysql: host = [host here]; dbname = [dbname] e; charset = UTF8", [user name], [password]);
You want to bring an associative array and loop in such a way:
$ result = $ result-> FetchAll (PDO :: FETCH_ASSOC); '$ A_result [' title '].' & Lt; / A & gt; ($ $ A_result as $ result) '&' a href = "'. $ A_result [' link ']." & Gt;
It is assuming that there is a link
column on your database
Comments
Post a Comment