newbie help with mysql_fetch_array

newbie help with mysql_fetch_array

am 14.01.2008 19:22:04 von sixstringsin

##in the mysql query below, i am selecting a few fields from the masks
table:-

$mask_query = "SELECT mask_id, mask_name, mask_dynamic FROM masks
where mask_project = $project_id AND mask_parent = $phase_id";

##next i am storing the return value to a variable (on executing the
script, I donot get any mysql error so i assume the query ran fine:-

$mask_res = mysql_query($mask_query) or die("can't run query
[$mask_query]: ".mysql_error());

##now i intend to print the field called mask_name on the browser:-

$tc_array = mysql_fetch_array($mask_res, MYSQL_ASSOC);
$tc_name = $tc_array["mask_name"];
print "mask Name:".$tc_array['mask_name'] . " ";


##However, what is printed is the string mask Name, followed by a
blank. The mask_name field from the db is ##not retrieved. Where am i
going wrong? Appreciate any help!

Re: newbie help with mysql_fetch_array

am 14.01.2008 19:31:17 von luiheidsgoeroe

On Mon, 14 Jan 2008 19:22:04 +0100, wrote:

> ##in the mysql query below, i am selecting a few fields from the masks=

> table:-
>
> $mask_query =3D "SELECT mask_id, mask_name, mask_dynamic FROM masks
> where mask_project =3D $project_id AND mask_parent =3D $phase_id";
>
> ##next i am storing the return value to a variable (on executing the
> script, I donot get any mysql error so i assume the query ran fine:-
>
> $mask_res =3D mysql_query($mask_query) or die("can't run query
> [$mask_query]: ".mysql_error());
>
> ##now i intend to print the field called mask_name on the browser:-
>
> $tc_array =3D mysql_fetch_array($mask_res, MYSQL_ASSOC);
> $tc_name =3D $tc_array["mask_name"];
> print "mask Name:".$tc_array['mask_name'] . " ";
>
>
> ##However, what is printed is the string mask Name, followed by a
> blank. The mask_name field from the db is ##not retrieved. Where am i
> going wrong? Appreciate any help!

var_dump() & print_r() are your friends when determining what a variable=
=

actually holds. Maybe there's no matching rows (check with =

mysql_num_rows()), or mask_name is indeed blank, maybe even something =

else (mask name =3D '

' for instance wouldn't show up in a browser giv=
en =

content-type text/html, as it would assume this to be an HTML tag).
-- =

Rik Wasmus

Re: newbie help with mysql_fetch_array

am 14.01.2008 19:31:37 von Michael Fesser

..oO(sixstringsin@yahoo.co.in)

>##in the mysql query below, i am selecting a few fields from the masks
>table:-
>
>$mask_query = "SELECT mask_id, mask_name, mask_dynamic FROM masks
>where mask_project = $project_id AND mask_parent = $phase_id";
>
>##next i am storing the return value to a variable (on executing the
>script, I donot get any mysql error so i assume the query ran fine:-
>
>$mask_res = mysql_query($mask_query) or die("can't run query
>[$mask_query]: ".mysql_error());
>
>##now i intend to print the field called mask_name on the browser:-
>
> $tc_array = mysql_fetch_array($mask_res, MYSQL_ASSOC);
> $tc_name = $tc_array["mask_name"];
> print "mask Name:".$tc_array['mask_name'] . " ";
>
>
>##However, what is printed is the string mask Name, followed by a
>blank. The mask_name field from the db is ##not retrieved. Where am i
>going wrong? Appreciate any help!

Make sure that error_reporting is set to E_ALL|E_STRICT in your php.ini
and display_errors is enabled. Do you get any notices when you run the
code? Does the query actually return anything? What does a

var_dump($tc_array);

show?

Micha

Re: newbie help with mysql_fetch_array

am 14.01.2008 20:15:32 von sixstringsin

On Jan 14, 11:31 pm, Michael Fesser wrote:
> .oO(sixstring...@yahoo.co.in)
>
>
>
> >##in the mysql query below, i am selecting a few fields from the masks
> >table:-
>
> >$mask_query = "SELECT mask_id, mask_name, mask_dynamic FROM masks
> >where mask_project = $project_id AND mask_parent = $phase_id";
>
> >##next i am storing the return value to a variable (on executing the
> >script, I donot get any mysql error so i assume the query ran fine:-
>
> >$mask_res = mysql_query($mask_query) or die("can't run query
> >[$mask_query]: ".mysql_error());
>
> >##now i intend to print the field called mask_name on the browser:-
>
> > $tc_array = mysql_fetch_array($mask_res, MYSQL_ASSOC);
> > $tc_name = $tc_array["mask_name"];
> > print "mask Name:".$tc_array['mask_name'] . " ";
>
> >##However, what is printed is the string mask Name, followed by a
> >blank. The mask_name field from the db is ##not retrieved. Where am i
> >going wrong? Appreciate any help!
>
> Make sure that error_reporting is set to E_ALL|E_STRICT in your php.ini
> and display_errors is enabled. Do you get any notices when you run the
> code? Does the query actually return anything? What does a
>
> var_dump($tc_array);
>
> show?
>
> Micha

thanks a lot for the help. Indeed var_dump($tc_array)
prints:bool(false). So is it that the mysql query is going wrong?

Re: newbie help with mysql_fetch_array

am 14.01.2008 20:20:57 von Jerry Stuckle

sixstringsin@yahoo.co.in wrote:
> On Jan 14, 11:31 pm, Michael Fesser wrote:
>> .oO(sixstring...@yahoo.co.in)
>>
>>
>>
>>> ##in the mysql query below, i am selecting a few fields from the masks
>>> table:-
>>> $mask_query = "SELECT mask_id, mask_name, mask_dynamic FROM masks
>>> where mask_project = $project_id AND mask_parent = $phase_id";
>>> ##next i am storing the return value to a variable (on executing the
>>> script, I donot get any mysql error so i assume the query ran fine:-
>>> $mask_res = mysql_query($mask_query) or die("can't run query
>>> [$mask_query]: ".mysql_error());
>>> ##now i intend to print the field called mask_name on the browser:-
>>> $tc_array = mysql_fetch_array($mask_res, MYSQL_ASSOC);
>>> $tc_name = $tc_array["mask_name"];
>>> print "mask Name:".$tc_array['mask_name'] . " ";
>>> ##However, what is printed is the string mask Name, followed by a
>>> blank. The mask_name field from the db is ##not retrieved. Where am i
>>> going wrong? Appreciate any help!
>> Make sure that error_reporting is set to E_ALL|E_STRICT in your php.ini
>> and display_errors is enabled. Do you get any notices when you run the
>> code? Does the query actually return anything? What does a
>>
>> var_dump($tc_array);
>>
>> show?
>>
>> Micha
>
> thanks a lot for the help. Indeed var_dump($tc_array)
> prints:bool(false). So is it that the mysql query is going wrong?
>

No, it just means the request didn't return any rows.

echo your $mask_query to see if it contains what you think it does.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: newbie help with mysql_fetch_array

am 14.01.2008 20:43:41 von Michael Fesser

..oO(sixstringsin@yahoo.co.in)

>On Jan 14, 11:31 pm, Michael Fesser wrote:
>
>> Make sure that error_reporting is set to E_ALL|E_STRICT in your php.ini
>> and display_errors is enabled. Do you get any notices when you run the
>> code? Does the query actually return anything? What does a
>>
>> var_dump($tc_array);
>>
>> show?
>
>thanks a lot for the help. Indeed var_dump($tc_array)
>prints:bool(false). So is it that the mysql query is going wrong?

The query didn't return anything. You can check with mysql_num_rows() to
see if there's something returned.

It also means that most likely your error_reporting directive is not
configured properly, since you should have received an E_NOTICE error.

Micha

Re: newbie help with mysql_fetch_array

am 14.01.2008 20:52:19 von Courtney

Jerry Stuckle wrote:
> sixstringsin@yahoo.co.in wrote:
>> On Jan 14, 11:31 pm, Michael Fesser wrote:
>>> .oO(sixstring...@yahoo.co.in)
>>>
>>>
>>>
>>>> ##in the mysql query below, i am selecting a few fields from the masks
>>>> table:-
>>>> $mask_query = "SELECT mask_id, mask_name, mask_dynamic FROM masks
>>>> where mask_project = $project_id AND mask_parent = $phase_id";
>>>> ##next i am storing the return value to a variable (on executing the
>>>> script, I donot get any mysql error so i assume the query ran fine:-
>>>> $mask_res = mysql_query($mask_query) or die("can't run query
>>>> [$mask_query]: ".mysql_error());
>>>> ##now i intend to print the field called mask_name on the browser:-
>>>> $tc_array = mysql_fetch_array($mask_res, MYSQL_ASSOC);
>>>> $tc_name = $tc_array["mask_name"];
>>>> print "mask Name:".$tc_array['mask_name'] . " ";
>>>> ##However, what is printed is the string mask Name, followed by a
>>>> blank. The mask_name field from the db is ##not retrieved. Where am i
>>>> going wrong? Appreciate any help!
>>> Make sure that error_reporting is set to E_ALL|E_STRICT in your php.ini
>>> and display_errors is enabled. Do you get any notices when you run the
>>> code? Does the query actually return anything? What does a
>>>
>>> var_dump($tc_array);
>>>
>>> show?
>>>
>>> Micha
>>
>> thanks a lot for the help. Indeed var_dump($tc_array)
>> prints:bool(false). So is it that the mysql query is going wrong?
>>
>
> No, it just means the request didn't return any rows.
>
> echo your $mask_query to see if it contains what you think it does.
>
And then if you have command line access., cut and paste it into a
command line mysql window.

About 85% of my issues show up that way..fix it till it works there,
then edit the source.