<![CDATA[ Support/Comments for MakeTable - My Forums]]> https://forums.modx.com/thread/?thread=38288 <![CDATA[Helme, please,...]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=5#dis-post-216394 I need from your help.
I want to migrate an existing page to ModX using MakeTable.
My problem is that I do not understand how to do this. huh
Thank you for your help.
Sergio

You can see the current page in www.cerianipublicidad.com.ar/web/guia_pymes_avisos.php
The PHP code of the page is the following:
//inicializo el criterio y recibo cualquier cadena que se desee buscar
$criterio = "";
if ($_GET["criterio"]!=""){
    $txt_criterio = $_GET["criterio"];
    $criterio = " AND empresas.empresa like '%" . $txt_criterio . "%'";
}

//Limito la busqueda
$TAMANO_PAGINA = 25;

//examino la página a mostrar y el inicio del registro a mostrar
$pagina = $_GET["pagina"];
if (!$pagina) {
    $inicio = 0;
    $pagina=1;
}
else {
    $inicio = ($pagina - 1) * $TAMANO_PAGINA;
}
//conecto con la base de datos
$conn = mysql_connect("localhost","user","pass");
mysql_select_db("database",$conn);

//miro a ver el número total de campos que hay en la tabla con esa búsqueda
$ssql = "select * from empresas,rubros WHERE rubros.Id_rubro=empresas.Id_rubro " . $criterio . " ORDER BY rubros.rubro,empresas.empresa";
$rs = mysql_query($ssql,$conn);
$num_total_registros = mysql_num_rows($rs);
//calculo el total de páginas
$total_paginas = ceil($num_total_registros / $TAMANO_PAGINA);

//pongo el número de registros total, el tamaño de página y la página que se muestra
echo "<div align='center'><b>";
echo "Hay " . $num_total_registros . " avisos registrados / ";
echo "Mostrando la página " . $pagina . " de " . $total_paginas . "";
echo "</div></b><br>";

//construyo la sentencia SQL
$ssql = "select * from empresas,rubros WHERE rubros.Id_rubro=empresas.Id_rubro " . $criterio . " order by rubros.rubro,empresas.empresa limit " . $inicio . "," . $TAMANO_PAGINA;
$rs = mysql_query($ssql);
print ("HTML CODE TO PRINT COLUMN HEADER");
  
$ultimorubro="";
while ($fila = mysql_fetch_object($rs)){
$Id_empresa = $fila->cod_emp;
$la_empresa = $fila->empresa;
$el_fono = $fila->telefono;
$el_mail = $fila->email;
$el_rubro = $fila->rubro;

if ($ultimorubro != $el_rubro ) {
  echo "<tr><td colspan='3' bgcolor='#CCCCCC'><b>$el_rubro</b></td></tr>";
  echo "<tr bgcolor='#FFFFFF'>";
  echo "<td><b>$la_empresa</b></td>";
  echo "<td><div align='right'>$el_fono</div></td>";
  if ($el_mail != "") {
    echo "<td><a href='mailto:$el_mail'>Em@il</a></td>";
  } else {
    echo "<td></td>";
  }
  echo "</tr>";
  $ultimorubro = $el_rubro;
} else {
  echo "<tr bgcolor='#FFFFFF'>";
  echo "<td><b>$la_empresa</b></td>";
  echo "<td><div align='right'>$el_fono</div></td>";
  if ($el_mail != "") {
    echo "<td><a href='mailto:$el_mail'>Em@il</a></td>";
  } else {
    echo "<td></td>";
  }
  echo "</tr>";
}
}

print ("</table><br>");

//cerramos el conjunto de resultado y la conexión con la base de datos
mysql_free_result($rs);
mysql_close($conn);

