Mysql query returns only the first letter of rows

Can someone please tell me what I am missing. The following sql query returns only the first letter of the rows extracted from my database:

 $result = mysql_query("SELECT * FROM users) or die("error in the query");

thank.

Update


$result = mysql_query("SELECT * 
                         FROM properties 
                         JOIN users USING(UserId) 
                        WHERE Level <> 'Admin' $pages->limit") or die("could not load all the properties"); 

$i=0; 
while($row = mysql_fetch_array($result)) { 
  $fn[$i] = $row ['FN']; 
  $ln[$i] = $row ['LN']; 
  $phone[$i] = $row ['Phone']; 
  $Email[$i] = $row ['Email']; 
} 

... the piece of code that gives me a headache from yesterday. $fn, $ln, $email and$ Phone` all contain only one character. I think the error is on my page, but I just do not see it. anything regarding a property contains a rite value

+3
source share
7 answers

If you use while()to distribute variables in an array, I do not think you need to use $iif you change the code to:

while($row = mysql_fetch_array($result)) { 
  $fn[] = $row ['FN']; 
  $ln[] = $row ['LN']; 
  $phone[] = $row ['Phone']; 
  $Email[] = $row ['Email']; 
}

$row['whatever'] ​​ . , ( , ); , .

:

`echo "<pre>" . print_r(get_defined_vars(),true) . "</pre>";

, , db , - .

+3

:

. ,

. , - , ( ), ,

+1

, - $ln, $ln, $phone $Email . , $i 0 , , mysql_fetch_array(), . , :

$tmp = 'A';
$tmp[0] = 'It does not matter how long this string is!';
echo $tmp;

, "I" .

:

$fn = $ln = $phone = $Email = array();
$i=0; 
while($row = mysql_fetch_array($result)) { 
    $fn[$i] = $row ['FN']; 
    $ln[$i] = $row ['LN']; 
    $phone[$i] = $row ['Phone']; 
    $Email[$i] = $row ['Email']; 
    ++$i;
} 

, .

"" , .

.

class User {
    public $first_name = '';
    public $last_name = '';
    public $phone_number = '';
    public $email = '';

    public function __construct($first, $last, $phone, $email) {
       $this->first_name = $first;
       $this->last_name = $last;
       $this->phone_number = $phone;
       $this->email = $email;
    }

    public function full_name() {
       return $first_name . ' ' . $last_name;
    }
}

while ($row = mysql_fetch_array($result)) { 
    $users[] = new User($row['FN'], $row['LN'], $row['Phone'], $row['Email']);
}

, IMHO, , , , .

+1

, foreach . SQL . , -

0

, . - :

$row = mysql_fetch_array($result);
echo $row[0];
0

, ...

$fn = array();

, while

0

. ( ).

, ($_GET) , , .

, .

So, as a reminder to lazy people, when you paste the old code into your page, double check the variable names! :)

0
source

Source: https://habr.com/ru/post/1727895/