Home    Back    Forward    Refresh    txtSQL Homepage

select
Purpose: To select data from a txtSQL table
txtSQL >= 2.2.2 RC2
mixed select ( array( 'table' => $table [, 'select' => $selectCols[, 'db' => $db [, 'where' => $where [, 'limit' => $limit [, 'orderby' => $orderb[, $distinct = $column]]]]] ) )

This function will retrieve data that matches the $where clause; if no $where clause is given, all rows match, and thus will be returned. If $selectCols is specified, then txtSQL will only select those columns. $selectCols should be an array with the following structure
     array ( col1, col2 ... )

The search will look inside the selected database if no $db is defined, and will return rows according to the limit clause. If $orderby is specified, then the results will be sorted according to the orderby clause. If $distinct is set to TRUE, then the any repeated values for that $column will be deleted.

Important- To achieve the same results as this function before txtSQL 2.2.2 RC2, use the execute() function
Note- The DISTINCT feature was added in txtSQL 2.2 Final release
Note- For more information on defining a where clause, see the 'where clause' section, or for defining a limit clause, see how to create a limit clause section
Note- If no database is selected, and no $db is given, txtSQL will issue an error


Example 15: select() Copy to clipboard
<?php
$data
= $sql->select(array(
    
'db'      => 'testDB',
    
'table'   => 'testTable',
    
'where'   => array('strtolower(somecolumn) = value'),
    
'limit'   => array(10, 19),
    
'orderby' => array('id', 'ASC')
    ));

foreach (
$data as $key => $row )
{
    print
'Row '.$key.': '.print_r($row,1)."<br>\n";
}
?>


User Comments - select
FarazAli <FarazAli at gmail dot com>
March 3, 2005, 10:03 pm
Please post questions at the forums (http://chibiguy.dotgeek.org)!

---

Just place the $sql->select() part inside of count() and you should be left with a count of how many records were returned

$data = count($sql->select(array(
'db' => 'testDB',
'table' => 'testTable',
'where' => array('strtolower(somecolumn) = value'),
'limit' => array(10, 19),
'orderby' => array('id', 'ASC')
)));
baKer <baker_ax at hotmail dot com>
March 3, 2005, 9:30 pm
How can I get the count of the returned recordset? Thanks.
Envel <quasiyodel at gmail dot com>
February 10, 2005, 6:42 pm
If you don't want to use a foreach() loop, you can see how txtSQL returns the values of arrays by executing a select statement:

$variable = $sql->select(array(
'table' => 'data',
'db' => 'testDB'
));

Then perform a variable dump with the code:

var_dump($variable);

for more info on how to read the output of this, go to the php-manual page:
http://php.net/var_dump

FarazAli <Faraz87 at comcast dot net>
July 30, 2004, 11:19 pm
You can specify what columns you want to select by adding something like

'select' => array('column', 'column2' ...)

to the array.

Example:
$sql->select(array(
'select' => array('id', 'name'),
'table' => 'data',
'db' => 'testDB'
));
Last Page Next Page

'Language Reference'

User Functions

Database Functions

Data Manipulation Functions
  • select
  • insert
  • update
  • delete
  • execute

    Table Functions

    Error Handling Functions

    SQL Syntax

  • [ txtSQL Documentation powered by txtSQL | 6 SQL Queries ]