Jump to content

[SOLVED] functions.. frustrating


spfoonnewb

Recommended Posts

I created a function that does a lot, and I need the value of it to be inserted into a mysql database..

 

If I call the function the normal way..

 

echo function_name();

 

It returns the value that I want.

 

 

It wont let me save that value as a variable such as..

 

$var = function_name();

 

If I put the function in the mysql insert statement the output is blank.

 

VALUE('".function_name()."')

What do I do!?

 

The end result of a function has to run a for each that looks like:

 

foreach ($str as $strval) {
	echo $strval;
}

 

So I cant save the stuff the function does as variable either.

Link to comment
Share on other sites

sorry didn't see your last post...

 

try something like this:

<?php

$variable = myfunction();

for($i=0, $i<=count($variable), $i++){
echo $variable[$i]."<br />";
}

function myfunction(){
foreach ($str as $strval) {
	$something[] = $strval;
}

return $something;
}

?>

 

*untested

Link to comment
Share on other sites

Ok, now that works.. but I need a way to get it to save into the database

 

The following returns the value I need.. but I can't get it in mysql

 

$variable = myfunction();

for ($i=0; $i<=count($variable); $i++) {
echo $variable[$i];
}

 

Heres a non-working way of what I mean..

 

$variable = myfunction();
$test = for ($i=0; $i<=count($variable); $i++) { echo $variable[$i]; }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.