I may be incorrect, but I do not think that by "redefining" the variable $pic is destroying its old contents. If you are familiar with how programming works, you realize that the "stuff" on the right side of the "=" sign is evaluated first, and then assigned to the left side of the "=" sign. Because $pic is in the mysql_fetch_array($pic) (on the right), $pic is evaluated before it ever gets "destroyed" by the redefining.

PHP may not be this way, but I think that it is. If I am incorrect, please let me know. I hope this helps out (with something).

~Philip


On Jun 23, 2004, at 11:47 AM, Cole S. Ashcraft wrote:

Kim,

Won't redefining the variable destroy the MySQL Resource, resulting in a resource invalid error, like he has?

$pic = mysql_query($sql,$connection); //Defines variable
$pic //Redefining variable, dumps old contents = //calling on an invalid MySQL Resource, because it doesn't exist mysql_fetch_array($pic);
My comments are in green.


Cole

Kim Steinhaug wrote:

Well, your query looked confusing to me, but break it up like this

First :
select
Then, name your coloumns, seperate with commas, or use wildcard for all
*
Define from what table you need to select
FROM database_table
Add some select statements with WHERE
WHERE
and the statements itself
1=1


What did I just write now? Looking at your example I guess :
1. you need the coloumns : Rune, username
2. your table : RuneRunner
3. your select criteria : UserID=3

I would then write your SQL query as this :

$sql = "SELECT Rune, username FROM RuneRunner WHERE UserID=3";

Then you could do your code,
$pic = mysql_query($sql,$connection);
$pic = mysql_fetch_array($pic);

You would also want to add a database abstraction layer, as for debugging
purposes this will make your life much easier.


Your original code looks to correct if you rewrite it abit, like this :

SELECT RuneRunner_1.Rune, RuneRunner_1.username FROM RuneRunner RuneRunner_1
WHERE (RuneRunner_1.User_ID=3);


Not tested but it should work fine. On the other hand, the referencename
after the
table name should be a short one to make the statement much easier to read,
somthing like :


SELECT rr.Rune, rr.username FROM RuneRunner rr WHERE (rr.User_ID=3);

Then again, since you only have one table in your statement there is no need
for the reference name,
and since your WHERE clause is a single statement there is no need for the
paranthese either.
So you are still back to :


SELECT Rune, username FROM RuneRunner WHERE User_ID=3;

--
--
Kim Steinhaug
----------------------------------------------------------------------
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
----------------------------------------------------------------------
www.steinhaug.com - www.easywebshop.no - www.webkitpro.com
----------------------------------------------------------------------

"Water_foul" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

why doesn't this work:
$pic=mysql_query('SELECT     Rune, username FROM         RuneRunner
RuneRunner_1 WHERE     (User_ID = 3)',$connection);
$pic=mysql_fetch_array($pic);





--
This message has been scanned for viruses and
dangerous content by MailScanner, and is believed to be clean.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to