Asked  7 Months ago    Answers:  5   Viewed   30 times

Ok i execute this

$table = get_personel_table(1);
function get_personel_table($id)
    {
        global $connection;
        $query  = "SELECT * ";
        $query .= "FROM employees ";
        $query .= "WHERE id=" . $id . " ";
        $query .= "ORDER BY id ASC";
        $query_result = mysql_query( $query , $connection );
        confirm_query($query_result);
        $query_result_array = mysql_fetch_array($query_result);
        return $query_result_array; // returns associative array!;
    }

and i do foreach

foreach($table as $table_var)
{
    echo "<td>" . $table_var . "</td>";
} 

and by doing so i get double output ... "1 1 1 1 jordan jordan 9108121544 9108121544 testEmail testEmail testAddress testAddress testCounty testCounty"

this below is the result of print_r

 Array
    (
        [0] => 1
        [id] => 1
        [1] => 1
        [department_id] => 1
        [2] => jordan
        [name] => jordan
        [3] => 9108121544
        [EGN] => 9108121544
        [4] => testEmail
        [email] => testEmail
        [5] => testAddress
        [address] => testAddress
        [6] => testCounty
        [country] => testCounty
    )

The information i have in the database is id =>1 , department_id => 1 , and so on ... My question is why i get double feedback(i don't know how to call it) , 0 = id , 1 = department_id , 2 = name and so on ..

and when i do foreach( ... ) i get everything doubled.

 Answers

40

From the manual:

mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both

By default, mysql_fetch_array gives both associative and numeric indexes. You don't want this. You can limit it with the second parameter:

$query_result_array = mysql_fetch_array($query_result, MYSQL_NUM); // numeric keys only
$query_result_array = mysql_fetch_array($query_result, MYSQL_ASSOC); // associative keys only

You can also use mysql_fetch_row to only get numeric keys, or mysql_fetch_assoc to only get associative keys.

$query_result_array = mysql_fetch_row($query_result); // numeric keys only
$query_result_array = mysql_fetch_assoc($query_result); // associative keys only
Wednesday, March 31, 2021
 
commonpike
answered 7 Months ago
71

you can't print the result from mysqli_query, it is mysqli_resource and for dumping the error you need to change mysql_error() to mysqli_error()

$username = "bob";
$db = mysqli_connect("localhost", "username", "password", "user_data");
$sql1 = "select id from user_information where username='$username'";
$result = mysqli_query($db, $sql1) or die(mysqli_error());
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 
    echo $row['id'].'<br>'; 
} 
Saturday, May 29, 2021
 
pamelus
answered 5 Months ago
39

yo need create the user "pma" in mysql or change this lines(user and password for mysql):

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

Linux: /etc/phpmyadmin/config.inc.php

Tuesday, July 13, 2021
 
ShadowZzz
answered 3 Months ago
65

It's already double buffered, that's what the unlockCanvasAndPost() call does. There is no need to create a bitmap.

Thursday, July 29, 2021
 
ericstumper
answered 3 Months ago
34
int a[] = {1, 2, 3, 4, 5};
int i = 1; // Second index number of the array a[]
a[i]++;
printf("%d %dn", i, a[i]);
a[i++];
printf("%d %dn", i, a[i]);

Output

1 3
2 3

a[i]++ increments the element at index i, it doesn't increment i. And a[i++] increments i, not the element at index i.

Saturday, September 4, 2021
 
Kai
answered 2 Months ago
Kai
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :