Datebase Class??

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Datebase Class??

Post by AndrewBacca »

Hi,

im tring to create a database class
i have it connectig using it

and i can select the first record. BUT i want to be able to select ALL records from the database (well the ones that match the query). so that i can access them after teh function has run

This what i have so far

Code: Select all

$query = "SELECT * FROM forensis_post_formating";
$result = $myDB->query_select($query);
then in the db class file

Code: Select all

function query_select($query)
{
	$result  = mysql_query($query);
	return $result;
}
then back in the other file

Code: Select all

$fetch = $myDB->Fetch($result);
is that which calls

Code: Select all

function Fetch($result)
  {
    $fetch = mysql_fetch_array($result);

    return $fetch;
  	}
back to the other file!

Code: Select all

print $fetchї3];


that last line prints the field of the first record depending on ghe number

if you need more details of what am i after, ill try to give me

cheers

Andrew
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

[php_man]while[/php_man] will certainly be of use, e.g.

Code: Select all

<?php
while ($fetch[] = mysql_fetch_array($result))
   {}
return $fetch;
?>
There are some fantastic books out there which can guide you through common PHP problems like this. I most certainly recommend PHP Anthology - you can download some sample chapters to check it out and it does teach you about best practice coding.

http://www.sitepoint.com/launch/24dc6f

And no, I am not gaining anything from recommending this book. ;)
Post Reply