glennn.php Posted April 20, 2006 Share Posted April 20, 2006 kind people, i'm attempting to print results of a mysql query into alphabetized groups - i can get the results, but i can't figure out how to separate them and sort them... can someone help?from this:[code]$sql = "SELECT `customer`.`username` , `customer`.`homepage` FROM customerORDER BY `customer`.`username` ASC , `customer`.`homepage` ASC";$result = mysql_query($sql) or die("Query failed");$row = mysql_fetch_array($result); // change to suit your needs print "${row[0]} - ${row[1]}";[code]obviously i'm only getting the first record's results... i need to get all the records as their added to the db...what i'd like to be able to do is print 26 groups according username...can someone show me how to get these results into some kind of array, and then printed, or whatever i need to do?thanksglennn Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 20, 2006 Share Posted April 20, 2006 print_r($nameofyourarray);this will print out all the array information for you to see, to make it to where you can read it better you can do.<pre><?phpprint_r($nameofyourarray);?></pre>hope this helps. Quote Link to comment Share on other sites More sharing options...
Darkness Soul Posted April 20, 2006 Share Posted April 20, 2006 Try the code now.. like it:[code]$sql = "SELECT username , homepage FROM customer ORDER BY username , homepage";$result = mysql_query($sql , $conn) or die(print "Query failed: ". mysql_error() );$lines = mysql_num_rows ( $result );for ( $i=0;$i<$lines;$i++ ){ $row = mysql_fetch_array($result); print "${row[0]} - ${row[1]} <br>";}[/code]If wont work, let's see what we can do.D.Soul Quote Link to comment Share on other sites More sharing options...
Barand Posted April 20, 2006 Share Posted April 20, 2006 try[code]$sql = "SELECT username, homepage FROM customer ORDER BY username, homepage";$result = mysql_query($sql) or die("Query failed" . mysql_error());$letter = '';while (list ($user, $page) = mysql_fetch_row($result)) { $initial = strtoupper($user{0}); if ($initial != $letter) { echo "<br><b>$initial</b><br>"; $letter = $initial; } echo "$user $page <br>";}[/code] Quote Link to comment Share on other sites More sharing options...
glennn.php Posted April 20, 2006 Author Share Posted April 20, 2006 thanks, you guys, that did it... Quote Link to comment Share on other sites More sharing options...
glennn.php Posted April 20, 2006 Author Share Posted April 20, 2006 [!--quoteo(post=366982:date=Apr 20 2006, 03:57 PM:name=Darkness Soul)--][div class=\'quotetop\']QUOTE(Darkness Soul @ Apr 20 2006, 03:57 PM) [snapback]366982[/snapback][/div][div class=\'quotemain\'][!--quotec--]Try the code now.. like it:[code]$sql = "SELECT username , homepage FROM customer ORDER BY username , homepage";$result = mysql_query($sql , $conn) or die(print "Query failed: ". mysql_error() );$lines = mysql_num_rows ( $result );for ( $i=0;$i<$lines;$i++ ){ $row = mysql_fetch_array($result); print "${row[0]} - ${row[1]} <br>";}[/code]If wont work, let's see what we can do.D.Soul[/quote]both of these worked, and Barand even broke it up for me, like i need - i really need to put each into a separate table cell - i'd like to get each query by alphabet letter - i've tried "select u,h from customer WHERE username LIKE 'a';" but it returned nothing. how can i properly get each letter separately? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 20, 2006 Share Posted April 20, 2006 I don't currently know databasing yet, I am working on it though. Quote Link to comment Share on other sites More sharing options...
glennn.php Posted April 20, 2006 Author Share Posted April 20, 2006 [!--quoteo(post=367009:date=Apr 20 2006, 05:39 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 20 2006, 05:39 PM) [snapback]367009[/snapback][/div][div class=\'quotemain\'][!--quotec--]I don't currently know databasing yet, I am working on it though.[/quote]this is what worked:select u,h from customer where username LIKE 'A%'; versus what i DID have, " ...LIKE 'A'; " Quote Link to comment 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.