Forum Moderators: coopster
I'm slowly learning this PHP lark, but keep running into problems that make me want to bang my head against a particuarly blunt wall. This is one of them...
Below is part of larger script I'm working on:
$searchterm3 = mysql_query("SELECT `data_txt` FROM jos_sobi2_fields_data WHERE `fieldid` = 16 AND `itemid` = 1");
echo($searchterm3);
The echo for this results in just "Resource id #3"
For other records (changing the 1 to 2, 3, 4, etc) it changes the Resource id to 4, 5, 6, etc.
I can't work out why this is as the SQL works in the query browser fine.
Currently I'm just echo-ing the searchterm for testing, but it is supposed to feed into something else later.
Anybody got any smart ideas what's wrong here? Thanks! :)
you need to use a function such as mysql_fetch_array in a loop afterwards using the resource id to return the actual data from mysql
[php.net...]
Return ValuesFor SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.
Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.