How do i display array in table in string ?

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 557 Views - Last Post: 19 March 2019 - 10:30 AM Rate Topic: -----

#1 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

How do i display array in table in string ?

Posted 16 March 2019 - 11:23 PM

Hello good day i'm having problems on how to display array shows error array to string conversion which i don't know how to figure out i'm still learning

here are my function code: problems is how to convert array into string which is my problem i don't know how problems is i don't know where to put function implode() do i need to write a new function call function table_header or labelheader_cell where do i put the code how do i write the code for implode i'm still new. This two array one should show link and other one is edit link but i don't know how. It would be a great help thank you.

function table_section_title1($msg, $colspan=2)
{
	echo "<tr><td colspan=$colspan class='tableheader'>$msg</td></tr>\n";
}

function table_header($labels, $params='')
{
	start_row();
	foreach ($labels as $label)
		labelheader_cell1($label, $params);
	end_row();
}


function labelheader_cell($label, $params="")
{
	echo "<td class='tableheader' $params>$label</td>\n";
}

function view($trans)
{
	return get_trans_view_str( $trans["order_no"]);
}



this my code display table array where do i need to put implode function? or how do i write it ? i'm still new in of need guidance
$show = (($dim == 1 && $_POST['dim1'] == 0) ||
		($dim == 2 && $_POST['dim1'] == 0 && $_POST['dim2'] == 0));
	if ($show)
		$th = array(_("Period"), _("Amount"), _("Dim. incl."), _("Last Year"));
	else
		$th = array(_("Period"), _("Amount") => array('fun'=>'trans_view', 'ord'=>'', 'align'=>'right'), _("Last Year"), array('insert'=>true, 'fun'=>'edit_link'),  array('insert'=>true, 'fun'=>'edit_link'));
	table_header1($th);

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: How do i display array in table in string ?

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: How do i display array in table in string ?

Posted 17 March 2019 - 04:55 AM

Which is line 72?
Was This Post Helpful? 0
  • +
  • -

#3 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

Re: How do i display array in table in string ?

Posted 17 March 2019 - 04:51 PM

function labelheader_cell which is line 72 and which is calling table_header on im trying to implode but don't know to do it
Was This Post Helpful? 0
  • +
  • -

#4 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

Re: How do i display array in table in string ?

Posted 17 March 2019 - 07:12 PM

im trying to figure out how to do function argument is a scalar and then it goes into an array and if an array it is passed on as is. How do i make sure array pass?
Was This Post Helpful? 0
  • +
  • -

#5 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

Re: How do i display array in table in string ?

Posted 17 March 2019 - 07:25 PM

all i'm trying to do is put a href link to my array for me to update or delete how do i put update link inside an array ? that would make all affected rows inside that array to have a href ?
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: How do i display array in table in string ?

Posted 18 March 2019 - 01:41 AM

Renaming some functions with a 1 at the end is causing a little confusion, but it looks like you are passing an array containing other arrays to function table_header. This then iterates this array calling function labelheader_cell with each array-element. This other function then attempts to echo these elements. However, because at least one of these elements is also an array it causes the error "array to string conversion".
Was This Post Helpful? 0
  • +
  • -

#7 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

Re: How do i display array in table in string ?

Posted 18 March 2019 - 04:45 AM

How should i fix this problem i having struggle to figure on how to fix array to string conversion.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: How do i display array in table in string ?

Posted 18 March 2019 - 04:52 AM

It looks like you want to pass to your table_header function an array of values which may either just contain a single value for a heading, or an array of values to include the header and other settings. Your function, while iterating the received array, has to first determine whether the value it is currently looking at is a single string value, or an array. Investigate how to distinguish between a string and an array, I am sure there are functions available to assist with this. Perhaps searching "php distinguish type" or similar will help.

Alternatively, you could always pass an array of arrays, with some of the arrays only containing a single (label) element.

Either way would work.
Was This Post Helpful? 0
  • +
  • -

#9 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

Re: How do i display array in table in string ?

Posted 18 March 2019 - 05:07 AM

is possible to add href in array i only want it to pass edit.php link so i could update amount if only do insert
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: How do i display array in table in string ?

Posted 18 March 2019 - 05:40 AM

Do you mean edit_link.php? Yes, it is possible, as I have described. Give it a go.
Was This Post Helpful? 0
  • +
  • -

#11 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

Re: How do i display array in table in string ?

Posted 18 March 2019 - 06:17 AM

would you give advice on how to add edit.php link in my array i can't really figure out how to do it. Thank you still new to programming.
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: How do i display array in table in string ?

Posted 18 March 2019 - 06:29 AM

I have already given advice (which you have failed to acknowledge). If you give it some attempt and provide your code you will doubtless receive some assistance. If you aren't going to attempt, or ask a specific question, then this topic is going nowhere.

I'll give one more piece of advice. I searched "php check if variable is string or array" and discovered that there is a function called is_array.
Was This Post Helpful? 0
  • +
  • -

#13 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

Re: How do i display array in table in string ?

Posted 18 March 2019 - 06:35 AM

i'm doing this correctly ? this is_array ?

function output_hidden()
{
	global $hidden_fields;

	if (is_array($hidden_fields))
		echo implode('', $hidden_fields);
	$hidden_fields = array();
}

$hidden_fields = array();

function hidden($name, $value=null, $echo=true)
{
  	global $Ajax, $hidden_fields;
	
	if ($value === null) 
		$value = get_post($name);
	
  	$ret = "<input type=\"hidden\" name=\"$name\" value=\"$value\">";
	$Ajax->addUpdate($name, $name, $value);
	if ($echo)
			$hidden_fields[] = $ret;
	else
		return $ret;
}

Was This Post Helpful? 0
  • +
  • -

#14 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: How do i display array in table in string ?

Posted 18 March 2019 - 07:25 AM

What happens when you run it.
Was This Post Helpful? 0
  • +
  • -

#15 Ryanayao   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-March 19

Re: How do i display array in table in string ?

Posted 18 March 2019 - 04:42 PM

still the same give me Array to string conversion i'm already at a lost on how to fix the problem
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2