How can i let an array with 5 values....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Apophis
Forum Newbie
Posts: 13
Joined: Fri Jul 28, 2006 7:56 am

How can i let an array with 5 values....

Post by Apophis »

Everah | 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]


How can i let an array with 5 values put de values one by one back in a print function where it will be used for a query and gives me back specific information with this print function. And it muss be done untill all te values of that array are used.

Code: Select all

<?php
include('config.php');

//Thake the id from the url to work with
$Id = (isset($_GET['Id'])) ? intval($_GET['Id']) : 0 ; 
$where = ($Id != 0) ? " WHERE Id=".$Id : " ";

//The function that i want to use for printing the details, and where the values have to go, one by on (6638,6642,6691,7470,7476)
function Print_distinct_mother ($mother){
	  
	  $sql = "SELECT * FROM dog_table WHERE Id = $mother";
	  $sql_result = mysql_query($sql) or die(mysql_error());
	  $sql_row = mysql_fetch_assoc($sql_result);
	
	  $Id = $mother['Id'];
	  $DOB1 = $mother['DOB'];
	  $DOB = date('d M Y', strtotime($DOB1));
	  
	  $Image_folder = "<img src=\"../pictures/andere/new.gif\" width=\"35\" height=\"15\" />";
      $new = $Image_folder;
	  $bewerk_datum = $mother['DOC'];  
	  $aantal_dagen = floor(abs((strtotime($bewerk_datum)-time())/(60*60*24)));  

	  $Image_folder2 = "<img src=\"../pictures/andere/update.gif\" width=\"47\" height=\"10\" />";
      $update = $Image_folder2;
	  $bewerk_datum2 = $mother['DOU'];  
	  $aantal_dagen2 = floor(abs((strtotime($bewerk_datum2)-time())/(60*60*24)));
	  
	  print "<span class=\"style2\">".$mother['Ch']."</span>\n";
	  print "</a>&nbsp";
	  print "<span class=\"style3\">".$mother['DogName']."</span>";
	  print "</a>&nbsp";
	  print "<span class=\"style4\">(".$mother['Color'].")</span>";
	  print "</a>&nbsp";
	  print "<span class=\"style4\">".$DOB."</span>";
	  print "</a>&nbsp;&nbsp;&nbsp&nbsp";
	  if($aantal_dagen <60){echo $new;}  
      //else{echo'';}
      if($aantal_dagen2 <60){echo $update;}  
      //else{echo'';}
	  print "<br><font color='black' size='1' face='Arial'>";
	  print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp[<a href=\"pedigree.php?Id=$Id\">Pedigree]</a>&nbsp;&nbsp;";
	  print "[<a href=\"breeding.php?Id=$Id\">Breeding]</a>&nbsp;&nbsp;";
	  print "[<a href=\"sibling.php?Id=$Id\">Sibling]</a></font>";
	  
}


	//Search the number of the father and the mother 
    $SQL_parents = "SELECT FatherId, MotherId FROM dog_table WHERE Id = '".$Id."'" or die(mysql_error());
	$SQL_parents_Result = mysql_query($SQL_parents);
	
	if ($SQL_parents_Result) { 
   		$parents_row = mysql_fetch_assoc($SQL_parents_Result); 
   		$MotherId = $parents_row['MotherId']; //the number of the mother
   		$FatherId = $parents_row['FatherId']; //the number of the father
} 
		else { 
  			echo $SQL_parents; 
}
    
	
	//Zoek de unieke teven die met de reu hebben gedekt
	//Will give me the following numbers((6638,6642,6691,7470,7476)
	$SQL_distinct_mother = "SELECT DISTINCT MotherId FROM dog_table where FatherId = $FatherId and MotherId != $MotherId and Id != $Id";
	$SQL_distinct_mother_result = mysql_query($SQL_distinct_mother) or die(mysql_error());

	if ($SQL_distinct_mother_result) {   
  			$numRows = mysql_num_rows($SQL_distinct_mother_result);  
  			for ($x=0;$x<$numRows;$x++) {  
      			$row = mysql_fetch_array($SQL_distinct_mother_result);  
      		$mother = $row['MotherId'];
      		//print $mother."<br>"; 
      		print Print_distinct_mother($mother);  
  		}  
	}   
?>

Everah | 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]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Without all the code... what does the array look like? Can you loop it with a for loop or foreach loop?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

$a = array(1,2,3,4,5);
foreach($a as $v) {
    someFunction($v);
}
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Post Reply