MySQL dropdown list problem. please help!

Discussion in 'MySQL' started by nQQb, Jan 21, 2008.

  1. #1
    Hi,

    I have a table with 16000 fields and curently I have a dropdown list which takes forever to load all these in the dropdown menu.

    Could someone please help me find a solution to this problem.

    is there a way I can have 500 records in menu and at top or bottom, a NEXT 500 records which would pull 500 more from that point?

    Here's the current code:

    <?php
    		function showArtists(){
    			$sql = mysql_query("SELECT id, artist FROM artists ORDER BY artist ASC");
    			echo "<select name='artist'>";
    			while(list($id, $artist)=mysql_fetch_array($sql)){
    				$artist = stripslashes($artist);
    				echo "<option value='$id'>$artist</option> \n";
    				}
    			echo "</select>";
    			}
    			
    			$message="Thank You. Your lyrics have been added to the database!";
    			
    ?>
    <body>
    	<div id="container">
        	<?php
    			if (isset($submit)){
    				$date = date("Ymd");
    				$insert_lyric_title = "INSERT INTO  `lyrics` ( `artist` ,  `title` ,  `date` ) VALUES ('$artist',  '$title',  '$date')";
    				$query= mysql_query($insert_lyric_title);
    				$track_id = mysql_insert_id();
    				$insert_lyric_text = 'INSERT INTO  `texts` ( `id` , `text`) VALUES ("'.$track_id.'", "'.mysql_real_escape_string($text).'")';
    				$query3= mysql_query($insert_lyric_text);
    				echo mysql_error();
    				echo "<div id='message'>$message</div><br /><br />";
    			}
    		?>	
    PHP:

     
    nQQb, Jan 21, 2008 IP
  2. Krnl

    Krnl Peon

    Messages:
    60
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Maybe add an alphabetical link list at the top of the page and query by artist's name i.e.

    a - b - c - d - e - f - g - etc...

    Someone clicks the "a" link, then put "a" into a variable, say $alpha - and execute the query as such:

    
    SELECT id, artist FROM artists where artist = '$alpha%' ORDER BY artist ASC
    
    Code (sql):
    There's probably a much better way to do this...this is just off the top of my head.
     
    Krnl, Jan 21, 2008 IP
  3. LinketySplit

    LinketySplit Peon

    Messages:
    97
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Alpha is probably your best bet. Otherwise you'll have to add LIMIT 50, OFFSET x to your queries, and pass their values to the record scrolling links you generate (e.g. view.php?limit=50&offset=50). Certainly doable, but alpha is quickest.
     
    LinketySplit, Jan 21, 2008 IP