Trying to use custom PHP code in WordPress Page
-
I have modified a page on my Word Press site to display a custom table using php/MySQL.
I must point out my skill level is poor and most code has been found from the net and changed by trial and error.
I can get the page to work using a simple single column table but ideally I would like to be able to display in multiple columns.
Using the details from this site –Webhostingtalk
I have come up with the following code but I am having issues with it not displaying data in a table.
<?php global $wpdb; $i = 1; $sql= "SELECT <code>value</code>, COUNT(*) as tot_year FROM <code>wp_bp_xprofile_data</code> WHERE <code>field_id</code> =45 GROUP BY value;"; $result = $wpdb->get_results($sql); // SHOW ON SCREEN THE RESULTS OF THE SRATCH - TO BE REMOVED AFTER TESTING print_r ($result); echo '<P><P>'; $num_years = $wpdb->num_rows; $num_columns = 4; $idx = 1; $num_rows = $num_years / $num_columns; //SHOW ON SCREEN THE NUMBER OF COLUMNS NEEDED - TO BE REMOVED AFTER TESTING echo 'number of rows: '.$num_rows; // CODE WORKS UP TO THIS POINT // Place the data in the proper columns / rows. while ($row = mysql_fetch_array($result)) { $row_id = $idx % $num_rows; $row[row_id] = "<td>$row[value]</td>"; $idx++; } // Print the whole thing now. echo ("<table>"); foreach ($rows as $cur_row) { echo ("<tr>" . $cur_row . "</tr>\n"); } echo ("</table>"); ?>
Could some kind soul please point out what I have done wrong please.
Cheers ??
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Trying to use custom PHP code in WordPress Page’ is closed to new replies.