Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57

    Unanswered: Discard undefined values...

    Hi there!

    Here is a function which returns to Flash a string mentioning all the students having a matricule containing the one we are looking for (variable $num).
    The string represents a list having numerous lines (see the <br /> tag).

    How can I discard in each line the undefined values encountered during the search so I avoid lines beginning with a space and/or values separated by an annoying double space?

    Many thanks for your help!

    Regards,

    Gerry


    Code:
    function matricule($num)
    {
    	GLOBAL $db,$table;
    	$query =mysql_query ("SELECT * FROM $table WHERE number LIKE '%$num%' OR numberTwo LIKE '%$num%' OR numberThree LIKE '%$num%' ORDER BY lastName, firstName" ) or die("&erreur=Connection impossible"); 
    	if ( mysql_num_rows( $query ) > 0) {
    		while ($row =mysql_fetch_array ($query ) ) {
    			$flashstr .= $row ["lastName" ]." ".$row ["firstName" ]." ".$row ["number" ]." ".$row ["numberTwo" ]." ".$row ["numberThree" ]."<br />";
    		}
    		print ("&message=Other search possible."."&my_list=".urlencode($flashstr)) ;
    	}
    	else {
    		print ("&message=No student has such a matricule."."&my_list=");
    	}
    }

  2. #2
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    57
    I found this solution which works fine:


    Code:
    function matricule($num)
    {
    	GLOBAL $db,$table;
    	$query =mysql_query ("SELECT * FROM $table WHERE number LIKE '%$num%' OR numberTwo LIKE '%$num%' OR numberThree LIKE '%$num%' ORDER BY lastName, firstName" ) or die("&erreur=Connection impossible"); 
    	if ( mysql_num_rows( $query ) > 0) {
    		while ($row =mysql_fetch_array ($query ) ) {
    			$number = $row ["number" ];
    			if ($number != "") {
    				$number = $number." ";
    			}
    			$numberTwo = $row ["numberTwo" ];
    			if ($numberTwo != "") {
    				$numberTwo = $numberTwo." ";
    			}
    			$numberThree = $row ["numberThree" ];
    			if ($numberThree != "") {
    				$numberThree = $numberThree." ";
    			}
    			$flashstr .= $row ["lastName" ]." ".$row ["firstName" ]." ".$number.$numberTwo.$numberThree."<br />";
    		}
    		print ("&message=Other search possible."."&my_list=".urlencode($flashstr)) ;
    	}
    	else {
    		print ("&message=No student has such a matricule."."&my_list=");
    	}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •