note 55055 added to function.sqlite-fetch-single
| From: | jmarbas at hotmail dot com | Date: | Sun, 24 Jul 2005 00:45:02 +0000 |
| Subject: | note 55055 added to function.sqlite-fetch-single | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92354@lists.php.net to get a copy of this message | ||
It isnt specified in the above description for this function, but yes this function will not only
return the first column, but it will also return the first value (ie from the first row in the
result set) of that column. Also the result set pointer is involved here in that if you use
sqlite_fetch_single in a loop, it will return each value in the first column sequentially and
advance the result set pointer each time.
i.e. the first loop iteration it returns the first value in the first column. the second loop
iteration it returns the second value in the first column. the third loop iteration the third value
and so on.
$handle = sqlite_open("database_file_name") or die("Could not open database");
//generate query string
$query = "select distinct field1 from database_name";
//execute query
$result = sqlite_query($handle,$query)
//if a row exists
if(sqlite_num_rows($result)>0){
echo "<table cellpadding=\"10\" border=\"1\">";
//check for more rows
while(sqlite_has_more($result)){
//get first field from each row
//print values
$row=sqlite_fetch_single($result);
echo "<tr>";
echo "<td>".$row."</td>";
echo "</tr>";
}
echo "</table>";
}
//close database file
sqlite_close($handle);
----
Manual Page -- http://www.php.net/manual/en/function.sqlite-fetch-single.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55055
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55055&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55055&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55055&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55055&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55055&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55055&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55055&report=yes
Search -- http://master.php.net/manage/user-notes.php