Re: data from database
| From: | John Nichel | Date: | Tue, 28 Oct 2003 20:19:13 +0000 |
| Subject: | Re: data from database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-167930@lists.php.net to get a copy of this message | ||
alain dhaene wrote:
Hi, I will write a function that returns the result of a recordset. I tried this: Function getPersonen() {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.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 );
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.closeDB(); //function that I implements in another filemysql_free_result($result);
Change this line to... return $result if you are not planning on passing the array.return $resultrow;
} I call this function: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.$resultaat = getPersonen();// Printen resultaten in HTML print "<table>\n"; while ($line = mysql_fetch_array($resultaat, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$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