PDA

View Full Version : Help finding a error in the code.


vorl
02-01-2008, 03:54 AM
Hi

Here is the code:

$result = mysql_query( "SELECT * FROM events" ) ;

$meta = mysql_fetch_field($result, 2);
$testdata = $meta->name;
echo "The field name is: <b>" . $testdata . "</b>";


$first = mysql_query( "SHOW FULL COLUMNS FROM events LIKE '".$testdata."'");
$second = mysql_fetch_array($first);
echo "The comment in the field is: <b>" . $second[Comment] . "</b>";


The problem which I am having is the last line where its supposed to return the contents of the column 'Comment'.
I think the problem (but not 100% sure) has to do with the following line, and thats why it isnt displaying the Comment:


$first = mysql_query( "SHOW FULL COLUMNS FROM events LIKE '".$testdata."'");


Any advise is greatly appreciated! :)

oesxyl
02-01-2008, 04:12 AM
The problem which I am having is the last line where its supposed to return the contents of the column 'Comment'.
I think the problem (but not 100% sure) has to do with the following line, and thats why it isnt displaying the Comment:


usualy is easy to debug the query if you see it in action, :)


$query = "SHOW FULL COLUMNS FROM events LIKE '".$testdata."'";
echo $query;
$first = mysql_query($query);
$second = mysql_fetch_array($first);
echo "The comment in the field is: <b>" . $second[Comment] . "</b>";


I think that the error is the value of $testdata, it must be a field name:

http://dev.mysql.com/doc/refman/5.0/en/show-columns.html

best regards

vorl
02-01-2008, 04:18 AM
hi thanks for the reply.

I forgot to mention the first 4 lines get me the field name. So I dont think thats the issue. :(
Also I should add that if I manually put in the field name in the following it works fine:


SHOW FULL COLUMNS FROM events LIKE '".$testdata."'"


Any other suggestions? :confused: Thanks again!:)

oesxyl
02-01-2008, 04:28 AM
hi thanks for the reply.

I forgot to mention the first 4 lines get me the field name. So I dont think thats the issue. :(
Also I should add that if I manually put in the field name in the following it works fine:

that's prove, in my opinion, that first query don't get the correct value.
the code from my replay is easy to use with both query, :)

the syntax of first query seem ok for me, maybe the offset 2 in this case, is > number of columns, but this is a presumption, :)
could be something else, trace it with echo, :)


I forgot, :), this could help:

echo mysql_error();



best regards

vorl
02-01-2008, 05:06 AM
I dont believe it...sorted!
You were sort of right in thinking there was something wrong in the first 4 lines! That offset 2 corresponded to the 2nd field and silly me, didnt have a comment on that field! :o And the field name when manually testing was a different field. :rolleyes:

I feel so stupid at the moment! Thanks anyway mate, you were a great help in finding this error :thumbsup:

Cheers! :)

oesxyl
02-01-2008, 05:12 AM
with pleasure any time, :)

best regards