Wednesday, 15 April 2015

UPDATED - PHP Fetch Associative Array - Selecting Multiple Rows from MySQL DB -


Currently, I'm able to choose a line of data from my database table. I was thinking that every time it is possible to select information from a particular line without changing the code according to your needs. This is for a news article on my website.

Here's my code:

  & lt ;? Php session_start (); If (! $ _ Session ['username']) {header ('location: index.php'); } 'Connect.php' is required; $ Tbl_name = 'news'; $ Sql ​​= "SELECT id, title, description, content $ tbl_name ORDER id id ECCCL3"; $ Article = array (); $ Result = mysqli_query ($ conn, $ sql); $ Line = mysqli_fetch_array ($ result, MYSQLI_ASSOC); Printf ('& lt; p class = "sidenav" & gt; 1. & lt; a href = "../ news.php? Article =% o" & gt;% s & lt; / a & gt; Lt; / p & gt;, $ line ["id"], $ line ["title"]); ? & Gt;  

Now, as you can see, I have selected 3 rows, how can I get data from more than one row? Currently, if I have more than one line, then this will not output anything to specific id ?

Update: What is a way to indicate certain information without specifically selecting a line, but what if I have more than one Want to print?

  $ result = mysqli_query ($ conn, $ sql); While ($ row = mysqli_fetch_array ($ result, MYSQLI_ASSOC)) {printf ('& lt; p class = "sidenav" & gt; 1. & lt; a href = "../ news.php? Article =% o" & Gt;% s & lt; / a & gt; & lt; / p & gt; ', $ line ["id"], $ line ["title"]); Printf ('& lt; p class = "sidenav" & gt; 2. & lt; a href = "../ news.php? Article =% o" & gt;% s & lt; / a & gt; Lt; / p & gt;, $ line ["id"], $ line ["title"]); Printf ('& lt; p class = "sidenav" & gt; 3. & lt; a href = "../ news.php? Article =% o" & gt;% s & lt; / a & gt; Lt; / p & gt; ', $ line ["id"], $ line ["title"]);  

Please help!

  $ result = Mysqli_query ($ conn, $ sql); While ($ row = mysqli_fetch_array ($ result, MYSQLI_ASSOC)) {printf ('& lt; p class = "sidenav" & gt; 1. & lt; a href = "../ news.php? Article =% o" & Gt;% s & lt; / a & gt; & lt; / p & gt; ', $ line ["id"], $ line ["title"]); }  

No comments:

Post a Comment