Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP MySQL Database Column Referencing
    primarykey
    data
    text
    <p>sorry for bothering you again but I'm really stuck!</p> <p>How would it be possible to do an if statement referencing wherever or not data was from a certain column or to strip the last number in a column's name and reference it that way?</p> <p>Basically I have an musicians database, where a person from the PEOPLE table is linked via ID to instruments in the INSTRUMENTS table, I have an e-mail search function that I need to send out the relative data to the relative instruments. So if someone plays guitar as their 2nd instrument and someone else plays it as their 5th I need the relevant grade, standard and comments to get sent with them in the e-mail function.</p> <p>I want to get the comments[i] , grade[i], standard[i] of the matching instrument[i]</p> <p>My tables layout: ( I know it isn';t very efficient and I will look into DB normalization in the future!)</p> <hr> <p>TABLE:<strong>INSTRUMENTS</strong></p> <p>COLUMNS:</p> <pre><code> id instrument1 grade2 standard3 comments4 instrument2 grade2 standard2 comments2 instrument3 grade3 standard3 comments3 instrument4 grade4 standard4 comments4 instrument5 grade5 standard5 comments5 </code></pre> <p>TABLE: <strong>PEOPLE</strong></p> <p>COLUMNS:</p> <pre><code>id first last snumber course email graduate inumber </code></pre> <hr> <p>EDIT:</p> <blockquote> <pre><code> while($getresults = mysql_fetch_assoc($result)){ </code></pre> </blockquote> <pre><code> $peoplequery = "SELECT * FROM people WHERE id = {$getresults [id]}"; $peopleresults = @mysql_query($peoplequery); $getpeopleresults = mysql_fetch_assoc($peopleresults); //add the details returned by the database to the table: $table .= " &lt;td&gt;&lt;p&gt;{$getpeopleresults [first]} {$getpeopleresults [last]}&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;{$getpeopleresults [email]}&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;{$getpeopleresults [course]}&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;{$getresults [grade]}&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;{$getresults [standard]}&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;{$getresults [comments]}&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td colspan=8&gt;&lt;hr size=1 color=gray&gt;&lt;/td&gt;&lt;/tr&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.
    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