Page 1 of 1

mysql_fetch_array - supplied argument error

Posted: Tue Jul 25, 2006 11:29 am
by kbrown3074
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Im getting an error on a select statement.  I am not sure why this is happening.  I have the vars different so they cant be referencing one another.  The error occurs on    while ($myrow = mysql_fetch_array($result))

Code: Select all

$dbcon = mysql_connect("localhost", "test", "test");

        mysql_select_db($dbase,$dbcon);
        $export = "select distinct agentno,pa_cq,last,first from $edttable order by last,first";

        $expresult = mysql_query($export,$dbcon) or die (mysql_error());
        $num_fields = mysql_num_fields($expresult);

        print("<table border='1'>\n");
        print("<tr><td bgcolor=\"#FFFFCC\">License #</td><td bgcolor=\"#FFFFCC\">Last Name</td><td bgcolor=\"#FFFFCC\">First Name</td>\n");

        $query1="select * from util.states";
        $result1=mysql_query($query1,$dbcon) or die (mysql_error());
        while ($myrow1 = mysql_fetch_assoc($result1))
        {
           $starray[]=$myrow1['STATE'];
           $tstate=$myrow1['STATE']; if($myrow1['STATE'] != '') { $tstate = $myrow1['STATE']; }
           print("<td bgcolor=\"#FFFFCC\">$tstate</td>");
        }
        print("</tr></table>\n");

        while($dbrow = mysql_fetch_array($expresult))
        {
           $pacq = ''; if($dbrow['pa_cq'] != '') { $pacq = $dbrow['pa_cq']; }
           $tempag = ''; if($dbrow['agentno'] != '') { $tempag = $dbrow['agentno']; }
           $first = ''; if($dbrow['first'] != '') { $first = $dbrow['first']; }
           $last = ''; if($dbrow['last'] != '') { $last = $dbrow['last']; }

           $query2 = "insert into combtmp (pa_cq,agentno,first,last) values ('$pacq','$tempag','$first','$last')";
           $result2=mysql_query($query2,$dbcon) or die (mysql_error());

           $query = "select agentno,state,lic,peoples,fraz_vet,fraz_ppl,stonebrdg,aflac,mutual,monumental,genworth,gwl,gwm from agstate where agentno='$tempag'";
            print("QUERY RESULT-$query\n");
           $result=mysql_query($query,$dbcon) or die (mysql_error());
           $recs = mysql_num_rows($result);

           while ($myrow = mysql_fetch_array($result))
           {
                $state = ''; if($myrow['state'] != '') { $state = $myrow['state']; }
                $lic = ''; if($myrow['lic'] != '') { $lic = $myrow['lic']; }
                if($lic == 'Y') { $lic = 'X'; }

                //$peoples = ''; if($myrow['peoples'] != '') { $peoples = $myrow['peoples']; }
                $fraz_vet = ''; if($myrow['fraz_vet'] != '') { $fraz_vet = $myrow['fraz_vet']; }
                if($fraz_vet == 'Y') { $fraz_vet = 'V'; }

                $fraz_ppl = ''; if($myrow['fraz_ppl'] != '') { $fraz_ppl = $myrow['fraz_ppl']; }
                if($fraz_ppl == 'Y') { $fraz_ppl = 'F'; }

                $stonebrdg = ''; if($myrow['stonebrdg'] != '') { $stonebrdg = $myrow['stonebrdg']; }
                if($stonebrdg == 'Y') { $stonebrdg = 'S'; }

                $aflac = ''; if($myrow['aflac'] != '') { $aflac = $myrow['aflac']; }
                if($aflac == 'Y') { $aflac = 'A'; }

                $mutual = ''; if($myrow['mutual'] != '') { $mutual = $myrow['mutual']; }
                if($mutual == 'Y') { $mutual = 'm'; }
   }
}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Jul 25, 2006 11:34 am
by jamiel
Your query is most likely returning an empty result set.

Posted: Tue Jul 25, 2006 11:42 am
by kbrown3074
there is a result set from query..there are 3-10 records for each one..the $tempag var is filled in at that point

Posted: Tue Jul 25, 2006 11:45 am
by jamiel
var_dump($recs); just before the loop. Lets see the output.

Posted: Tue Jul 25, 2006 11:59 am
by kbrown3074
var dump of $recs

int(4) int(7) int(1) int(2) int(37) int(2) int (1) int(9) int(1) int(1) int(1)

Posted: Tue Jul 25, 2006 4:31 pm
by jamiel
Whats the error?

Posted: Tue Jul 25, 2006 6:04 pm
by RobertGonzalez
kbrown3074, you realize you have almost no error checking going on within your script? Try putting some calls to die in there where potential errors could be to see what is actually coming out of your DB interaction.

Usually the 'supplied argument' error message in thrown when you try to run a mysql_fetch_array (or other fetch call) on a result set that was not set because of a query error.

Posted: Tue Jul 25, 2006 7:39 pm
by kbrown3074
Everah..yea I know about the error checking. I usually just check out the apache error log to find out when I mess up..that usually suffices...except in this case. The problem was actually down further in the code that I didnt post. I had an update line that used the same darn $result and it should have been $result3.

Posted: Tue Jul 25, 2006 11:15 pm
by RobertGonzalez
So you're all fixed then?

Posted: Wed Jul 26, 2006 6:53 am
by kbrown3074
Yup..that thing finally works. I have another stupid question..but I can make a new thread in that one.