I am trying to get rid of the border space between the cells. I thought cellspacing would do the trick but there is still a slim white border. Can anyone give me some advice...
<body>
<center><table style="cellspacing:0; width:400px; border:none;">
<?
echo "<tr><td> Team </td><td>Correct Picks</td><td>Points</td></tr>";
while($row = mysql_fetch_array($memberslist)) {
if ($row['User_ID'] == $id) {
echo "<tr bgcolor=\"gray\"><td>" . $row['User_ID'] . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
} else {
echo "<tr><td>" . $row['User_ID'] . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
}
}
?>
</table></center>
</body>
cellspacing=0;
is no CSS. That was once a HTML attribute:
<table cellspacing="0" style="width:400px">
See as well the related (duplicate?) question:
How to set cellpadding & cellspacing in CSS?
Related
I'm using Simple XML to format election results data into a user-friendly webpage. I'm listing the races and candidates using PHP foreach, but there's some extra data (7 elements, to be exact) nested under each race that's being treated as candidates. How can I filter them out?
Here's the XML: https://ftpcontent.worldnow.com/wicu/BTI/election.xml
Here's the code output: https://lillydigitalmedia.com/election.php
Here's the code:
<?php
$btiresults = simplexml_load_file("https://ftpcontent.worldnow.com/wicu/BTI/election.xml");
echo "<p><em>Updated: " . $btiresults['Time'] . "</em></p>";
foreach($btiresults->children() as $race) {
echo "<h4 class='card-title' style='margin-top: 20px'><strong>" . $race->Name1 . "</strong></h4>";
foreach($race->children() as $candidate) {
echo "<p style='width: 100%;'><span style='float: left;'><strong>" . $candidate->Name . "</strong> <small>" . $candidate->Party . "</small></span><span style='float: right;'>" . $candidate->Votes . " votes</span></p>";
echo "<div class='progress' style='height: 25px; width: 100%;'>";
echo "<div class='progress-bar' role='progressbar' style='width:" . $candidate->PercentageOfVotesCast . "%' aria-valuenow='" . $candidate->PercentageOfVotesCast . "' aria-valuemin='0' aria-valuemax='100'>" . $candidate->PercentageOfVotesCast . "%</div>";
echo "</div>";
}
}
?>
Thanks in advance.
Since you are dealing with xml, you might as well use xpath.
Try something like the following (after the existing echo "<p><em>Updated: " . $btiresults['Time'] . "</em></p>";):
$races = $btiresults->xpath('//Race');
foreach($races as $race) {
echo "<h4 class='card-title' style='margin-top: 20px'><strong>" . $race->Name1 . "</strong></h4>";
foreach($race->xpath('./Candidate') as $candidate) {
echo "<p style='width: 100%;'><span style='float: left;'><strong>" . $candidate->Name . "</strong> <small>" . $candidate->Party . "</small></span><span style='float: right;'>" . $candidate->Votes . " votes</span></p>";
echo "<div class='progress' style='height: 25px; width: 100%;'>";
echo "<div class='progress-bar' role='progressbar' style='width:" . $candidate->PercentageOfVotesCast . "%' aria-valuenow='" . $candidate->PercentageOfVotesCast . "' aria-valuemin='0' aria-valuemax='100'>" . $candidate->PercentageOfVotesCast . "%</div>";
echo "</div>";
}
}
and see if it works.
You could simply look at the tag name of the Element, using SimpleXMLElement::getName.
Wrap the content of your inner foreach loop into an if condition that checks if it is Candidate:
foreach($race->children() as $candidate) {
if($candidate->getName() == 'Candidate') {
echo '…';
}
}
(Might perhaps make sense to rename the variable from $candiate to something like $child, since at the time it gets assigned a value in the foreach loop, you don’t know whether its actually a Candidate node yet … but that is a rather philosophical aspect.)
hello guys i am trying to make a foreach loop in a while loop. in foreach loop i try to produce list elements with divs inside them but i have very strange output
here is my code
$countercat= 0;
$classvar= 1;
echo "<div class='selector-page'>";
echo "<div class='selector'>";
echo "<ul>";
while ($countercat <= 8){
$stmt=$conn->prepare('SELECT eidos, name, meta_keys, address, telephone, perioxi, st_img, st_open, st_close, lat, longtit FROM magazia WHERE perioxi= :perioxi AND eidos= :eidos ORDER BY st_id ASC');
$stmt->bindParam(':perioxi', $name, PDO::PARAM_STR);
$stmt->bindParam(':eidos', $eidos, PDO::PARAM_STR);
$eidos= $c_titles[$countercat]['c_name'];
$stmt->execute();
$allrows=$stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($allrows as $row) {
echo "<li>";
echo "<div class='p". $classvar . " w3-card targetDiv w3-margin-top cardsmar'>";
echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'";
echo "<div class='w3-container w3-center'>";
echo "<h3>" . $row['name'] ."</h3>";
echo "<p>" . $row['eidos'] . "</p>";
echo "<p>" . $row['address'] . " , " . $row['perioxi'] . "</p>";
echo "<p>" . $lang['wrlt'] . " : " . $row['st_open'] . "-" . $row['st_close'] . "</p>";
echo "<a href='katastimata.php?name=" . $row['name'] . "' role='button' class='w3-button w3-round w3black'>" . $lang['t9'] . "</a><br />";
echo "<a href='https://www.google.com/maps?q=loc:" . $row['lat'] . "," . $row['longtit'] . "' role='button' class='w3-button w3-round w3-green btnmar'>" . $lang['spot2'] . "</a>";
echo "</div>";
echo "</div>";
echo "</li>";
}
$countercat++;
$classvar++;
}
echo "</ul>";
echo "</div>";
echo "</div>";
}
?>
here is an image from my debugger consonle
as you see in the image inside in the ul tag exists only one li elemenemt
and the rest of them are out side ul /ul.
my first thought was that is not valid to put div tag in a li tag but this is not true if i use this in the top of my file
DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/html1-transitional.dtd"
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang:"en"
i am stack here for so long
what am i missing guys?
thanks in advance
vaggelis
You Didn't Close the <img> tag here.
echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'";
You Must Close the tag as
echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'/>";
This code reads a CSV file for creating a table. It works fine.
How do I make the 1st row to be formatted in header style (from the table CSS)?
<table id="myTable" class="tablesorter animated fadeInDown"> <!-- cellspacing='0' is important, must stay -->
<tbody>
<?php
$lines = file('graphdata/IndicForTableVsOthers.csv');
foreach ($lines as $lineNum => $line) {
if($lineNum == 0) {
print " <tr id=\"tr" . $lineNum . "\">";
}
print " <tr id=\"tr" . $lineNum . "\">";
$tokens = str_getcsv($line);
print "<td style=\"width: 300px;\">" . trim($tokens[0]) . "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[1]) . "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[2]) . "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[3]) . "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[4]) . "</td>";
print "</script>\n";
}
?>
</tbody>
This should work, I also changed some other parts who I think would have generated wrong marup.
<table id="myTable" class="tablesorter animated fadeInDown">
<?php
$lines = file('graphdata/IndicForTableVsOthers.csv');
foreach ($lines as $lineNum => $line) {
$cellType = ($lineNum == 0 ? "th" : "td");
$tokens = str_getcsv($line);
if ($lineNum == 0) echo "<thead>";
if ($lineNum == 1) echo "<tbody>";
echo "<tr id=\"tr" . $lineNum . "\">";
echo "<" . $cellType . " style=\"width: 300px;\">" . trim($tokens[0]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[1]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[2]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[3]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[4]) . "</" . $cellType . ">";
echo "</tr>";
if ($lineNum == 0) echo "</thead>";
}
if (count($lines) > 1) echo "</tbody>";
?>
</table>
If the first row is printed but it looks light and you want it Bold and Pretty so the user knows it's the header, add a class for convenience.
table.cs-contents tr:first-child td {
font-weight: bold;
text-align: center;
border-bottom: 2px solid #eaeaea;
}
I would like to add a url to php table along with variable.
Any one please help me solving this.
See the comment description in table for further info.
<?php
include('config.php');
$qry = "SELECT * FROM pincode_data where pinCode='641028'";
$result = mysql_query($qry) or die (mysql_error());
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
while($row=mysql_fetch_array($result))
{
echo "<tr><td>Pincode:</td> <td><a href='pinview.php?pin=" . $pinCode . "'>".$row['pinCode'] . "</td></tr>"; //I want a hyperlink here along with pin number example url: pinview.php?pin=641028
echo "<tr><td>Office Name:</td> <td>" . $row['postOffice'] . "</a></td>";
echo "<tr><td>Office Type:</td> <td>".$row['OfficeType'] . " </td></tr>";
echo "<tr><td>Contact:</td> <td>".$row['contact'] . "</td></tr>";
echo "<tr><td>Taluk:</td> <td>".$row['talukName'] . " </td></tr>";
echo "<tr><td>District:</td> <td>".$row['districtName'] . " </td></tr>";
echo "<tr><td>State:</td> <td>".$row['stateName'] . "</td></tr>";
echo "<tr><td>Postal Division:</td> <td>".$row['postalDivision'] . " </td></tr>";
echo "<tr><td>Postal Region:</td> <td>".$row['postalRegion'] . " </td></tr>";
echo "<td>Postal Circle:</td> <td>".$row['postalCircle'] . "</td> ";
}
echo "</table>";
mysql_close();
?>
Replace with this line you have to add $row['pinCode'] instead of $pinCode
echo "<tr><td>Pincode:</td> <td><a href='pinview.php?pin=" . $row['pinCode'] . "'>".$row['pinCode'] . "</td></tr>";
This my code:
<?php
$lijstDoelmannen = mysql_query("SELECT * FROM Speler WHERE positie = 'Doelman' ORDER BY familienaam, voornaam");
$teller = 1;
while($rij = mysql_fetch_array($lijstDoelmannen))
{
if($teller < 5){
echo "<td><a href='spelerDetail.php?spelerId='" . $rij['id'] . "><img src='images/spelers/unknown.png' alt='' width='50' />
<br /><br />" . $rij["id"] . " " . $rij['familienaam'] . " " . $rij['voornaam'] . "</a></td>";
}
}
?>
The problem is that in the hyperlink the parameter spelerId = spaces (not filled in). If I echo $rij["id"], it gives me the right value.
You have a ' in the wrong spot in your href.
"...<a href='spelerDetail.php?spelerId='" . $rij['id'] . ">..."
This should be:
"...<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>..."
<a href='spelerDetail.php?spelerId='" . $rij['id'] . ">
You need to move the apostrophe:
<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>
It's currently ending the link, before the variable is added.
You can also do:
echo "<td><a href='spelerDetail.php?spelerId={$rij['id']}'
while($rij = mysql_fetch_array($lijstDoelmannen))
{
if($teller < 5){
echo "<td><a href='spelerDetail.php?spelerId='" . $rij['id'] . "><img src='images/spelers/unknown.png' alt='' width='50' />
<br /><br />" . $rij["id"] . " " . $rij['familienaam'] . " " . $rij['voornaam'] . "</a></td>";
}
}
?>
I prefer writing the above code this way to avid these types of issues:
while($rij = mysql_fetch_array($lijstDoelmannen)){
if($teller < 5){ ?>
<td><a href="spelerDetail.php?spelerId=<?php echo $rij['id'] ?>">
<img src="images/spelers/unknown.png" alt="" width="50" />
<br /><br /><?php echo $rij['id'] . " " . $rij['familienaam'] . " " . $rij['voornaam'] ?></a></td>
<?php }} ?>