Λίστα μελών

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
Threshold
Δημοσιεύσεις: 48
Εγγραφή: 02 Μαρ 2009 22:16
Επικοινωνία:

Λίστα μελών

Δημοσίευση από Threshold » 29 Απρ 2009 12:48

Λοιπόν έχω φτιάξει ένα script το οποίο διαβάζει τους χρήστες από μια βάση και τους κατηγοριοποιεί ανάλογως με το αρχικό γράμμα του username. Βέβαια το έχω κάνει κάπως μπακαλίστικα και θέλω να το διορθώσω λίγο. Καμία ιδέα για το τι μπορώ να κάνω;

Κώδικας: Επιλογή όλων

<?php
require_once &#40;"db.php"&#41;;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http&#58;//www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http&#58;//www.w3.org/1999/xhtml" xml&#58;lang="en" lang="en">

<head>

<title>Members List</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>

	<h1>Members List</h1>

	<h2>A</h2>

	<?php

		$query = "SELECT userid, username FROM user WHERE username LIKE 'A%'";
		$rs = mysql_query&#40;$query&#41; or die&#40;"Cannot execute query <br/>" . $query&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result = mysql_fetch_array&#40;$rs, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result&#91;'userid'&#93; . "'>" . $result&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>B</h2>
	
	<?php

		$query1 = "SELECT userid, username FROM user WHERE username LIKE 'B%'";
		$rs1 = mysql_query&#40;$query1&#41; or die&#40;"Cannot execute query <br/>" . $query1&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result1 = mysql_fetch_array&#40;$rs1, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result1&#91;'userid'&#93; . "'>" . $result1&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result1&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>C</h2>
	
	<?php

		$query2 = "SELECT userid, username FROM user WHERE username LIKE 'C%'";
		$rs2 = mysql_query&#40;$query2&#41; or die&#40;"Cannot execute query <br/>" . $query2&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result2 = mysql_fetch_array&#40;$rs2, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result2&#91;'userid'&#93; . "'>" . $result2&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result2&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>D</h2>
	
	<?php

		$query3 = "SELECT userid, username FROM user WHERE username LIKE 'D%'";
		$rs3 = mysql_query&#40;$query3&#41; or die&#40;"Cannot execute query <br/>" . $query3&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result3 = mysql_fetch_array&#40;$rs3, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result3&#91;'userid'&#93; . "'>" . $result3&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result3&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>E</h2>
	
	<?php

		$query4 = "SELECT userid, username FROM user WHERE username LIKE 'E%'";
		$rs4 = mysql_query&#40;$query4&#41; or die&#40;"Cannot execute query <br/>" . $query4&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result4 = mysql_fetch_array&#40;$rs4, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result4&#91;'userid'&#93; . "'>" . $result4&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result4&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>F</h2>
	
	<?php

		$query5 = "SELECT userid, username FROM user WHERE username LIKE 'F%'";
		$rs5 = mysql_query&#40;$query5&#41; or die&#40;"Cannot execute query <br/>" . $query5&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result5 = mysql_fetch_array&#40;$rs5, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result5&#91;'userid'&#93; . "'>" . $result5&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result5&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>G</h2>
	
	<?php

		$query6 = "SELECT userid, username FROM user WHERE username LIKE 'G%'";
		$rs6 = mysql_query&#40;$query6&#41; or die&#40;"Cannot execute query <br/>" . $query6&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result6 = mysql_fetch_array&#40;$rs6, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result6&#91;'userid'&#93; . "'>" . $result6&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result6&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>H</h2>
	
	<?php

		$query7 = "SELECT userid, username FROM user WHERE username LIKE 'H%'";
		$rs7 = mysql_query&#40;$query7&#41; or die&#40;"Cannot execute query <br/>" . $query7&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result7 = mysql_fetch_array&#40;$rs7, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result7&#91;'userid'&#93; . "'>" . $result7&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result7&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>I</h2>
	
	<?php

		$query8 = "SELECT userid, username FROM user WHERE username LIKE 'I%'";
		$rs8 = mysql_query&#40;$query8&#41; or die&#40;"Cannot execute query <br/>" . $query8&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result8 = mysql_fetch_array&#40;$rs8, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result8&#91;'userid'&#93; . "'>" . $result8&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result8&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>J</h2>
	
	<?php

		$query9 = "SELECT userid, username FROM user WHERE username LIKE 'J%'";	
		$rs9 = mysql_query&#40;$query9&#41; or die&#40;"Cannot execute query <br/>" . $query9&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result9 = mysql_fetch_array&#40;$rs9, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result9&#91;'userid'&#93; . "'>" . $result9&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result9&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>K</h2>
	
	<?php

		$query10 = "SELECT userid, username FROM user WHERE username LIKE 'K%'";
		$rs10 = mysql_query&#40;$query10&#41; or die&#40;"Cannot execute query <br/>" . $query10&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result10 = mysql_fetch_array&#40;$rs10, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result10&#91;'userid'&#93; . "'>" . $result10&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result10&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>L</h2>
	
	<?php

		$query11 = "SELECT userid, username FROM user WHERE username LIKE 'L%'";
		$rs11 = mysql_query&#40;$query11&#41; or die&#40;"Cannot execute query <br/>" . $query11&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result11 = mysql_fetch_array&#40;$rs11, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result11&#91;'userid'&#93; . "'>" . $result11&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result11&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>M</h2>

	<?php

		$query12 = "SELECT userid, username FROM user WHERE username LIKE 'M%'";
		$rs12 = mysql_query&#40;$query12&#41; or die&#40;"Cannot execute query <br/>" . $query12&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result12 = mysql_fetch_array&#40;$rs12, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result12&#91;'userid'&#93; . "'>" . $result12&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result12&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	<h2>N</h2>
	
	<?php

		$query13 = "SELECT userid, username FROM user WHERE username LIKE 'N%'";		
		$rs13 = mysql_query&#40;$query13&#41; or die&#40;"Cannot execute query <br/>" . $query13&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result13 = mysql_fetch_array&#40;$rs13, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result13&#91;'userid'&#93; . "'>" . $result13&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result13&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>O</h2>
	
	<?php

		$query14 = "SELECT userid, username FROM user WHERE username LIKE 'O%'";		
		$rs14 = mysql_query&#40;$query14&#41; or die&#40;"Cannot execute query <br/>" . $query14&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result14 = mysql_fetch_array&#40;$rs14, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result14&#91;'userid'&#93; . "'>" . $result14&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result14&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>P</h2>
	
	<?php

		$query15 = "SELECT userid, username FROM user WHERE username LIKE 'P%'";		
		$rs15 = mysql_query&#40;$query15&#41; or die&#40;"Cannot execute query <br/>" . $query15&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result15 = mysql_fetch_array&#40;$rs15, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result15&#91;'userid'&#93; . "'>" . $result15&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result15&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>Q</h2>
	
	<?php

		$query16 = "SELECT userid, username FROM user WHERE username LIKE 'Q%'";	
		$rs16 = mysql_query&#40;$query16&#41; or die&#40;"Cannot execute query <br/>" . $query16&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result16 = mysql_fetch_array&#40;$rs16, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result16&#91;'userid'&#93; . "'>" . $result16&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result16&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>R</h2>
	
	<?php

		$query17 = "SELECT userid, username FROM user WHERE username LIKE 'R%'";
		$rs17 = mysql_query&#40;$query17&#41; or die&#40;"Cannot execute query <br/>" . $query17&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result17 = mysql_fetch_array&#40;$rs17, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result17&#91;'userid'&#93; . "'>" . $result17&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result17&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>S</h2>
	
	<?php

		$query18 = "SELECT userid, username FROM user WHERE username LIKE 'S%'";	
		$rs18 = mysql_query&#40;$query18&#41; or die&#40;"Cannot execute query <br/>" . $query18&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result18 = mysql_fetch_array&#40;$rs18, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result18&#91;'userid'&#93; . "'>" . $result18&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result18&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>T</h2>
	
	<?php

		$query19 = "SELECT userid, username FROM user WHERE username LIKE 'T%'";	
		$rs19 = mysql_query&#40;$query19&#41; or die&#40;"Cannot execute query <br/>" . $query19&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result19 = mysql_fetch_array&#40;$rs19, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result19&#91;'userid'&#93; . "'>" . $result19&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result19&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>U</h2>
	
	<?php

		$query20 = "SELECT userid, username FROM user WHERE username LIKE 'U%'";	
		$rs20 = mysql_query&#40;$query20&#41; or die&#40;"Cannot execute query <br/>" . $query20&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result20 = mysql_fetch_array&#40;$rs20, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result20&#91;'userid'&#93; . "'>" . $result20&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result20&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>V</h2>

	<?php

		$query21 = "SELECT userid, username FROM user WHERE username LIKE 'V%'";	
		$rs21 = mysql_query&#40;$query21&#41; or die&#40;"Cannot execute query <br/>" . $query21&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result21 = mysql_fetch_array&#40;$rs21, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result21&#91;'userid'&#93; . "'>" . $result21&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result21&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>W</h2>
	
	<?php

		$query22 = "SELECT userid, username FROM user WHERE username LIKE 'W%'";	
		$rs22 = mysql_query&#40;$query22&#41; or die&#40;"Cannot execute query <br/>" . $query22&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result22 = mysql_fetch_array&#40;$rs22, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result22&#91;'userid'&#93; . "'>" . $result22&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result22&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>X</h2>
	
	<?php

		$query23 = "SELECT userid, username FROM user WHERE username LIKE 'X%'";	
		$rs23 = mysql_query&#40;$query23&#41; or die&#40;"Cannot execute query <br/>" . $query23&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result23 = mysql_fetch_array&#40;$rs23, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result23&#91;'userid'&#93; . "'>" . $result23&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result23&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>Y</h2>
	
	<?php

		$query24 = "SELECT userid, username FROM user WHERE username LIKE 'Y%'";	
		$rs24 = mysql_query&#40;$query24&#41; or die&#40;"Cannot execute query <br/>" . $query24&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result24 = mysql_fetch_array&#40;$rs24, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result24&#91;'userid'&#93; . "'>" . $result24&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result24&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	
	<h2>Z</h2>
	
	<?php

		$query25 = "SELECT userid, username FROM user WHERE username LIKE 'Z%'";	
		$rs25 = mysql_query&#40;$query25&#41; or die&#40;"Cannot execute query <br/>" . $query25&#41;;
		
		echo "<table border ='1'>";
		
			echo "<tr>\n";
			
				echo "<td><h3>User ID</h3></td>\n";
				echo "<td><h3>Username</h3></td>\n";
				
			echo "</tr>\n";
		
		while&#40;$result25 = mysql_fetch_array&#40;$rs25, MYSQL_ASSOC&#41;&#41;&#123;
		
			echo "<tr>\n";
			
				echo "<td><a href='profile.php?PID=" . $result25&#91;'userid'&#93; . "'>" . $result25&#91;'userid'&#93; . "</a></td>\n";
				echo "<td>" . $result25&#91;'username'&#93; . "</td>\n";
				
			echo "</tr>\n";
			
		&#125;
		
		echo "</table>";
		
	?>
	

