Gossamer Forum
Home : Products : DBMan : Customization :

Unneeded fields

Quote Reply
Unneeded fields
I'm still experimenting with my recipe site.
I've managed to build a recipe page from the database. However, I have 13 fields called Ingred(ients)1-13. If I don't need all fields for a specific recipe they still take screen real estate.

Say e.g. that I have a recipe using 5 ingredients. I get:
Ingredient 1
Ingredient 2
Ingredient 3
Ingredient 4
Ingredient 5

<BIG SPACE>

Intructions.

I want the page to discard the fields 6-13 and put Instructions shortly after Ingred 5. (Changing <BIG SPACE> to <SMALL SPACE> )

a/ Is this possible?
b/ Is it possible to format a "memo" field while being displayed, i.e. putting <br> after each ingredient in a large "Ingred"-field?

Cheers,

M.
Quote Reply
Re: Unneeded fields In reply to
Let's say you have a display that looks, in part, something like this:

Code:
print qq|
<table>
<tr><td>$rec{'Ingredient1'}</td></tr>
<tr><td>$rec{'Ingredient2'}</td></tr>
<tr><td>$rec{'Ingredient3'}</td></tr>
<tr><td>$rec{'Ingredient4'}</td></tr>
<tr><td>$rec{'Ingredient5'}</td></tr>
<tr><td>$rec{'Ingredient6'}</td></tr>
</table>
|;

You know that every recipe must have at least one ingredient, so you know that one won't be blank. But the others might.

print qq|
<table>
<tr><td>$rec{'Ingredient1'}</td></tr>|;
if ($rec{'Ingredient2'} {
print qq|
<tr><td>$rec{'Ingredient2'}</td></tr>
|;
}
if ($rec{'Ingredient3'} {
print qq|
<tr><td>$rec{'Ingredient3'}</td></tr>
|;
}
if ($rec{'Ingredient4'} {
print qq|
<tr><td>$rec{'Ingredient4'}</td></tr>
|;
}
if ($rec{'Ingredient5'} {
print qq|
<tr><td>$rec{'Ingredient5'}</td></tr>
|;
}
if ($rec{'Ingredient6'} {
print qq|
<tr><td>$rec{'Ingredient6'}</td></tr>
|;
}
print qq|
</table>
|;[/code]
Code:
$rec{'Ingred'} =~ s/\n/<BR>/g;

Substitue the real field name for Ingred.

This second choice might be better, if you want users to be able to search for recipes by ingredient.


------------------
JPD





Quote Reply
Re: Unneeded fields In reply to
------------------------------------
print qq|
<table>
<tr><td>$rec{'Ingredient1'}</td></tr>|;
if ($rec{'Ingredient2'} {
print qq|
<tr><td>$rec{'Ingredient2'}</td></tr>
|;
-----------------------------------------
That looks fairly straightforward Perl to me.
(Although much may pass as ordinary Perl with my experience - If Ingredient2 is not empty (or exists) then print etc ...)
Can one add whatever Perl in between print qq| and |; ?

Chimbis
Quote Reply
Re: Unneeded fields In reply to
Yep. It's straightforward Perl.

And nope. Smile

You can't put Perl between print qq| and |; You put Perl outside of them. (I think that's what you meant, but I wanted to be sure.)


------------------
JPD





Quote Reply
Re: Unneeded fields In reply to
Your second suggestion did exactly what I wanted it to do.

Thinking about the Perl substitution it means
"substitute all new lines with <br>", right but what is "g"?

Thanks,

C.
Quote Reply
Re: Unneeded fields In reply to
The "g" in the substitution expression means "global." "Do it every time." Otherwise, it will stop after the first one.


------------------
JPD