Retrieving data from database
-
Hi everyone,
I’m trying to write a plugin that should retrieve data from the database and display them, but for some reason it’s not working. This is my code
global $wpdb; $domande = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."tstile ORDER BY Posizione_Gruppo ASC, Posizione_Domanda ASC;"); $arrayDomande = array(); foreach($domande as $domanda) { if (!isset($arrayDomande[$domanda->Posizione_Gruppo])) { $arrayDomande[$domanda->Posizione_Gruppo] = array('gruppo' => $domanda->Gruppo, 'domande' => array()); } $arrayDomande[$domanda->Posizione_Gruppo]['domande'][$domanda->Posizione_Domanda] = array( 'ID' => $domanda->ID, 'domanda_sx' => $domanda->Domanda_Sx, 'domanda_dx' => $domanda->Domanda_Dx, 'valore_sx' => $domanda->Valore_Sx, 'valore_dx' => $domanda->Valore_Dx); } ?> <form name="frm_stile" id="id_frm_stile" method="post"> <?php wp_nonce_field('nonce_save_test_stile','nonce_stile'); ?> <input type="hidden" name="action" value="save_t_stile" /> <table class="table_test ab"> <thead class="table_header"> <tr> <th class="h_risposta"></th> <th class="h_domanda" width="45%">Opzione</th> <th class="h_text">#</th> <th class="h_domanda domanda2" width="45%">Opzione</th> <th class="h_risposta"></th> </tr> </thead> <?php $ix = 1; foreach($arrayDomande as $posizioneGruppo => $infoGruppo) { ?> <tbody> <tr> <th colspan="5" class="gruppo"><?php echo sprintf("Gruppo %s", ($ix)) ?></th> </tr> <?php $iy = 1; foreach($infoGruppo['domande'] as $opzione) { ?> <tr class="<?php echo($iy%2==0?'odd':'even'); ?>"> <td class="input" width="1"> <input type="hidden" name="ixd[<?php echo sprintf($opzione['ID']);?>]" value="<?php echo sprintf("%s,%s", $iy, $ix); ?>" /> <input type="radio" name="r[<?php echo sprintf($opzione['ID']); ?>]" id="id_domanda_sx_<?php echo sprintf($opzione['ID']); ?>" value="sx"/> </td> <td class="domanda"><label for="id_domanda_sx_<?php echo sprintf($opzione['ID']); ?>"><?php echo sprintf($opzione['domanda_sx'])?></label></td> <td class="text numero-domanda"><?php echo sprintf($iy); ?></td> <td class="domanda domanda2"><label for="id_domanda_dx_<?php echo sprintf($opzione['ID']); ?>"><?php echo sprintf($opzione['domanda_dx'])?></label></td> <td class="input" width="1"><input type="radio" name="r[<?php echo sprintf($opzione['ID']); ?>]" id="id_domanda_dx_<?php echo sprintf($opzione['ID']); ?>" value="dx"/></td> </tr> <?php $iy++; } ?> </tbody> <?php $ix++; } ?> <tfoot> <tr> <td colspan="5"><button id="btnSave">Salva e visualizza risultato</button></td> </tr> </tfoot> </table> </form>
Any help? Thanks in advance.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Retrieving data from database’ is closed to new replies.