</body>

</html>

Άβαταρ μέλους
ThyClub
Honorary Member
Δημοσιεύσεις: 5312
Εγγραφή: 17 Νοέμ 2003 00:21
Τοποθεσία: Hell's Kitchen
Επικοινωνία:

Λίστα μελών

Δημοσίευση από ThyClub » 29 Απρ 2009 13:38

OMG :o

26 queries ...
σβήσε όλα εκτός απο το πρώτο και κάντο:

Κώδικας: Επιλογή όλων

$query = "SELECT userid, username FROM user ORDER BY `username` ASC";

Threshold
Δημοσιεύσεις: 48
Εγγραφή: 02 Μαρ 2009 22:16
Επικοινωνία:

Λίστα μελών

Δημοσίευση από Threshold » 29 Απρ 2009 13:50

Χαχαχα, ναι μου βγήκαν τα μάτια για να κάνω σωστά copy paste :p

Thanks, δουλεύει τζιτζί!!

Άβαταρ μέλους
Banavas
Script Master
Δημοσιεύσεις: 1367
Εγγραφή: 21 Νοέμ 2004 20:25
Επικοινωνία:

Λίστα μελών

Δημοσίευση από Banavas » 29 Απρ 2009 16:25

Για να πας ένα βήμα παραπέρα και να μοιάζει η απεικόνιση με αυτήν που είχες με το script σου με τα 26 queries διάβαζε το πρώτο γράμμα του ονόματος και αποθήκευσέ το στην μεταβλητή $first_letter.

