PDA

View Full Version : Resource ID #7 (Not 17)



Independent
10-06-2008, 06:59 AM
$ham = mysql_query("SELECT * from logs");
echo $ham;
I get resource #7 error, when I do this, the file is already connected to the MySQL Database, I'm trying to show all table records from logs.

+REP for anyone who can help.

But I have to goto school in a min.

Jackboy
10-06-2008, 07:02 AM
$ham = mysql_query("SELECT * from `logs`");
while ($allrecords = mysql_fetch_array($ham)){
Print "$allrecords[FIELDNAME]";
}

It does a loop for each piece of data

change the FIELDNAME to the fieldname you wish to display obviously

Protege
10-06-2008, 11:53 AM
I'd change what jack put above:



$mysqlQuery = mysql_query( 'SELECT * from `logs`' );
while ( $r = mysql_fetch_array( $mysqlQuery ) )
{
echo ( $r[ 'fieldName' ] );
}

Agnostic Bear
10-06-2008, 12:09 PM
I'd change what jack put above:



$mysqlQuery = mysql_query( 'SELECT * from `logs`' );
while ( $r = mysql_fetch_array( $mysqlQuery ) )
{
echo ( $r[ 'fieldName' ] );
}


And I'd change what you used.


$mysqlQuery = mysql_query( 'SELECT * from `logs`' );
while ( false !== ( $r = mysql_fetch_array( $mysqlQuery ) ) )
{
echo( $r[ 'fieldName' ] );
}

Independent
10-06-2008, 03:04 PM
Ah I get it, thanks.. +REPing now.

Agnostic Bear
10-06-2008, 03:12 PM
$ham = mysql_query("SELECT * from `logs`");
while ($allrecords = mysql_fetch_array($ham)){
Print "$allrecords[FIELDNAME]";
}
It does a loop for each piece of data

change the FIELDNAME to the fieldname you wish to display obviously

stop using $var[var] it's alot slower unless you've defined FIELDNAME somewhere, use it as a string i.e: $var['var'] it works out something stupid like 5x faster.


What one works to display every field in the table.

Nether, you'd need to build some kind of foreach loop to go through, something like this:



foreach( $fetch as $key => $var )
{
if(!is_numeric($key))
{
echo($key . ' - ' . $var);
}
}

where $fetch is the mysql_fetch_array

Agnostic Bear
10-06-2008, 03:34 PM
Also Resource ID #* aren't errors, they're resources.

Jackboy
10-06-2008, 04:54 PM
stop using $var[var] it's alot slower unless you've defined FIELDNAME somewhere, use it as a string i.e: $var['var'] it works out something stupid like 5x faster.

I never knew that, cheers mate

Blob
10-06-2008, 06:15 PM
You get them when you echo a mysql_query

Want to hide these adverts? Register an account for free!