[SOLVED] getting the value from a db field array

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
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

[SOLVED] getting the value from a db field array

Post by glennn3 »

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


need to collect the value from a particular field in a db as records are added, to be supplied in $NAME AND $NUMBER for the paypal link, like so (if anyone could help i'd be most appreciateive):

Code: Select all

$results_table .= "<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" border="0" name="submit" width="87" height="23">
			<input type="hidden" name="add" value="1">
			<input type="hidden" name="cmd" value="_cart">
			<input type="hidden" name="business" value="email@address.com">
			<input type="hidden" name="item_name" value=".$NAME.">
			<input type="hidden" name="item_number" value=".$NUMBER.">
			<input type="hidden" name="amount" value="20.00">
			<input type="hidden" name="no_note" value="1">
			<input type="hidden" name="currency_code" value="USD">
			<input type="hidden" name="lc" value="US">
		";
		} // end if
		$results_table .= "</td>";
		for ($i=0; $i<$count_temp; $i++){
			if ($fields_labels_ar[$i]["present_results_search_field"] == "1"){ // the user want to display the field in the search results page
				$results_table .= "<td class="".$td_results_class."">"; // start the cell
				
				$field_name_temp = $fields_labels_ar[$i]["name_field"];
				$field_value = $records_row[$field_name_temp];
				$field_type = $fields_labels_ar[$i]["type_field"];
				$field_content = $fields_labels_ar[$i]["content_field"];
				$field_separator = $fields_labels_ar[$i]["separator_field"];

				//$foreign_key_temp = $fields_labels_ar[$i]["foreign_key_field"];
	
				$field_values_ar = array(); // reset the array containing values to display, otherwise for each loop I have the previous values

				$primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
				if ($primary_key_field_field != ""){
					
					$primary_key_field_field = $fields_labels_ar[$i]["primary_key_field_field"];
					$primary_key_table_field = $fields_labels_ar[$i]["primary_key_table_field"];
					$primary_key_db_field = $fields_labels_ar[$i]["primary_key_db_field"];
					$linked_fields_field = $fields_labels_ar[$i]["linked_fields_field"];
					$alias_suffix_field = $fields_labels_ar[$i]["alias_suffix_field"];
					$linked_fields_ar = explode($fields_labels_ar[$i]["separator_field"], $linked_fields_field);

					for ($j=0;$j<count($linked_fields_ar);$j++) {
						$field_values_ar[$j] .= $records_row[$linked_fields_ar[$j].$alias_prefix.$alias_suffix_field];
					} // end for
				}
				else{
					$field_values_ar[0] = $field_value;
				}

				$count_temp_2 = count($field_values_ar);
				for ($j=0; $j<$count_temp_2; $j++) {
					$field_to_display = get_field_correct_displaying($field_values_ar[$j], $field_type, $field_content, $field_separator, "results_table"); // get the correct display mode for the field

					if ( $field_to_display == "") {
						$field_to_display .= "&nbsp;";
					}

					$results_table .= $field_to_display."&nbsp;"; // at the field value to the table
				}
				$results_table = substr($results_table, 0, -6); // delete the last &nbsp;
				$results_table .= "</td>"; // end the cell

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

could you explain where $NAME and $NUMBER come from? I mean, where are they set? They don't just magically appear..
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

sorry - i hit the "Code" button...

Post by glennn3 »

the $name and $number came from here >>

and the $results_table returns the title that i want - but it's only passing the first word of the contents of the particular field to Paypal; if $records_row[2]; is "Love Me Do", the value passed to paypal is "Love" ...

any idea why?

Code: Select all

while($records_row = fetch_row_db($res_records)) 
	{
	

//////////////////////
		
            $title = $records_row[2];
            $number = $records_row[1];
			
           $results_table .= "<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" border="0" name="submit" width="87" height="23">
			<input type="hidden" name="add" value="1">
			<input type="hidden" name="cmd" value="_cart">
			<input type="hidden" name="business" value="business@business.com">
			<input type="hidden" name="item_name" value=".$title.">
			<input type="hidden" name="item_number" value=".$number.">
			<input type="hidden" name="amount" value="20.00">
			<input type="hidden" name="no_note" value="1">
			<input type="hidden" name="currency_code" value="USD">
			<input type="hidden" name="lc" value="US">";
		} // end if
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you need to add quotes around the 2 values, like you have around each input's name attribute.
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

Post by glennn3 »

i'm sorry i don't understand (i'm learning this stuff as i go) - various quotes i've tried around the values have either not changed anything or returned "$records_row[2]" ...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$results_table .= "<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" border="0" name="submit" width="87" height="23">
            <input type="hidden" name="add" value="1">
            <input type="hidden" name="cmd" value="_cart">
            <input type="hidden" name="business" value="business@business.com">
            <input type="hidden" name="item_name" value="".$title."">
            <input type="hidden" name="item_number" value="".$number."">
            <input type="hidden" name="amount" value="20.00">
            <input type="hidden" name="no_note" value="1">
            <input type="hidden" name="currency_code" value="USD">
            <input type="hidden" name="lc" value="US">";
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

Post by glennn3 »

boom - thanks, you're a millionaire...
Post Reply