Κώδικας: Επιλογή όλων

$first_letter=$substr&#40;$result&#91;'username'&#93;,0,1&#41;;
Mέσα στο loop του while βάλε ένα έλεγχο αν το όνομα που διαβάζει εκείνη τη στιγμή είναι ίδιο με το προηγούμενο, αν είναι ίδιο το εκτυπώνει στη λίστα και προχωράει στο επόμενο.
Αν είναι διαφορετικό τότε αλλάζεις την διαδικασία εκτύπωσης και τυπώνει πρώτα μια επικεφαλίδα και στη συνέχεια το όνομα.

Κώδικας: Επιλογή όλων

while.............

if &#40;$substr&#40;$result&#91;'username'&#93;,0,1&#41; == $first_letter&#41; &#123;
echo $result&#91;'username'&#93;;
&#125;else&#123;
echo "<br><h1>". substr&#40;$result&#91;'username'&#93;,0,1&#41;."</h1><br>". $result&#91;'username'&#93;;
&#125;
$first_letter=$substr&#40;$result&#91;'username'&#93;,0,1&#41;;
&#125; //end while
Έτσι με αυτό τον τρόπο θα έχεις τα ονόματα χωρισμένα σε ομάδες με επικεφαλίδες το αρχικό γράμμα της ομάδας. Και επιπλέον δεν θα υπάρχουν επικεφαλίδες για γράμματα που δεν έχουν ονόματα όπως στο δικό σου παράδειγμα.
Happy coding....
Μάρκος
http://lasernet.gr

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες