On Thu, 12 Aug 2004 09:20:44 -0400, Deepak Dhake
<[EMAIL PROTECTED]> wrote:
> $query4 = mysql_query("SELECT result FROM TBL_result WHERE survey_no=2";
> while($row2 = mysql_fetch_array($query4)) {
>   //print array
> }
> 
> this will print whole array. i just want to print a row at a time and it should be 
> in the loop because i am printing other things as well. can you tell me how to print 
> a row at a time. actually as i explained earlier, i am able to print a row at a time 
> but when it becomes i=1 and starts outer loop for the second time it just printing 
> the same values. any suggestion?
> 

I think you're getting your terminology mixed up. $row2 is an array
which corresponds to a row in the database. Yes, this will print all
of the returned records, but I can think off very fe wtimes where you
don't want to do that.

This loop *is* what you want. Tell us what you're trying to do and
we'll try to help.

> thanks,
> deepak
> 
> 
> 
> 
> Justin Patrin wrote:
> 
> >On Wed, 11 Aug 2004 17:13:49 -0400, Deepak Dhake
> ><[EMAIL PROTECTED]> wrote:
> >
> >
> >>i am trying to print some values from a table with using
> >>mysql_fetch_array in a loop but not able to get correct values.
> >>it works fine for the loop i=0, prints all desired values but when it
> >>bocomes i=1 and starts the loop again the result values gets reset and
> >>prints the same old values.
> >>
> >>for example:
> >>outout of the query is
> >>result 1
> >>result 2
> >>result 3
> >>result 4
> >>result 5
> >>result 6
> >>result 7
> >>result 8
> >>result 9
> >>result 10
> >>result 11
> >>result 12
> >>
> >>:when i=0, it runs through the loop and prints
> >>result 1
> >>result 2
> >>result 3
> >>result 4
> >>result 5
> >>result 6
> >>:which is perfect.
> >>:but when i=1, it prints the same values,
> >>result 1
> >>result 2
> >>result 3
> >>result 4
> >>result 5
> >>result 6
> >>
> >>why is that so? can anyone help me? thanks in advance.
> >>
> >>$query4 = mysql_query("SELECT result FROM TBL_result WHERE survey_no=2";
> >>
> >>for($i=0; $i < 2; ++$i)        //surveys
> >>{
> >>    for($j=0; $j < 2; ++$j)        //questions
> >>    {
> >>        for ($k=0; $k < 3; ++$k)    //sub-quesions
> >>        {
> >>            $row2 = mysql_fetch_array($query4);
> >>            //Printing all result values one by one
> >>        }
> >>    }
> >>}
> >>
> >>
> >>
> >
> >I'm not sure what you think this should do, but you're assuming that 2
> >* 2 * 3 (12) records will be returned, no more, no less. I doubt this
> >is the case. Normally, such things are done like this:
> >$query4 = mysql_query("SELECT result FROM TBL_result WHERE survey_no=2";
> >while($row2 = mysql_fetch_array($query4)) {
> >  //print array
> >}
> >
> >If this isn't what you want, perhaps you should be doing 3 seperate
> >queries in there? Please explain why you have 3 for loops around your
> >fetch;
> >
> >
> >
> 
> 

-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

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

Reply via email to