Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 07-13-2008, 08:28 PM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Non-VB query...

I'm trying to knock up a relatively simple script for accessing a database to pull out the Artist and Title of an album ... but there is a small issue of the fact that these are stored in tables which have 1 entry for each track (so it could effectively be 15 entries for the same Artist/Album). I've been trying to figure out how to pull both of these, but only once for unique results (I did use DISTINCT but it only apparently works on one column).

Here is the code I have at present:

PHP Code:
$result mysql_query("SELECT album, artist FROM samdb.songlist ORDER BY date_added DESC LIMIT 10"
or die(
mysql_error());
echo 
"<table>";
echo 
"<tr><td colspan='2' align='center'>Ten Latest Albums</td></tr>";
// keeps getting the next row until there are no more to get
while($row mysql_fetch_array$result )) {
    
// Print out the contents of each row into a table
    
echo "<tr><td>"
    echo 
$row['artist'];
    echo 
"</td><td>"
    echo 
" - ".$row['album'];
    echo 
"</td></tr>"

echo 
"</table>"
I found this example from another site which I've used ... it's definately not tidy, but I think is close enough for what I need to do!

What I basically need it to do is display one album title, even if there are 15 entries in the table, then if it finds any blank entries, discount them.

Hope this made some sense!

Jase
Reply With Quote
  #2  
Old 07-14-2008, 02:33 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

put a group by in there.

SELECT album, artist, max(date_added) as 'date_added' FROM samdb.songlist group by album,artist ORDER BY date_added DESC LIMIT 10")

Not sure how there can be blank entires though.

That's a badly un-normalised data structure.
artist_table
artist_id name birthdate favourite_color

album_table
artist_id album_id album_name other_album_data

track table
album_id track_name track_length
Reply With Quote
  #3  
Old 07-14-2008, 03:45 PM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Eikinskjaldi View Post
put a group by in there.

SELECT album, artist, max(date_added) as 'date_added' FROM samdb.songlist group by album,artist ORDER BY date_added DESC LIMIT 10")

Not sure how there can be blank entires though.

That's a badly un-normalised data structure.
artist_table
artist_id name birthdate favourite_color

album_table
artist_id album_id album_name other_album_data

track table
album_id track_name track_length
Thanks, but that doesn't appear to do what I need it to ... it pulls the tracks from the album too -- I want it to just show the Artist of the Album (could be Various) and then the Album title -- just once for each album, not for each track, if you follow what I mean?

I do agree it's badly formatted in the database, I'm working on tidying this lot up!

Thanks for your help,

Jason
Reply With Quote
  #4  
Old 07-15-2008, 08:54 PM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, I've moved away from that issue now, there's no point trying to do all of that as I released some albums have multiple artists.

Next issue though ....

PHP Code:
$myvar str_replace(array('+','Ad','CD','BE'), array('%','\Ad','\CD',''), urlencode($row['album'])); 
I've found some combination of letters are actually ascii hex codes for other characters -- which means if it suddenly finds the characters "Ad" it inserts a dash. I've breifly combatted this with adding a \ before it .. which seems to work, but is there an easier way of doing this? So any letter isn't taken as ascii hex?

Cheers!

Jason
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:20 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.11906 seconds
  • Memory Usage 2,193KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete