0

I've recently started working with PHP and SQLite and I'm having problems with PHP arrays (I think). This is the code I use:

<?php
$dbo = new SQLiteDatabase("rsc/db.sqlite");
$test = $dbo->arrayQuery("DROP TABLE users;");
$test = $dbo->arrayQuery("CREATE TABLE \"users\"(name text, avatar text);");
$test = $dbo->arrayQuery("INSERT INTO users(name, avatar) VALUES('zad0xsis', 'http://zad0xsis.net/');");

// get number of rows changed
$changes = $dbo->changes();
echo "<br />Rows changed:  $changes<br />";

// Get and show inputted data
$tableArray = $dbo->arrayQuery("SELECT * FROM users;");
echo "Table Contents\n";
echo "<pre>\n";
print_r($tableArray);
echo "\n</pre>";

?>

And when showing the data (print_r($tableArray);) I get this array:

Array
(
    [0] => Array
        (
            [0] => zad0xsis
            [name] => zad0xsis
            [1] => http://zad0xsis.net/
            [avatar] => http://zad0xsis.net/
        )

)

I don't know why the values are duplicated, like [0] and [name], but it shows the data. Now, when I try to do print_r($tableArray["name"]); I should get the value, but it doesn't prints anything :( What I'm doing wrong? Thanks!

3
  • echo $tableArray[0]["name"]; perhaps Commented Jul 19, 2011 at 11:11
  • Try printing like thisc echo $tableArray[0]['name']; ` Commented Jul 19, 2011 at 11:11
  • 1
    you get value duplicate because you're using mysql_fetch_array statement like, try mysql_fetch_assoc for single value Commented Jul 19, 2011 at 11:13

1 Answer 1

3

it helps you to select both

$tableArray[0] 

or

$tableArray['name'];

it's fine.

to your problem: You'll have to

print_r($tableArray[0]['name'])

or

print_r($tableArray[0][0])

Sign up to request clarification or add additional context in comments.

1 Comment

I'll accept the answer in 7 minutes, when StackOverflow allows me ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.