Need help reformating table content.

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
webtrix
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Feb 12, 2018 2:28 pm

Mon Feb 12, 2018 2:39 pm

Hi.

I have a table with a column that is in INT(11) with the following content: 20270224 and it´s used to sort the lines in the table to it needs to be kept in INT(11). The output result should end up being 24-02-2027. This result should be repeated for each line that is in the output.

I hope someone can help with the "recoding" of the table (column) content.

The code i use so far is:

Code: Select all

<?php require_once('Connections/DDS.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php require_once('Functions/SKVliste3Funk.php'); ?>
<?php
$SKV1 = new WA_MySQLi_RS("SKV1",$DDS,0);
$SKV1->setQuery("SELECT Medlemmer.*, SKVinfo.SKVtype, MAX(SKVinfo.SKVdato), SKVinfo.SKVID, SKVinfo.SKVMedlemsnummer, SKVinfo.SKVnummer, Betalt.*, `Status`.STATID, `Status`.STATMedlemsnummer, `Status`.`Status` FROM Medlemmer LEFT OUTER JOIN SKVinfo ON Medlemmer.Medlemsnummer = SKVinfo.SKVMedlemsnummer LEFT OUTER JOIN Betalt ON Medlemmer.Medlemsnummer = Betalt.BetMedlemsnummer LEFT OUTER JOIN `Status` ON Medlemmer.Medlemsnummer = `Status`.STATMedlemsnummer WHERE `Status`.`Status` = 'Indmeldt' GROUP BY SKVinfo.SKVMedlemsnummer ORDER BY Medlemmer.Navn ASC");
$SKV1->execute();
?>

<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>DDS-Slagelse</title>
		<!-- Bootstrap CSS Framework via CDN (kan også downloades) -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
		<link href="/css/main.css" rel="stylesheet">
		<style type="text/css">
		body {
	background-color: #CCC;
}
        </style>
	</head>

<body>
<p>&nbsp;</p>
<table width="977" border="1">
    <tr>
      <td>Medlemsnummer</td>
      <td>Navn</td>
        <td>Højeste SKV Niveau</td>
      <td>Længste gællende SKV Dato</td>
      <td>Status</td>
      <td>Betalt år</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  <?php
while(!$SKV1->atEnd()) {
	if (true){
?>

    <tr>
      <td width="100"><?php echo($SKV1->getColumnVal("SKVMedlemsnummer")); ?></td>
      <td width="200"><?php echo($SKV1->getColumnVal("Navn")); ?></td>
      <td width="148"><?php echo($SKV1->getColumnVal("SKVtype")); ?></td>
      <td width="187"><?php echo($SKV1->getColumnVal("MAX(SKVinfo.SKVdato)")); ?></td>
      <td width="151"><?php echo($SKV1->getColumnVal("Status")); ?></td>
      <td width="151"><?php echo($SKV1->getColumnVal("Betaltaar")); ?></td>
      <td width="151"><a href="step2trans.php?recordID=<?php echo($SKV1->getColumnVal("SKVMedlemsnummer")); ?>">Transporttilladelse</a></td>
      <td width="151"><a href="test.php?recordID=<?php echo($SKV1->getColumnVal("SKVMedlemsnummer")); ?>">test</a></td>
      <td width="151">&nbsp;</td>
    </tr>
    <?php																   
	}
  $SKV1->moveNext();
}
$SKV1->moveFirst(); //return RS to first record
?>
</table>
</body>
</html>
This is the line that has the table content that needs changing: <td width="187"><?php echo($SKV1->getColumnVal("MAX(SKVinfo.SKVdato)")); ?></td>

I hope someone can help.

Phi11W
New php-forum User
New php-forum User
Posts: 17
Joined: Thu Aug 17, 2017 3:37 am

Tue Feb 13, 2018 5:25 am

I have a table with a column that is in INT(11) with the following content: 20270224 and it´s used to sort the lines in the table so it needs to be kept in INT(11).
I strongly disagree.
If you're storing a date, then it should be held in a Date field, which affords you many more options.
The output result should end up being 24-02-2027. This result should be repeated for each line that is in the output.
Assuming you really, really can't change this field, then you need to do some string manipulation:

Code: Select all

$numVar = 20270224 ; 
$stringVar = (string)$numVar ; 
$stringVar = substr( $stringVar, 6, 2 ) . '-' . substr( $stringVar, 4, 2 ) . '-' . substr( $stringVar, 0, 3 ) ; 
echo ( $stringVar ) ; 
The alternative, if this were a Date field, is

Code: Select all

echo( ( new DateTime( $dateVar ) )->format( 'd-m-Y' ) ); 
Regards, Phill W.
Regards,
Phill W.

webtrix
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Feb 12, 2018 2:28 pm

Tue Feb 13, 2018 1:43 pm

Thanks.. That was the help i needed..

Best Regards
Jess

Post Reply