Re: [PHP] data from database

2003-10-29 Thread alain dhaene
it works,

thanks,

Alain

John Nichel [EMAIL PROTECTED] schreef in bericht
news:[EMAIL PROTECTED]
 alain dhaene wrote:
  Hi,
 
  I will write a function that returns the result of a recordset.
  I tried this:
 
Function getPersonen()
{
 openDB();  //function that I implements in another file
 
 
   $query = SELECT * FROM Cursisten;
   $result = mysql_query($query)
   or die(Fout bij uitvoeren query);
 
   $resultrow = mysql_fetch_array( $result );

 Get rid of the above line, unless you plan on passing the array.  From
 the looks below, you want to pass the identifier though.  If you do want
 to pass the result array instead of the identifier, leave as is.

   closeDB();   //function that I implements in another file
 mysql_free_result($result);

 If you are going to pass the identifier, you just killed it here.  If
 you are going to pass the data array, swap these two lines, ie free your
 result before you close your connections.

  return $resultrow;

 Change this line to...

 return $result

 if you are not planning on passing the array.

}
 
  I call this function:
 
  $resultaat =  getPersonen();
// Printen resultaten in HTML
   print table\n;
   while ($line = mysql_fetch_array($resultaat, MYSQL_ASSOC)) {

 What you do with this, all depends on how you rewrite your function.  If
 you're passing the identifier, you can leave it as is, if you're passing
 the result data array, you need to get rid of the while loop.

   print \ttr\n;
   foreach ($line as $col_value) {
   print \t\ttd$col_value/td\n;
   }
   print \t/tr\n;
   }
   print /table\n;
 
   In runtime I have the following error
 
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
  result resource in
  /home/schoolre/public_html/Hitek/Online/Registratie/showPerson.php on
line 8
 
  What is wrong?

 Alot, I suggest you check out the MySQL functions

 http://us4.php.net/manual/en/ref.mysql.php

 --
 By-Tor.com
 It's all about the Rush
 http://www.by-tor.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] data from database

2003-10-28 Thread alain dhaene
Hi,

I will write a function that returns the result of a recordset.
I tried this:

  Function getPersonen()
  {
   openDB();  //function that I implements in another file


 $query = SELECT * FROM Cursisten;
 $result = mysql_query($query)
 or die(Fout bij uitvoeren query);

 $resultrow = mysql_fetch_array( $result );

 closeDB();   //function that I implements in another file
   mysql_free_result($result);

return $resultrow;

  }

I call this function:

$resultaat =  getPersonen();
  // Printen resultaten in HTML
 print table\n;
 while ($line = mysql_fetch_array($resultaat, MYSQL_ASSOC)) {
 print \ttr\n;
 foreach ($line as $col_value) {
 print \t\ttd$col_value/td\n;
 }
 print \t/tr\n;
 }
 print /table\n;

 In runtime I have the following error

  Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in
/home/schoolre/public_html/Hitek/Online/Registratie/showPerson.php on line 8

What is wrong?

Alain

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] data from database

2003-10-28 Thread Gregory Kornblum
$result = mysql_query($query)

You need to pass the connection resource returned from your mysql_connect
call as a second parameter. Regards.

-Gregory

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] data from database

2003-10-28 Thread John Nichel
Gregory Kornblum wrote:
$result = mysql_query($query)


You need to pass the connection resource returned from your mysql_connect
call as a second parameter. Regards.
-Gregory

While it is a good practice to do this, it is not necessary...

If link_identifier isn't specified, the last opened link is assumed. If 
no link is open, the function tries to establish a link as if 
mysql_connect() was called with no arguments, and use it. The result of 
the query is buffered.



--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] data from database

2003-10-28 Thread John Nichel
alain dhaene wrote:
Hi,

I will write a function that returns the result of a recordset.
I tried this:
  Function getPersonen()
  {
   openDB();  //function that I implements in another file
 $query = SELECT * FROM Cursisten;
 $result = mysql_query($query)
 or die(Fout bij uitvoeren query);
 $resultrow = mysql_fetch_array( $result );
Get rid of the above line, unless you plan on passing the array.  From 
the looks below, you want to pass the identifier though.  If you do want 
to pass the result array instead of the identifier, leave as is.

 closeDB();   //function that I implements in another file
   mysql_free_result($result);
If you are going to pass the identifier, you just killed it here.  If 
you are going to pass the data array, swap these two lines, ie free your 
result before you close your connections.

return $resultrow;
Change this line to...

return $result

if you are not planning on passing the array.

  }

I call this function:

$resultaat =  getPersonen();
  // Printen resultaten in HTML
 print table\n;
 while ($line = mysql_fetch_array($resultaat, MYSQL_ASSOC)) {
What you do with this, all depends on how you rewrite your function.  If 
you're passing the identifier, you can leave it as is, if you're passing 
the result data array, you need to get rid of the while loop.

 print \ttr\n;
 foreach ($line as $col_value) {
 print \t\ttd$col_value/td\n;
 }
 print \t/tr\n;
 }
 print /table\n;
 In runtime I have the following error

  Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in
/home/schoolre/public_html/Hitek/Online/Registratie/showPerson.php on line 8
What is wrong?
Alot, I suggest you check out the MySQL functions

http://us4.php.net/manual/en/ref.mysql.php

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php