Jump to content

return and fetch array from object


Miko

Recommended Posts

Hello,

 

I'm kinda new in oop php so my following question could be very easy for you experts  :P

 

I have here my code:

 

<?php

							$contact = new Contact();
							$get_contact = $contact->get_Contact($cl_number,$contact_id);

							if($get_contact == true){

								echo "<select name=\"get_contact\" onChange=\"ContactDetails(this.value)\">";
								echo "<option selected> </option>";

								foreach($get_contact as $Contact){

									$fname = $Contact['FIRST_NAME'];
									$lname = $Contact['LAST_NAME'];
									$email = $Contact['EMAIL'];
									$tel = $Contact['TEL'];
									$clnumber = $Contact['CUST_ID'];
									$c_id = $Contact['ID'];

									echo "<option value=\"$c_id\">".$fname."</option>";

								}

								echo "</select>";

								$array = array($get_contact);

									if($contact_id == $c_id){

									//if(in_array($contact_id,$array)){


									?>

										<tr>
											<td>Contact First Name:</td>
											<td><input type="text" name="consignee_fname" value="<?php if($fname == ""){echo "No contact details found.";}else {echo $fname;} ?>" size="39" /></td>
										</tr>
										<tr>
											<td>Contact Last Name:</td>
											<td><input type="text" name="consignee_lname" value="<?php if($lname == ""){echo "No contact details found.";}else {echo $lname;} ?>" size="39"/></td>
										</tr>
										<tr>
											<td>Contact Email Address:</td>
											<td><input type="text" name="consign_email" value="<?php if($email == ""){echo "No contact details found.";}else {echo $email;} ?>" size="39" /</td>
										</tr>
										<tr>
											<td>Customer Number:</td>
											<td><input type="text" name="ct_cust_number" value="<?php if($custid == ""){echo "No contact details found.";}else {echo $custid;} ?>" size="39" /><td>
										</tr>
										<tr>
											<td>Contact Telephone:</td>
											<td><input type="text" name="ct_cust_tel" value="<?php if($tel == ""){echo "No contact details found.";}else {echo $tel;} ?>" size="39" /></td>
										</tr>
										<tr>
											<td> </td>
											<td><input type="submit" name="consignee_submit" value="Submit" /></td>
										</tr>

									<?php

									}

						?>

and my object:

 

<?php	class Contact
{

	public function get_Contact($cl_number,$contact_id){

		if(isset($cl_number)){

			$sql = "SELECT * FROM tbl_client_contacts WHERE CUST_ID = '$cl_number' ";
			echo $sql;
			$query = mysql_query($sql);

			while($row = mysql_fetch_array($query)){

				$contact[] = $row;

			}

			return $contact;

		}elseif(isset($contact_id)){

			$sql = "SELECT * FROM tbl_client_contacts WHERE CUST_ID = (SELECT CUST_ID FROM tbl_client_contacts WHERE ID = '$contact_id' ) ";
			echo $sql;
			$query = mysql_query($sql);

			while($row = mysql_fetch_array($query)){

				$contact[] = $row;

			}

			return $contact;

		}

	}

}?>

 

As you can see there is one line "if(in_array)" where I would like to "compare" 2 values, when the 2 values are the same some input fields are shown.

How can I do that with a bit the same code?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/177521-return-and-fetch-array-from-object/
Share on other sites

your right, my explaination was not correct.

 

I would like to do the following (tell me if it is hard to understand, my english is not so good):

 

  • There a select menu with some contact persons inside.
  • User selects one of the contact persons and should get the details of that person in the input fields below

 

I'm trying to use the if in_array because I want to maintain the list of contact persons in the select menu.

 

I hope that I was clear enough here?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.