Hi peeps

just a quicky.
I have created an array and i want to add to the array inside a while loop is this possible?

$data = array();
while ($var=mysql_fetch_array($var2))
{
if ($var==$match)
{
//this would be where i add to the data array how i dont know yet
}
}

any ideas it would really help

    Yes,
    that is how we do it. At least I do.

    Try this

    <?php
    
    $data = array();
    while ($var=mysql_fetch_array($var2))
    {
        if ($var==$match)
        {
            $data[] = $var; // adds $var as next element in $data 
        }
    }
    
    echo '<pre>';
    print_r( $data ); // have a look at $data array
    
    ?>

      Use [] to add to the end ...

      $data[] = 'blah';

      ... or ...

      array_push($data, 'Blah');

      ... does the same thing.

      P.

        is this possible

        <?php

        $data = array();
        while ($var=mysql_fetch_array($var2))
        {
        if ($var==$match)
        {
        $data[] = $var => $value;
        }
        }

        echo '<pre>';
        print_r( $data ); // have a look at $data array

        ?>

          That does not really make sense, and is probably syntactically incorrect due to the =>.

          If you are trying to retrieve the result set into an array, you should use:

          $data = array();
          while ($row = mysql_fetch_array($var2))
          {
              $data[] = $row;
          }

            this is the script i was trying to write

            $url_extq_data = array();
            	if (isset($_REQUEST)) 
            		{
                	foreach($_REQUEST as $key=>$value)
            			{
            			// only get the data for extra questions
            			$schq = "SELECT * FROM extraq WHERE programid='$programid'";
            			$schr = mysql_query($schq);
            			while($schrow=mysql_fetch_array($schr))
            				{
            				$thisqid = $schrow["id"];
            				$tagit = $schrow["tagit"];
            				if ($thisqid==$key)
            					{
            					$addq3 = "INSERT INTO extraqopt (extraqid, value, subid) VALUES ('$thisqid', '$value', '$subid')";
            					$addr3 = mysql_query($addq3);
            					// add data add to array ready for send
            					$url_extq_data = $tagit => $value;				
            					}
            				}
            			}
            		}
              Write a Reply...