Link to home
Start Free TrialLog in
Avatar of TrinitySJ
TrinitySJ

asked on

need to get the number of rows

i need to get the number of rows

this is what i have so far.. and i get the last one....
more info if needed... please ask me...
echo'<IMG SRC="char_test3.php?tournament='.$tournament.'';
				
	$zips = $z->get_zips_in_range($tzip, $distance, _ZIPS_SORT_BY_DISTANCE_DESC, true); 
	foreach ($zips as $key => $value) {
	$count = count($zips);	
 
		$sqlcc2="SELECT COUNT(wname) FROM wrestler where wzip = '$key'";
		$resultcc2 = mysql_query($sqlcc2) or die(mysql_error()); 
		while($rowcc2 = mysql_fetch_array($resultcc2)){
		
		$count_class = $rowcc2[0];
		}
		echo'&zip'.$key.'='.$count_class.'';
	}
		
		for( $i = 0; $i < $count; $i++)
		{
			
		}
	echo'">';

Open in new window

Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

I assume $count_class should be the var with number of rows ?

try

                $sqlcc2="SELECT COUNT(wname) FROM wrestler where wzip = '$key'";
                $resultcc2 = mysql_query($sqlcc2) or die(mysql_error());
////// here
$test = mysql_num_rows($resultcc2);
//////
                while($rowcc2 = mysql_fetch_array($resultcc2)){
               
                $count_class = $rowcc2[0];
                }

echo"$test";
Avatar of TrinitySJ
TrinitySJ

ASKER

ah.. no that count is working fine.. it is the $count= count($zips)

i need to know the number of returned zips in the for each line...
Try to move it outside the loop

        $count = count($zips);  
        foreach ($zips as $key => $value) {

                $sqlcc2="SELECT COUNT(wname) FROM wrestler where wzip = '$key'";
                $resultcc2 = mysql_query($sqlcc2) or die(mysql_error());
                while($rowcc2 = mysql_fetch_array($resultcc2)){
               
                $count_class = $rowcc2[0];
                }
                echo'&zip'.$key.'='.$count_class.'';
        }
I tried that and i only get one return when i do that..

this is the part of the code that i'm working through that is giving me a hard time
the count that i need to get it the number of zips not the count_class.
I get the count_class fine

it is the number of returned zips that i need in the top of the foreach loop... make sense?

echo'<IMG SRC="char_test3.php?tournament='.$tournament.'';
                        
      $zips = $z->get_zips_in_range($tzip, $distance, _ZIPS_SORT_BY_DISTANCE_DESC, true);
      foreach ($zips as $key => $value) {
      $count = count($zips);      

            $sqlcc2="SELECT COUNT(wname) FROM wrestler where wzip = '$key'";
            $resultcc2 = mysql_query($sqlcc2) or die(mysql_error());
            while($rowcc2 = mysql_fetch_array($resultcc2)){
            
            $count_class = $rowcc2[0];
            }
            
      }
            ///here
            for( $i = 0; $i < $count; $i++)
            {
                  echo'&zip'.$key.'='.$count_class.'';
            }
                                         ///////here

      echo'">';
not sure if this helps
but
after a loop

      foreach ($zips as $key => $value) {
      $count = count($zips);      

            $sqlcc2="SELECT COUNT(wname) FROM wrestler where wzip = '$key'";
            $resultcc2 = mysql_query($sqlcc2) or die(mysql_error());
            while($rowcc2 = mysql_fetch_array($resultcc2)){
           
            $count_class = $rowcc2[0];
            }
           
      }




you have the last key HERE ($key)

            ///here
            for( $i = 0; $i < $count; $i++)
            {
                  echo'&zip'.$key.'='.$count_class.'';
            }
                                         ///////here


maybe you should move the second loop into the end of the first one ?
that did not work..

here is what i'm getting...
i get the count. $count=4

but it is doing the loop 4 times for each that it finds.. and i just need the one per loop..

