Tarık Baysal Tarık Baysal - 28 days ago 6x
PHP Question

PHP FETCH data from db on row by row not column

I need to fetch data from my db. I've done it but when I say fetch array [1], the output is the all second letters in all rows. Here is the code:

include "baglan2.php";

$query = $db->query("SELECT * FROM diziler", PDO::FETCH_ASSOC);
if ( $query->rowCount() ){
foreach( $query as $row ){
echo ($row['link']. "<br />");

I tried it with msqli but saw the same result; here is the mysqli code:

$query = mysqli_query($baglanti, "SELECT * FROM diziler");
if ( mysqli_affected_rows($baglanti) ){
while ( $row = mysqli_fetch_assoc($query) ){
print $row['link'][1]."<br />";

For instance all my data are links. When I run print
, it gives "t" letter from "http:" in all rows. I need to fetch my data by row not column. I have tried every method possible. However I couldn't find any method that worked.

for instance I want to make this codes output
in each element.


I am giving solution based on second attempt:-

$query = mysqli_query($baglanti, "SELECT link FROM diziler"); 
$link_array = array(); 
if ( $query){ 
    while ( $row = mysqli_fetch_assoc($query) ){ 
               $link_array[] = $row['link']; 
echo "<pre/>";print_r($link_array); // it have all the links

Reason:- https://eval.in/649070

It's specification is given here:- http://stackoverflow.com/a/17193651/4248328

That is:- $string[int] is syntactic sugar for substr($string, int, 1)