Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP only display rows from a mysql table that are associated with User ID
    primarykey
    data
    text
    <p>I hope someone can help me out,</p> <p>I have two tables <code>wp_wp_pro_quiz_statistic_ref</code> and <code>wp_wp_pro_quiz_statistic</code> the common link between them is <code>statistic_ref_id</code>.</p> <p>The data a want to display is in <code>wp_wp_pro_quiz_statistic</code> I can fetch it using something like this:</p> <pre><code>&lt;?php global $wpdb; $current_user = wp_get_current_user(); $current_user_statid = $wpdb-&gt;get_results( "SELECT * FROM wp_wp_pro_quiz_statistic_ref WHERE user_id = $current_user-&gt;ID"); $result = $wpdb-&gt;get_results( "SELECT * FROM wp_wp_pro_quiz_statistic WHERE $current_user_statid = statistic_ref_id"); echo "Question:"." "."Points:"."&lt;br&gt;&lt;br&gt;"; foreach($result as $row) { echo $row-&gt;question_id." ".$row-&gt;points."&lt;br&gt;"; } ?&gt; </code></pre> <p><code>wp_wp_pro_quiz_statistic_ref</code> stores the <code>user_id</code> and <code>statistic_ref_id</code> the user ID can be pulled using <code>$current_user = wp_get_current_user();</code> or something similar. Im not sure how to then use 'statistic_ref_id' to only display rows that match the value of <code>statistic_ref_id</code> in <code>wp_wp_pro_quiz_statistic</code>.</p> <p>Update: </p> <pre><code> &lt;table border="1" width="500px"&gt; &lt;tr&gt; &lt;th&gt;Question Number&lt;/th&gt; &lt;th&gt;Clause&lt;/th&gt; &lt;th&gt;Subject&lt;/th&gt; &lt;th&gt;Score&lt;/th&gt; &lt;/tr&gt; &lt;?php global $wpdb; $current_user = wp_get_current_user(); $result = $wpdb-&gt;get_results( " SELECT stats.* FROM wp_wp_pro_quiz_statistic stats JOIN wp_wp_pro_quiz_statistic_ref refs on stats.statistic_ref_id = refs.statistic_ref_id WHERE refs.user_id= $current_user-&gt;ID "); foreach($result as $row) { echo "&lt;tr&gt; &lt;td&gt;$row-&gt;question_id&lt;/td&gt; &lt;td&gt;some clause&lt;/td&gt; &lt;td&gt;some subject&lt;/td&gt; &lt;td&gt;$row-&gt;points&lt;/td&gt; &lt;/tr&gt;"; } ?&gt; &lt;/table&gt; &lt;table border="1" width="500px"&gt; &lt;tr&gt;&lt;td width="445px"&gt;Total Score (Maximum 125)&lt;/td&gt;&lt;td width="55px"&gt;0&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload