-
mysql_fetch_row problems with parameters...
Hi,
I got some problems with the function 'MYSQL_FETCH_ROW'. I encounter the typical "Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /bla/bla/... in line X.
There ist a lot of descriptions in the manual and many articles dealing with the problem, but I couldn't yet solve the issue.
Here is an example:
#Database connection an logon info skipped at this place...
$query = ("SELECT * FROM dbname");
$result = MYSQL_QUERY ($query);
function testoutput()
{
echo "\n<table>\n<tr>\n" .
"<br><th>X1</th>\n" .
"<br><th>X2</th>\n" .
"<br><th>X...</th>\n" .
"<br><th>Xn</th>\n";
while ($row = mysql_fetch_row ($result)
{
echo "<tr>\n";
foreach ($row as $data)
{
echo "<td> $data </td>\n";
echo "</tr>\n";
}
}
echo "</table>\n";
}
testoutput($result);
mysql_close;
As you might figure the only purpose of this script is generating an ordered and structured table with data from the DB....
So there is something I always stumble upon, the error described in the begining of the posting.
I guess it's a problem with the array and the method to pass it to the function.
Tanks for help...
Last edited by MuSQLe; 03-18-2003 at 07:33 AM.
-
Just print $result...
It is not a class (I don't think)
I believe I heard somewhere that it is the actual string sent from the server.
Actually, try this:
echo nl2br( $result );
See what comes out and let us know...
-
hmmmm... not what i wanted
Hi,
first of all thanks for your answer to the thread... but the change did not do what I wanted to do.
I put the altered sample code into a debug area of the script and extracted it from the while() loop to see its initial output. It returns the last value of the read array, in this case: "Resource id #5" which is Xn in the above given example.
Maybe I misinterpreted your code, so tell me what you think...
-
$query = ("SELECT * FROM dbname");
$result = MYSQL_QUERY ($query);
function testoutput()
{
echo "\n<table>\n<tr>\n" .
"<br><th>X1</th>\n" .
"<br><th>X2</th>\n" .
"<br><th>X...</th>\n" .
"<br><th>Xn</th>\n";
while ($row = mysql_fetch_row ($result)
{
echo "<tr>\n";
foreach ($row as $data)
{
echo "<td> $data </td>\n";
echo "</tr>\n";
}
}
echo "</table>\n";
}
testoutput($result);
mysql_close;
About the code...first
THE FUNCTION PROTOTYPE MUST HAVE THIS SIGNATURE:
function testoutput( $result_to_test )
{
//blah
}
Because you use it like this:
testoutput( $result );
Above in your source code you have:
function testoutput()
{
USE THIS CODE BELOW TO REPLACE THE SNIPPET YOU GAVE US:
$query = ("SELECT * FROM dbname");
$result = MYSQL_QUERY ($query);
function testoutput( $result_in_fn )
{
echo "\n<table>\n<tr>\n" .
"<br><th>X1</th>\n" .
"<br><th>X2</th>\n" .
"<br><th>X...</th>\n" .
"<br><th>Xn</th>\n";
while ( $row = mysql_fetch_row ($result_in_fn) )
{
echo "<tr>\n";
foreach ($row as $data)
{
echo "<td> $data </td>\n";
echo "</tr>\n";
}
}
echo "</table>\n";
}
testoutput($result);
mysql_close;
-
A little relief...
Yep, that helped at least a little for he prints the data now.
Still the output is not what I want, but I'll creep on that for myself.
I guess I should buy myself a new book, cause the one I'm learning with potetionally SUCKS!!!!!
If the book was good, I wouldn't have all these boring questions...
Thanx
-
What are you really trying to do?
What are you really trying to get it to do?
You were doing it correctly.
What happened was that your function was not actually getting the parameter that you were passing it. Then when $result was accessed from your function, it did not exist, so it was created, but it was not created as a properly formatted MySQL result.
You were accessing the data correctly. It was just your test function that had gone off the path.
Last edited by rwendel; 03-19-2003 at 10:22 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|