Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with @Caleb But still you wanna be with this database design, you can do like this, this is most in-efficient way because of your DB structure.</p> <p>I have not tested this, so there might be some syntax errors.</p> <pre><code>$selQuery = "select * from instruments LEFT JOIN people ON instruments.id=people.id where instrument1 like 'guitar' OR instrument2 like 'guitar' OR instrument3 like 'guitar' OR instrument4 like 'guitar' OR instrument5 like 'guitar'"; $resQuery = mysql_query($selQuery) $peoples = array(); while($row = mysql_fetch_assoc($resQuery)) { for($i = 1; $i&lt;= 5; $i++ ) { if(strtolower($row['instrument'.$i]) == strtolower('Guitar')) { $people = array(); $people['id'] = $row['id']; $people['first'] = $row['first']; $people['email'] = $row['email']; $people['instrument'] = $row['instrument'.$i]; $people['grade'] = $row['grade'.$i]; $people['standard'] = $row['standard'.$i]; $people['comments'] = $row['comments'.$i]; array_push($peoples , $people); break; } } } </code></pre> <p>ok I have reviewed ur code,</p> <p>make changes as below</p> <pre><code>//Find instruments searched for: $query = "SELECT * from instruments where '$search' in (instrument , instrument2, instrument3, instrument4, instrument5)"; $result = @mysql_query($query); //Start building the table: $table = "&lt;th&gt;&lt;p&gt;&lt;b&gt;You searched for $search&lt;/b&gt;&lt;/p&gt;&lt;/th&gt; &lt;table&gt; &lt;th&gt; &lt;p&gt;&lt;b&gt;Name &lt;/b&gt;&lt;/p&gt;&lt;/th&gt; &lt;th&gt; &lt;p&gt;&lt;b&gt;Email &lt;/b&gt;&lt;/p&gt; &lt;/th&gt; &lt;th&gt; &lt;p&gt;&lt;b&gt;Course &lt;/b&gt;&lt;/p&gt;&lt;/th&gt; &lt;th&gt; &lt;p&gt;&lt;b&gt;Grade &lt;/b&gt;&lt;/p&gt;&lt;/th&gt; &lt;th&gt; &lt;p&gt;&lt;b&gt;Standard &lt;/b&gt;&lt;/p&gt;&lt;/th&gt; &lt;th&gt; &lt;p&gt;&lt;b&gt;Comments&lt;/b&gt;&lt;/p&gt; &lt;/th&gt;&lt;/tr&gt;"; $peoples = array(); while($row = mysql_fetch_assoc($result)){ if(strtolower($row['instrument']) == strtolower($search)) { $people = array(); $people['id'] = $row['id']; $people['instrument'] = $row['instrument'.$i]; $people['grade'] = $row['grade'.$i]; $people['standard'] = $row['standard'.$i]; $people['comments'] = $row['comments'.$i]; array_push($peoples , $people); continue; } for($i = 2; $i&lt;= 5; $i++ ) { if(strtolower($row['instrument'.$i]) == strtolower($search)) { $people = array(); $people['id'] = $row['id']; $people['instrument'] = $row['instrument'.$i]; $people['grade'] = $row['grade'.$i]; $people['standard'] = $row['standard'.$i]; $people['comments'] = $row['comments'.$i]; array_push($peoples , $people); break; } } } foreach($peoples as $people) { $peoplequery = "SELECT * FROM people WHERE id = '".$people[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;{$people[grade]}&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;{$people[standard]}&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;{$people[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.
 

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