我有这本联系方式,我正在做。我已将每个联系信息保存在mysql数据库中:
CREATE TABLE IF NOT EXISTS `contacts` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`surname` varchar(255) NOT NULL,
`officemail` varchar(255) NOT NULL,
`homemail` varchar(255) NOT NULL,
`officestreet` varchar(255) NOT NULL,
`homestreet` varchar(255) NOT NULL,
`category` varchar(255) NOT NULL,
`picture` longblob NOT NULL,
`img` varchar(17) NOT NULL,
`homephone` varchar(255) NOT NULL,
`officephone` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;
现在我的问题是:让我们说这些列中的很多都是空的(见下图)only two columns are filled
如何根据填充的列数更改 红色标记 位置?这甚至可能吗?
编辑
这是我的显示代码
while($contactRow = $contact->fetch_assoc()){
$random = rand(0,1000006050);
$emptyImage = (empty($contactRow['picture'])) ? '<div class="emptyProfile" style="cursor: pointer;width: 95px"><label for="file-input'.$contactRow['id'].'" style="z-index:2;zoom: 1;display: inline-block;vertical-align: top;"><img src="images/person.jpg" style="width: 95px;cursor: pointer;z-index:2;zoom: 1"><div style="position: absolute;margin-top:-25px;font-size: 8pt;font-family:Verdana, Arial, Helvetica, sans-serif;zoom:0;opacity: 0;text-align: center;width:95px;background: rgba(255, 255, 255, 0.87);height:21px;cursor: pointer;z-index:1;" class="uploadContactPicture" id="uploadContactPicture'.$contactRow['id'].'"><div style="margin-top: 3px;" id="uploadContactPictureText'.$contactRow['id'].'">Upload photo </div></div></label> <input id="file-input'.$contactRow['id'].'" class="'.$contactRow['id'].'" type="file" name="file[]" style="display: none;" accept="image/*"/></div>' : '<div style="background-image:url(php/imageViewContact.php?id='.$contactRow['id'].'&rand='.$random.');box-shadow:-3px 3px rgba(128, 123, 123, 0.28);width:95px; height: 95px;background-size:cover;background-position:center top;vertical-align:middle" class="fullProfileContact" id="'.$contactRow['id'].'"></div>';
$contactRowStreet = (empty($contactRow['homestreet'])) ? (empty($contactRow['officestreet']) ? '' : $contactRow['officestreet']) : $contactRow['homestreet'];
?>
<div style="background: rgba(255, 255, 255, 0.64);width:97.5%;border-radius: 5px;box-shadow:1px 3px rgba(128, 123, 123, 0.28);margin-bottom:9px;height:124px;" id="contact<?php echo $contactRow['id']; ?>">
<div class="imageHolderContacts" style="border-right: 1px dotted rgba(153, 153, 153, 0.57);width:115px;float: left;">
<img src="images/tape.png" style="width:50px;position: absolute;z-index:999;margin-top: -19px;margin-left:22px;" alt="tape"><?php echo $emptyImage; ?>
</div>
<div style="float: left;margin-left: 16px;margin-top:3px;font-family:Arial, Helvetica, sans-serif;font-size: 11pt;color:rgba(103, 103, 103, 0.65);">
<div style="position: absolute; width:99%;display:inline-table;">
<div style="float: left;margin-right:4px;">
<?php echo ucfirst($contactRow['name']).' '.ucfirst($contactRow['surname']); ?>
</div>
<div style="overflow:hidden;width:290px;border-left: 1px dotted #999999;">
<div style="margin-left:4px; width:400px;position:static"><?php echo $contactRowStreet ?> </div>
</div>
</div>
</div>
</div>
<?php
}
答案 0 :(得分:1)
你好Arijanit Nitti Salihu,
由于我们没有您的显示数据代码,我假设并回答您:
如果你得到空字段值,你可以简单地为" "
添加一个空格,所以你的代码就像
if(!empty($row['name'])){
echo $row['name'];
}else{
echo " "
}
如果您想要代替该元素的上边距,可以放置样式min-width
和clear:both;
属性:或者您可以使用<p></p>
标记,这样就可以:
if(!empty($row['name'])){
echo "<p>".$row['name']."</p>";
}else{
echo "<p> </p>"
}
根据您的给定代码,我显示的是name
和surname
字段的代码,就像您必须处理所有其他字段一样。
while($contactRow = $contact->fetch_assoc()){
$random = rand(0,1000006050);
$emptyImage = (empty($contactRow['picture'])) ? '<div class="emptyProfile" style="cursor: pointer;width: 95px"><label for="file-input'.$contactRow['id'].'" style="z-index:2;zoom: 1;display: inline-block;vertical-align: top;"><img src="images/person.jpg" style="width: 95px;cursor: pointer;z-index:2;zoom: 1"><div style="position: absolute;margin-top:-25px;font-size: 8pt;font-family:Verdana, Arial, Helvetica, sans-serif;zoom:0;opacity: 0;text-align: center;width:95px;background: rgba(255, 255, 255, 0.87);height:21px;cursor: pointer;z-index:1;" class="uploadContactPicture" id="uploadContactPicture'.$contactRow['id'].'"><div style="margin-top: 3px;" id="uploadContactPictureText'.$contactRow['id'].'">Upload photo </div></div></label> <input id="file-input'.$contactRow['id'].'" class="'.$contactRow['id'].'" type="file" name="file[]" style="display: none;" accept="image/*"/></div>' : '<div style="background-image:url(php/imageViewContact.php?id='.$contactRow['id'].'&rand='.$random.');box-shadow:-3px 3px rgba(128, 123, 123, 0.28);width:95px; height: 95px;background-size:cover;background-position:center top;vertical-align:middle" class="fullProfileContact" id="'.$contactRow['id'].'"></div>';
$contactRowStreet = (empty($contactRow['homestreet'])) ? (empty($contactRow['officestreet']) ? '' : $contactRow['officestreet']) : $contactRow['homestreet'];
?>
<div style="background: rgba(255, 255, 255, 0.64);width:97.5%;border-radius: 5px;box-shadow:1px 3px rgba(128, 123, 123, 0.28);margin-bottom:9px;height:124px;" id="contact<?php echo $contactRow['id']; ?>">
<div class="imageHolderContacts" style="border-right: 1px dotted rgba(153, 153, 153, 0.57);width:115px;float: left;">
<img src="images/tape.png" style="width:50px;position: absolute;z-index:999;margin-top: -19px;margin-left:22px;" alt="tape"><?php echo $emptyImage; ?>
</div>
<div style="float: left;margin-left: 16px;margin-top:3px;font-family:Arial, Helvetica, sans-serif;font-size: 11pt;color:rgba(103, 103, 103, 0.65);">
<div style="position: absolute; width:99%;display:inline-table;">
<?php if(!empty($contactRow['name'])){ ?>
<div style="float: left;margin-right:4px; clear:both;">
<p><?php echo ucfirst($contactRow['name']).' '.ucfirst($contactRow['surname']); ?></p>
</div>
<?php }else{ ?>
<div style="float: left;margin-right:4px; clear:both;">
<p> </p>
</div>
<?php } ?>
<?php if(!empty($contactRow['surname'])){ ?>
<div style="float: left;margin-right:4px; clear:both;">
<p><?php echo ucfirst($contactRow['surname']).' '.ucfirst($contactRow['surname']); ?></p>
</div>
<?php }else{ ?>
<div style="float: left;margin-right:4px; clear:both;">
<p> </p>
</div>
<?php } ?>
<div style="overflow:hidden;width:290px;border-left: 1px dotted #999999;">
<div style="margin-left:4px; width:400px;position:static"><?php echo $contactRowStreet ?> </div>
</div>
</div>
</div>
</div>
<?php
}
我希望这会对你有帮助。!
答案 1 :(得分:0)
这取决于您要在何处找到您的数据。但是根据您的问题,我认为您希望通过联系人的图像在中心垂直的某个位置管理您的数据。
如果你能够在你的mysql行中count the non empty fields,那么你可以使用php if / switch语句来管理它。
注意:请按照相关的stackoverflow答案来计算mysql表行的非空字段
<?php
$margin-top = "";
switch ($row['total_non_empty_fields']) {
case 1:
$margin-top = "100px";
break;
case 2:
$margin-top = "90px";
break;
case 3:
$margin-top = "80px";
break;
case 4:
$margin-top = "70px";
break;
case 5:
$margin-top = "60px";
break;
case 6:
$margin-top = "50px";
break;
case 7:
$margin-top = "40px";
break;
case 8:
$margin-top = "30px";
break;
case 9:
$margin-top = "20px";
break;
case 10:
$margin-top = "10px";
break;
default:
$margin-top = "0px";
break;
}
echo "<div id='contact-detail' style='margin-top:".$margin-top."'>
your code......
</div>";
?>