SQLite SELECT


SELECT is something you really need to know, because without it, whats the point of using SQL if you can't get it out?

Unlike other SQL Commands, this requires a few extras to get the data out.

Here is an example:

/* $con is the SQLite Handle */
$result sqlite_query($con"SELECT * FROM table"$result_type$query_error);
/* But thats not all */
while($row sqlite_fetch_array($result)) {
  
/*
    The variable $row is accessible for each individual row
    If you have a column id, you can do echo $row['id']; 
    and it will echo that rows ID, you can do it for any column
  */
}


Break it down
SELECT * FROM table - This is the SELECT Statement, this will select all columns (Thats what the * means) from all rows in the tables. You can refine this by doing SELECT * FROM table WHERE id = 1, of course not always WHERE id = 1, but you can indeed use the WHERE statement in that query to pull out specifics.

sqlite_fetch_array($result) - This function fetches the row from $result (Which was set to the sqlite_query), once it has gone through them all, it returns false, which stops it.

Here is a more specific tutorial on the * in SELECT * FROM, lets say you had this SQLite Table:


CREATE TABLE pages (
  page_id INT,
  title TEXT,
  content TEXT
);


And all you wanted to get from the table was title and content, it would look like this...


/* $con is the SQLite Handle */
$result sqlite_query($con"SELECT title, content FROM table WHERE page_id = 1");
while(
$row sqlite_fetch_array($result)) {
  echo 
$row['title'];
  echo 
$row['content'];
}


Thats it! And if you were to do echo row['page_id']; you would get nothing, as you did not select that column.