Pre-Season All-American Slam<br>
<IMG SRC="char_test3.php?tournament=Pre-Season All-American Slam&zip0=15&zip0=38&zip0=44&zip0=82&zip1=15&zip1=38&zip1=44&zip1=82&zip2=15&zip2=38&zip2=44&zip2=82&zip3=15&zip3=38&zip3=44&zip3=82">
echo'<IMG SRC="char_test3.php?tournament='.$tournament.'';
				
	$zips = $z->get_zips_in_range($tzip, $distance, _ZIPS_SORT_BY_DISTANCE_DESC, true); 
	
	$count = count($zips);
	for( $i = 0; $i < $count; $i++)
    {
		foreach ($zips as $key => $value) {
		
			$sqlcc2="SELECT COUNT(wname) FROM wrestler where wzip = '$key'";
			$resultcc2 = mysql_query($sqlcc2) or die(mysql_error()); 
			while($rowcc2 = mysql_fetch_array($resultcc2)){
			
			$count_class = $rowcc2[0];
			}
		
        echo'&zip'.$i.'='.$count_class.'';
        }
	}
	echo'">';

Open in new window

the solution is near

this is the bad result
Pre-Season All-American Slam<br>
<IMG SRC="char_test3.php?tournament=Pre-Season All-American Slam&zip0=15&zip0=38&zip0=44&zip0=82&zip1=15&zip1=38&zip1=44&zip1=82&zip2=15&zip2=38&zip2=44&zip2=82&zip3=15&zip3=38&zip3=44&zip3=82">

what do you expect to have as an good result
Pre-Season All-American Slam<br>
<IMG SRC="char_test3.php?tournament=Pre-Season All-American Slam&zip1=15&zip2=38&zip3=44&zip4=82">
the previous comment is what i would like to have as the good result.. however i cannot get that no matter what i do.
what is the result for (switch in proper place)

                foreach ($zips as $key => $value) {
               
                        $sqlcc2="SELECT COUNT(wname) FROM wrestler where wzip = '$key'";
                        $resultcc2 = mysql_query($sqlcc2) or die(mysql_error());
                        $rowcc2 = mysql_fetch_array($resultcc2);
                        $count_class = $rowcc2[0];
                 }

zip0=15&zip1=15&zip2=15 etc. ?
try this and paste the result
echo'<IMG SRC="char_test3.php?tournament='.$tournament.'';
                                
        $zips = $z->get_zips_in_range($tzip, $distance, _ZIPS_SORT_BY_DISTANCE_DESC, true); 
        
        $count = count($zips);
        for( $i = 0; $i < $count; $i++)
    {
                foreach ($zips as $key => $value) {
                
                        $sqlcc2="SELECT COUNT(wname) FROM wrestler where wzip = '$key' limit $i,1";
                        $resultcc2 = mysql_query($sqlcc2) or die(mysql_error()); 
                        $rowcc2 = mysql_fetch_array($resultcc2);                        
                        $count_class = $rowcc2[0];
                
        echo'&zip'.$i.'='.$count_class.'';
        }
        }
        echo'">';

Open in new window

Pre-Season All-American Slam<br><IMG SRC="char_test3.php?tournament=Pre-Season All-American Slam&zip0=15&zip0=38&zip0=44&zip0=82&zip1=&zip1=&zip1=&zip1=&zip2=&zip2=&zip2=&zip2=&zip3=&zip3=&zip3=&zip3=">

that is the result that i get...
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok i think were getting somewhere...
that is working.. but the zip0 does not work.. i have to have it start at zip1

Pre-Season All-American Slam<br><IMG SRC="char_test3.php?tournament=Pre-Season All-American Slam&zip0=15&zip1=38&zip2=44&zip3=82">

is the return that i get from the code now..

this is great...
i fixed it.. changed

$i = 0
to
$i = 1
right, index from 1
the issue was that there was two loops, simply unnecessary...
//===========
$i = 0;
can be
$i = 1;
//================
either will work
i have another question about this.. can you help me...
make another question and post a link to it here