2xAA Posted July 25, 2011 Share Posted July 25, 2011 Hi guys, I'm creating a patchbook type thing where users post their settings for instruments for a music creation program called 'Little Sound DJ' (LSDJ for short). I've literally been doing PHP and mySQL for two days and I've learnt a lot already but I'm kinda stuck now. Already I've implemented a punBB user system which stores the user who created the patch and hides the Submit button to stop guests posting patches and flooding the database. I've also got the whole thing writing and calling data to my database. What I need help with is filtering between and displaying patches. There are 4 types of patches, all with different data which can be entered into them: PULSE - WAVE - KIT - NOISE All of these are being stored in the same table like so: pulse_name pulse_ etc.. wave_name wave_ etc... kit_name kit_ etc... noise_name noise_ etc... The table also has an id row and a username row, storing the name of the punBB user. So if I show a table full of results for a PULSE patch like so: (It's not pretty, but I'll style it once I've got the back code done) <table align="center" width="228" border="1" cellspacing="0"> <tr> <td width="49"><? echo $rows['usrname']; ?></td> <td width="175"><? echo $rows['type']; ?></td> </tr> <tr> <td>Name:</td> <td><? echo $rows['pulse_name']; ?></td> </tr> <tr> <td>Envelope:</td> <td><? echo $rows['pulse_envelope']; ?></td> </tr> <tr> <td>Wave:</td> <td><? echo $rows['pulse_wave']; ?></td> </tr> <tr> <td>Output:</td> <td><? echo $rows['pulse_output']; ?></td> </tr> <tr> <td>Length:</td> <td><? echo $rows['pulse_length']; ?></td> </tr> <tr> <td>Sweep</td> <td><? echo $rows['pulse_sweep']; ?></td> </tr> <tr> <td>Vib. Type</td> <td><? echo $rows['pulse_vibtype']; ?></td> </tr> <tr> <td>PU2 Tune</td> <td><? echo $rows['pulse_pu2tune']; ?></td> </tr> <tr> <td>PU Fine</td> <td><? echo $rows['pulse_pufine']; ?></td> </tr> <tr> <td>Automate</td> <td><? if($rows['pulse_auto'] == ''): echo 'Off'; else: echo 'On'; endif; ?></td> </tr> <tr> <td>Table</td> <td><? if($rows['pulse_table'] == ''): echo 'Off'; else: echo 'On'; endif; ?></td> </tr> </table> How can I tell the PHP/mySQL to display a patch separately in a different table if the type (PULSE,WAVE,KIT,NOISE) is different? I am literally just calling the data from the database like so: // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> My server details: MySQL client version: 5.0.32 Used PHP extensions: mysqli If you need more info please ask, I'd really like to get this solved soon! Thanks, 2xAA Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/ Share on other sites More sharing options...
fenway Posted July 26, 2011 Share Posted July 26, 2011 Displaying the results of outside the scope of the DB. Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247109 Share on other sites More sharing options...
2xAA Posted July 26, 2011 Author Share Posted July 26, 2011 Okay, I think I should create a different table for each instrument, that way I can display everything differently. Pain in the ass, but that should work. Sorry for cluttering your forums :/ Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247306 Share on other sites More sharing options...
fenway Posted July 26, 2011 Share Posted July 26, 2011 If they're actually different -- as in they have different fields -- then sure. Otherwise, add a "type" column, and your problem goes away. Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247318 Share on other sites More sharing options...
2xAA Posted July 26, 2011 Author Share Posted July 26, 2011 How would I add in a type column opposed to a row? Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247321 Share on other sites More sharing options...
fenway Posted July 26, 2011 Share Posted July 26, 2011 Well, you haven't explicitly listed all of your fields -- so please do -- and I'll give you suggestions accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247348 Share on other sites More sharing options...
2xAA Posted July 26, 2011 Author Share Posted July 26, 2011 id usrname type pulse_name pulse_envelope pulse_wave pulse_output pulse_length pulse_sweep pulse_vibtype pulse_pu2tune pulse_pufine pulse_auto pulse_table wave_name wave_volume wave_output wave_vibtype wave_play wave_length wave_repeat wave_speed wave_auto wave_table wave_wave wave_filter wave_q wave_dist wave_phase wave_svol wave_scutoff wave_sphase wave_svshift wave_evol wave_ecutoff wave_ephase wave_evshift kit_name kit_kit1 kit_kit2 kit_volume kit_output kit_pitch kit_offset1 kit_offset2 kit_len1 kit_len2 kit_loop1 kit_loop2 kit_speed kit_dist kit_vibtype kit_auto kit_table noise_name noise_output noise_length noise_shape noise_scmd noise_auto noise_table the _auto and _table for each type are checkboxes. To display these I'm using an 'if' function to say if they are on or off. Thanks for the help by the way Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247360 Share on other sites More sharing options...
fenway Posted July 26, 2011 Share Posted July 26, 2011 Oh yeah -- definitely different tables -- there share almost nothing. Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247545 Share on other sites More sharing options...
2xAA Posted July 26, 2011 Author Share Posted July 26, 2011 Thank-you fenway Would you like any credit (ie a link to your profile here?/website is you have one?) on the bottom of the front page when it is finished? (This site should generate a fair amount of traffic) If not you can 'solve'/delete this thread. Thanks once again! Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247583 Share on other sites More sharing options...
fenway Posted July 27, 2011 Share Posted July 27, 2011 No need for credit -- but thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/242803-filtering-between-results-from-a-database/#findComment-1247654 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.