DB functions

Hi

Suppose this will be a good time to mention that I'm totally new to Zoop and PHP for that fact. I'm more skilled in ASP.NET so excuse my ignorance when it comes to my questions..

I've been following the Zoop documentation on Wayback machine and just have a couple of questions on the DB section.. There are a couple of zoop db functions listed with there apparent results.

Example.
sql_fetch_rows("select * from users2")

//Results
Array
(
[0] => Array
(
[userid] => 1
[first_name] => Steve
[last_name] => Tester
[email_address] => test@testing.com
[username] => Tester
[password] => IloveTesting3
[info] => I am L33t
[last_login] => 0000-00-00 00:00:00
[activated] => 0
)

[1] => Array
(
[userid] => 2
[first_name] => John
[last_name] => Tester
[email_address] => testingrocks@testing.com
[username] => test4me
[password] => TestingIsInMYBlood
[info] =>
[last_login] => 0000-00-00 00:00:00
[activated] => 1
)
)

When I try to run that function and echo the results i just get "Array" as the results and nothing like the supposed example results.

My code
function pageRecords($inPath)
{
$results = sql_fetch_rows("select * from users2");
echo $results;
}

I've had a look at PHP.net to try make use of some of the mysql functions on there, but doesn't look I can pass them the zoop sql function results to handle.

Am i doing something wrong? Is there more to do to achieve similar results like in the example?

If anyone has any other good Zoop tutorials or examples regarding DB interaction it would be great...

Chris

Another Question

Can someone please tell me what i'm missing here...

I'm following this tutorial on Wayback Machine (http://web.archive.org/web/20070216191238/zoopframework.com/ss.4/7020/Fr...)

When i try implement the first bunch of code in the example and try run it i get the following error.

Fatal error: Class 'form' not found in C:\xampp\htdocs\opwall2008\zone_users.php on line 42.

I've checked my includes.php and made sure the 'forms' component is enabled. Is there anything else i'm missing?

Chris

ChrisB 18 Jul 2008

You are missing one of the Zoop components includes

First welcome to Zoop as it will make a lot of sense transitioning from .NET. You are missing an include for one of the Zoop Components called form. The page you are attempting to access in the zone_users calls the forms class to do something. Edit your includes.php file and uncomment or add the line below:

$zoop->addComponent('forms');

FYI it looks like you are running XAMPP (a windows based web server package for others reading this that don't know) and if you are still have trouble with the includes after uncommenting the line you may want to check the post below for help with windows includes.

http://www.zoopframework.com/forum/bugs/problem-with-database

jmorant@cloud9l... 23 Jul 2008

You are seeing the correct output

The results you are getting from the database query are an array so when you call echo you will only have the type printed for the variable. To traverse and print an array in PHP you will want to call print_r or in Zoop you can use echo_r which is print_r wrapped with to make it display in a HTML compatible fashion.

Since you are new to PHP you are probably not familiar with associative arrays. In .NET and JavaScript they are referred to as HASH tables and they are the bread and butter when working with arrays in PHP that relate to SQL data. In the post above I would work with it slightly differently to reduce some over head and make my array indexes the primary table key.

function pageRecords($inPath)
{
$results = sql_fetch_assoc("select * from users2");
echo $results;
}
 
$rows = sql_fetch_assoc("select * from users2");
echo_r($rows);
foreach($rows as $userid=>$data) {
echo "Hello ".$data['first_name'].'<br />';
}
 
 
//Results, Now the array indexes on userid assuming userid is the primary key
Array
(
[1] => Array
(
[first_name] => Steve
[last_name] => Tester
[email_address] => test@testing.com
[username] => Tester
[password] => IloveTesting3
[info] => I am L33t
[last_login] => 0000-00-00 00:00:00
[activated] => 0
)
 
[2] => Array
(
[first_name] => John
[last_name] => Tester
[email_address] => testingrocks@testing.com
[username] => test4me
[password] => TestingIsInMYBlood
[info] =>
[last_login] => 0000-00-00 00:00:00
[activated] => 1
)
)
Hello Steve
Hello John

jmorant@cloud9l... 23 Jul 2008