Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Links

Status
Not open for further replies.

jgd12345

Technical User
Joined
Apr 22, 2003
Messages
124
Location
GB
Hi, I wonder if there's a simpler way of doing the following. It's quite long winded for something so basic but it works. Here's an example of how it looks
Thanx

while($band = mysql_fetch_array($query2)) {
$tabs = '';
$end = '';

$query = mysql_query("SELECT * FROM $bdb_tabs WHERE bid='$band[id]' AND filetype!='Lyrics'");

if(mysql_num_rows($query) != 0) {
$tabs .= ' - [Tabs: ';
$end = "yes";
}

$query = mysql_query("SELECT * FROM $bdb_tabs WHERE bid='$band[id]' AND filetype='Bass Tab'");

if(mysql_num_rows($query) != 0) {
$previous = "yes";
$tabs .= '<a href=&quot;tabs_songs.php?bid='.$band[id].'&filetype=bass&quot;>Bass</a>';
}

$query = mysql_query(&quot;SELECT * FROM $bdb_tabs WHERE bid='$band[id]' AND filetype='Drum Tab'&quot;);

if(mysql_num_rows($query) != 0) {
if($previous == &quot;yes&quot;) {
$tabs .= ' | ';
}

$previous = &quot;yes&quot;;
$tabs .= '<a href=&quot;tabs_songs.php?bid='.$band[id].'&filetype=drum&quot;>Drum</a>';
}

$query = mysql_query(&quot;SELECT * FROM $bdb_tabs WHERE bid='$band[id]' AND filetype='Guitar Tab'&quot;);

if(mysql_num_rows($query) != 0) {
if($previous == &quot;yes&quot;) {
$tabs .= ' | ';
}

$tabs .= '<a href=&quot;tabs_songs.php?bid='.$band[id].'&filetype=guitar&quot;>Guitar</a>';
}

if($end == &quot;yes&quot;) {
$tabs .= ']';
}

$query = mysql_query(&quot;SELECT * FROM $bdb_tabs WHERE bid='$band[id]' AND filetype='Lyrics'&quot;);

if(mysql_num_rows($query) != 0) {
$tabs .= ' - [<a href=&quot;tabs_songs.php?bid='.$band[id].'&filetype=lyrics&quot;>Lyrics</a>]';
}

eval(&quot;\$bandsrow .= \&quot;&quot;.template(&quot;bands_row&quot;).&quot;\&quot;;&quot;);
}
 
Howsabout telling us what it's supposed to do as well, either some comments in the code or just a short synapsis would probably suffice.

-Rob
 
I thought the example would pretty much show that but basically there's tabs for certain bands (lyrics,guitar,bass,drum) and it checks if there are tabs for the specific band (by a field called bid in the tabs table) and if it exists it displays the relative link as shown in the example. Thanx
 
hehe, doesn't matter I'll keep it how it is.
 
sleipnir
If I remember right tabs are a kind of shorthanded sheet music for guitar players

jgd12345
Yes, there's definately one huge way to shorten everything you're doing up, it's more on the SQL side... but you're doing a
Code:
SELECT * FROM $bdb_tabs WHERE bid='$band[id]' AND filetype!='Lyrics'&quot;

and then just changing your filetype... I don't know if you even need the filetype limitation in there or if you're fetching all of them.  Additionally, I don't know the structure of $bdb_tabs, but I'm guessing you're wasting space by doing a SELECT *... but that's trivial.

Basically I'd rewrite it as.

SELECT * FROM $bdb_tabs WHERE bid='$band[id]' ORDER BY filetype;

Then use a

(might I suggest using $result instead of $query as a varibable name)

while($row = mysql_fetch_assoc($query)) {

}

In that loop examine the contents of $row[&quot;filetype&quot;] to determine which type of tab you're dealing with, and output the appropriate line.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top