View Full Version : if fields are blank
ziggy1621
04-26-2007, 04:36 PM
i'm trying to get the script below to not display the field if the value is blank (i.e. if there is not an entry in the database, don't show the title)
Thanks in advanced... I'm stumped...
function create_table_from_database($fields,$values=''){
$table = "<table>";
foreach($fields as $field){
if(!strstr($field,'id')){
$table .= "<tr><td valign='top'><strong>".ucwords(str_replace("_"," ",$field))."</strong></td><td>";
if(strstr($field,"comments") || strstr($field,"description")){
$table .= "<textarea name='".$field."' cols='35' rows='5'>";
if($values != ''){
$table .= $values[$field][0];
}
$table .= "</textarea>";
}elseif(strstr($field,"select")){
global $$field;
$table .= '<select name="'.$field.'">';
$selects = $$field;
foreach($selects as $key => $value){
if($values != '' && $values[$field][0] == $key){
$selected = ' selected ';
}else{
$selected = '';
}
$table .= '<option value="'.$key.'"'.$selected.'>'.$value.'</option>';
}
$table .= '</select>';
}else{
$table .= '<input type="text" name="'.$field.'" size="30"';
if($values != ''){
$table .= ' value="'.$values[$field][0].'"';
}
$table .= ' />';
}
$table .= "</td></tr>";
}
}
$table .= "</table>";
return $table;
}
iLLin
04-26-2007, 04:44 PM
Use can use empty(), or check if it == "" or use strlen()...
ziggy1621
04-26-2007, 04:56 PM
Use can use empty(), or check if it == "" or use strlen()...
thanks, but where would I put it. Sorry to be asking for it done, but I'm so swamped today.
thanks
this may help as well... this is where it is pulling from
<? case "edit":
$query = "SELECT * FROM ".$table." WHERE ".$tableKey." = '".$_GET['id']."'";
$database->query($query,'edit');
//print_r($database->edit);
$fields = $database->list_fields($table,$values = $database->edit);
?>
<h2>Edit <?= $pageTitles;?></h2>
<form id="form1" name="form1" method="post" action="?action=update">
<div id="tableForm">
<?= create_table_from_database($fields,$database->edit);?>
<input type="submit" name="Submit" value="Submit" />
<input name="id" type="hidden" id="id" value="<?= $database->edit[$tableKey][0];?>" />
</div>
</form>
iLLin
04-26-2007, 05:01 PM
thanks, but where would I put it. Sorry to be asking for it done, but I'm so swamped today.
thanks
LOL, your so swamped... If you want to have someone else do you work then maybe you should post in the "Paid work offers and requests" Forum.
Fumigator
04-26-2007, 05:35 PM
iLLin don't argue with the guy, just get it DONE! He's got a deadline to make.
:p
ziggy1621
04-26-2007, 07:10 PM
iLLin don't argue with the guy, just get it DONE! He's got a deadline to make.
:p
If you wanted to be funny you are in the wrong forum. I wasn't trying to be a jerk. I've given work away without pay in here... Guess you gotta not be shallow.. Thanks for the tip... I'll go spend an hour reading up on what you could have posted in 1 minute.. Genious:thumbsup:
iLLin
04-26-2007, 08:11 PM
Yea you and your 16 posts have given away so much free code... Man... WHERE WAS I?
Fumigator
04-26-2007, 08:16 PM
Why can't I be funny? I'm not saying I was... I probably wasn't, in fact... but I reserve the right to be a comedian in this forum.
Nightfire
04-26-2007, 08:25 PM
If you wanted to be funny you are in the wrong forum. I wasn't trying to be a jerk. I've given work away without pay in here... Guess you gotta not be shallow.. Thanks for the tip... I'll go spend an hour reading up on what you could have posted in 1 minute.. Genious:thumbsup:
The answer has been given to you. If you're unsure how to use the functions shown by iLLin, then search for them on php.net. Stop being lazy, we're here to help, not do your work for you, as we're too swamped
ziggy1621
04-26-2007, 09:22 PM
The answer has been given to you. If you're unsure how to use the functions shown by iLLin, then search for them on php.net. Stop being lazy, we're here to help, not do your work for you, as we're too swamped
You don't get it. I never ask for freebies and don't like to, but when I'm as swamped as I am now.. and thats not deadlines, just too many different things going on (I own a small I.T. business)... I look to a forum for a little friendly help (since i'm asking for one line of code... not a project).... If I had the time to investigate, I wouldn't have even come here... I would have gone directly to google.
Sometimes you don't have to be a tightwad...
thanks anyway
Nightfire
04-26-2007, 09:29 PM
Yet you've had time to reply how many times here? For the time you've wasted replying, you could've typed the functions given to you in php.net. Here, I'll even type the url's for you so you can just click.
http://php.net/empty
http://php.net/strlen
I'm also guessing that you didn't create the code you've posted, as well, you are checking if things are empty in there already.
rafiki
04-26-2007, 09:31 PM
if (!isset($_POST['email'])){
echo 'you missed out your email';
}else{
echo 'yay you entered your email';
}
is how to use isset
if (empty($_POST['email'])){
echo 'you missed out your email';
}else{
echo 'yay you entered your email';
}
is empty()
if ($_POST['email'] == ''){
echo 'you missed out your email';
}else{
echo 'yay you entered your email';
}
is how to check if its empty
if (strlen($_POST['email']) < 1 ){
echo 'you missed out your email';
}else{
echo 'yay you entered your email';
}
if (count($_POST['email']) < 1){
echo 'you missed out your email';
}else{
echo 'yay you entered your email';
}
any more i can help ypu with?
ziggy1621
04-26-2007, 09:40 PM
thanks rafiki.. that does help a bit...
Nightfire: I've been working on other projects while waiting.. thanks
CFMaBiSmAd
04-26-2007, 09:52 PM
Since we don't know which portion of the output you want and don't want (you already have a foreach(...) loop that only outputs things if they exist) no one here would have a clue as to the intent of what you want or where in the code to do this, so if you don't know but where would I put it, what makes you think anyone in a forum would know either.
If you provide specific details about what fields you want tested and what output you specifically want and what you are getting now and under what conditions it occurs and what you want this to be under those conditions, you might get someone to give you some direction on how to change it.
I am constantly amazed that people post questions like this and then wait around hours and days in a forum, when they could do the research and programming themselves in a few 10's of minutes. If you would say that it would take you the hours and days to do this yourself, you would need to ask yourself if you are attempting to do something that is beyond your ability, in which case you should be posting this in the paid work offer section.
ziggy1621
04-26-2007, 09:53 PM
I'm walking into a pre-existing script that it over my head in some aspects. I'm just trying to accomplish one simple thing and thought someone may know.
and I'm doing the research CFM...
I just can't get it. I can't believe you guys can be such duds. I'm not asking for a project, nor a stupid remark... If you can't do it, just say it
I like learning and want to learn more, but pointing me to a function doesn't teach me anything. It only shows the function. I could use !=='', but the problem is the way this script is split up in grabbing fields and values in two different spots.
I want to learn, I don't want to pay.
See.. its got this section pulling the field name:
if(!strstr($field,'id')){
$table .= "<tr><td valign='top'><strong>".ucwords(str_replace("_"," ",$field))."</strong></td><td>";
and this section pulling the values
$table .= '<input type="text" name="'.$field.'" size="30"';
if($values !== ''){
$table .= ' value="'.$values[$field][0].'"';
}
$table .= ' />';
I can set the values to if values !=='' or as you guys showed if !empty, but that does nothing for not showing that <tr> line in the form if values are empty....
just forget it.. you guys are frustrating me more than helping
Fumigator
04-26-2007, 10:20 PM
I'll change your script for $50. PM me if interested.
Len Whistler
04-26-2007, 11:26 PM
thanks, but where would I put it.
Ziggy1621 below is the code I use and it's put where you want it echoed. In this example if row 7 in my database is empty the echo statement will not be executed and PHP goes to the next line. If it has value the echo statement is executed and then to the next line of code.
if (strlen($row[7]) > 0) {
echo "blah";
}
Spookster
04-27-2007, 01:39 AM
Several of you in this thread have been given infractions for your behavior. I would suggest refraining from such behavior in the future as you are about one infraction away from becoming banned.
This thread is now closed.
ziggy1621
05-01-2007, 03:50 AM
Ziggy1621 below is the code I use and it's put where you want it echoed. In this example if row 7 in my database is empty the echo statement will not be executed and PHP goes to the next line. If it has value the echo statement is executed and then to the next line of code.
if (strlen($row[7]) > 0) {
echo "blah";
}
thanks a ton.. I'll check into that in the a.m. I really appreciate your time.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.