//muestro los distintos índices de las páginas, si es que hay varias páginas
echo "<div align='center'><b>";
if ($total_paginas > 1){
    for ($i=1;$i<=$total_paginas;$i++){
       if ($pagina == $i)
          //si muestro el índice de la página actual, no coloco enlace
          echo $pagina . " ";
       else
          //si el índice no corresponde con la página mostrada actualmente, coloco el enlace para ir a esa página
          echo "<a href='guia_pymes_avisos.php?pagina=" . $i . "&criterio=" . $txt_criterio . "'>" . $i . "</a> ";
    }
}
echo "</div></b>";
print("<form action='guia_pymes_avisos.php' method='get'>
Buscar empresa:
<input type='text' name='criterio' size='22' maxlength='150'>
<input type='submit' value='Buscar'>
</form>
]]>
yiyo Nov 17, 2006, 08:59 AM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=5#dis-post-216394
<![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=5#dis-post-216393 Quote from: doze at Sep 07, 2006, 06:57 AM

If I go to page 2 in the courses table when 25 items are listed per page and then select 50 to be listed, I get "no industries found" message.

Hmmmm, that does appear to causes issues. If you select say 10 per page, then go to page 2 and select to view more per page than the actual number of records, it shows the error. This does not occur if you’re on page 1 sad

UPDATE: The problem appears to be triggered whenever you chose to display more records per page, than there is remaining (not total like I thought before) from any page but the first one.

eg. If I have 100 records, and I choose to show 25 records per page, I’ll have 4 pages. If I got to page two, I’ll still have 3 pages left (75 records). If I select to show 50 records per page, no problems, but 100 per page will cause issue.

If I use the same 100 record example and go to page 3, so I have 1 page (25 records) left, and now select 50 per page, I’ll get the error.

Maybe because it can’t populate the 50 records on the page from the current position in the table?]]>
briggsys Sep 15, 2006, 05:29 AM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=5#dis-post-216393
<![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216392
I have one last question for you, is there an easy way to have the results so that if the "start date" is todays date or before, then do not return that row in the array (webpage)

Then I could just upload the file and the snippet would ensure only current results are returned and I would not need to edit the table all the time to remove old dates.


FIXED:
$sql = 'SELECT * FROM modx_courses WHERE end >= CURDATE() '.$objTable->handleSorting().' '.$objTable->handlePaging();

end is the name of the field in the table modx_courses I wanted to compare dates with (its the end date of the course)]]>
briggsys Sep 15, 2006, 03:39 AM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216392
<![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216391 Quote from: Briggsy at Sep 11, 2006, 05:57 AM

In the example below it is in VARCHAR because DATE turned it into YYYY-MM-DD. The CSV that I used to upload the data was it in DD-MM-YY which is also the same format as I wanted it shown on the site.

I can get the CSV changed but still need to show it in DD-MM-YY on website. FOund a few SQL querys and PH codes to do it but couldn’t get them to work (don’t know enough)

Two approaches to sorting properly and displaying any format...

1. Store as unix timstamp or datetime in MySQL; MakeTable can then sort by the actual field name and you can use something like this to convert the output when assigning the column values to each row of the result set array:
<?php
...
    'StartDate' => strftime('%d-%m-%y', strtotime($row['Start']),
...
?>

and then when creating the table headers:
<?php
...
'StartDate'=> $objTable->prepareOrderByLink('Start', 'Start Date'),
...
?>


The first param in prepareOrderByLink is the actual column name to sort by, and the second is the label for the table header column.

2. Without changing the db, you can use strtotime to convert that European date format to a unix timestamp (as in the above example) and make that concatenated with the id field, the key of each array element; you can then simply krsort() the results to order them properly:

<?php
...
$results= array ();
// loop through result of query and assign each row of values
foreach ($rs as $row) {
    // create a sortable key in format {Start}-{Code}
    $rowKey= strtotime($row['Start']) . '-' . $row['Code'];
    $results[$rowKey]= array (
        'Code' => $row['Code'],
        ...
    );
}
...
// Order array in reverse by key
krsort($results);
...
?>
]]>
opengeek Sep 11, 2006, 11:39 AM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216391
<![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216390 Quote from: OpenGeek at Sep 06, 2006, 09:33 PM

And you should be sorting on the actual field with the date value, which I hope is stored as a DATE type in the database (in the format YYYY-MM-DD);

In the example below it is in VARCHAR because DATE turned it into YYYY-MM-DD. The CSV that I used to upload the data was it in DD-MM-YY which is also the same format as I wanted it shown on the site.

I can get the CSV changed but still need to show it in DD-MM-YY on website. FOund a few SQL querys and PH codes to do it but couldn’t get them to work (don’t know enough)]]>
briggsys Sep 11, 2006, 12:57 AM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216390
<![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216389 doze Sep 07, 2006, 01:57 AM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216389 <![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216388 Quote from: Briggsy at Sep 06, 2006, 09:06 PM

All works except the date fields (which are in dd/mm/yy). Sorting by ascending order I get results below, which is sorting on the first two didgets, and then secondary sort on the second two digits.

02/12/06
03/10/06
03/12/06
04/11/06
04/12/06

It’s Jason BTW, not Jarrod -- but anyway smiley I didn’t take offense to anything you mentioned; was just trying to clarify where my efforts were focused...

And you should be sorting on the actual field with the date value, which I hope is stored as a DATE type in the database (in the format YYYY-MM-DD); otherwise, you’re going to have to come up with a fancy, custom algorithm to sort that properly after you build the array, or a fancy custom SORT BY clause in your query using MySQL date functions.]]>
opengeek Sep 06, 2006, 04:33 PM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216388
<![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216387

Jarrod Jason, my comment was not to say anything bad about you or your snippet, I was merely thinking it could have been beneficial for us non developer types, however sounds like this is already in hand with your new version which I am looking forward too.

I do however have one more issue I am hoping someone can help me with?

I am trying to have it sort by the following headings: Code / Start Date / End Date / Course / Location

All works except the date fields (which are in dd/mm/yy). Sorting by ascending order I get results below, which is sorting on the first two didgets, and then secondary sort on the second two digits rather than by the actual date as required.

02/12/06
03/10/06
03/12/06
04/11/06
04/12/06

]]>
briggsys Sep 06, 2006, 04:06 PM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216387
<![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216386 now only want have some time to surf this alone
hi]]>
xyzvisual Sep 05, 2006, 04:26 AM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216386
<![CDATA[Re: Support/Comments for MakeTable]]> https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216385 Quote from: xyzvisual at Sep 04, 2006, 05:27 PM

any link of this snippet/class working?
Unfortunately, I do not have any publically accessible instances that I can think of, though I’ve certainly used this class on a dozen or so projects to produce a wide range of table layouts for managing custom data for the respective sites. The snippet was simply an example I threw together to show how to use some of the class.

I would document more of the features of this, but I am currently producing a replacement for MakeTable that can use chunks as templates, support groupings with custom templates and more. It’s part of the xPDO project I’ve been working on for the past few months, which currently includeds an updated version of MakeTable that works with any xPDO-generated classes (but that’s a whole other topic).

In the meantime, I’ll answer any questions you might have about the class, or how to author a snippet for it as I am able.]]>
opengeek Sep 04, 2006, 09:17 PM https://forums.modx.com/thread/38288/support-comments-for-maketable?page=4#dis-post-216385