Page 1 of 1

PHP Help - Added a default value to blank field

Posted: Wed Jun 30, 2010 3:27 pm
by ChuckAkins
I am working on a site and need to add a value to fields that are blank or null within the database.

E.g. if XXX field is empty add a marketing link as an upgrade package etc.

Here is the code:

Code: Select all

$em_columns = array(
					"logo" =>array("header"=>"Logo", "type"=>"label", "title"=>"Logo"),
					"contact_name" =>array("header"=>"Contact Name", "type"=>"label", "title"=>"Contact Name"),
					"company" =>array("header"=>"Company", "type"=>"label",  "title"=>"Company Name"),
					"city" =>array("header"=>"City", "type"=>"label", "title"=>"City"), 
					"state" =>array("header"=>"State", "type"=>"label", "title"=>"State"),
					"zip" =>array("header"=>"Zip", "type"=>"label", "title"=>"Zip"), 
					"county" =>array("header"=>"County", "type"=>"label", "title"=>"County"),
					"phone" =>array("header"=>"Phone", "type"=>"label", "title"=>"Phone"),
					"website" =>array("header"=>"Website", "type"=>"label", "title"=>"Website"),
					"sic_desc" =>array("header"=>"Company Description", "type"=>"label", "title"=>"Company Description"),
					"about" =>array("header"=>"About", "type"=>"label", "title"=>"About"),
				  );

Thanks in advance for any help!

Re: PHP Help - Added a default value to blank field

Posted: Wed Jun 30, 2010 3:35 pm
by AbraCadaver
You didn't give any explanation for your array, so here is a wild guess:

Code: Select all

foreach($em_columns as $column => $array) {
	// UPDATE table_name SET $column = 'marketing link etc' WHERE $column = '' OR $column IS NULL
}

Re: PHP Help - Added a default value to blank field

Posted: Wed Jun 30, 2010 3:43 pm
by ChuckAkins
Shawn,

Thanks for the reply.

The table displays information from a database in a directory format. This particular array is to display the 'more details' on each company. The goal is to create links to a marketing page for a premium listing. (e.g. having a published logo in your listing cost $$).

I will try your code. I am somewhat of a PHP novice (enough to use it, but not enough to write it). Where do I need to put this? Inside the array?

Thanks very much for your help!

Re: PHP Help - Added a default value to blank field

Posted: Wed Jun 30, 2010 3:46 pm
by AbraCadaver
No, don't use what I gave you. You're talking about displaying a link and not updating the database. You need to show your display code and comment where you want to display a link etc...

Re: PHP Help - Added a default value to blank field

Posted: Wed Jun 30, 2010 3:52 pm
by ChuckAkins
This is part of the datagrid system, so there really is no display portion. If you change that array it updates automatically based on the data from the database. It's not like a typical database page in that you set the parameters then write out HTML display code.

That is where I am stuck.

And have no idea what to do.

Re: PHP Help - Added a default value to blank field

Posted: Wed Jun 30, 2010 4:06 pm
by Jonah Bron
Something like this?

Code: Select all

foreach ($em_columns as $em_key => $em_column) {
    foreach ($em_column as $key => $field) {
        if (empty($field)) { // if field is empty...
            $em_columns[$em_key][$key] = "blah blah"; // put whatever you want into it
        }
    }
}

Re: PHP Help - Added a default value to blank field

Posted: Wed Jun 30, 2010 4:29 pm
by ChuckAkins
Where would I put this in to test it?

Re: PHP Help - Added a default value to blank field

Posted: Thu Jul 01, 2010 8:59 am
by ChuckAkins
Bump for help!

Thanks guys!