|
|
|
|
![]() ![]() |
Dec 26 2005, 03:46 PM
Post
#1
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 52 Joined: 17-July 05 From: hong kong Member No.: 9,520 |
For example...
a table have 2 columns, 100 rows for column i.e. no, name I want to get corresponding name when no=17 How to write this php coding?? |
|
|
|
Dec 26 2005, 04:02 PM
Post
#2
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 62 Joined: 22-December 05 From: Sandefjord,Norway Member No.: 16,078 |
An idea could be to Click Here: http://php.about.com/library/bl-addtut03.htm
There you find a tutorial about that, just rewrite a little on that script and it will problety work, Hope i Helped ~ Arne-Christian |
|
|
|
Dec 27 2005, 12:46 AM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 362 Joined: 2-March 05 From: The Netherlands Member No.: 4,097 |
Not too hard:
CODE print "<tr><td>Column 1</td><td>Column 2</td></tr>"; $query = mysql_query("SELECT * FROM table"); while($getArray = mysql_fetch_array($query)){ print "<tr><td>$getArray[number]</td><td>$getArray[name]</td></tr>";} Note that while{} is an ongoing loop, it will load any number of records wich will display a full list* of each record, showing number and the name attached to it. * To limit the number of results change the query by: CODE $query = mysql_query("SELECT * FROM table LIMIT 10 the above code would limit the number of results (rows) to 10 * To order the number of results change the query by: CODE $query = mysql_query("SELECT * FROM table ORDER BY number DESC"); the above code would order the list by number descending * To do both: CODE $query = mysql_query("SELECT * FROM table ORDER BY number DESC LIMIT 10"); any questions ill gladly answer |
|
|
|
Dec 27 2005, 03:15 PM
Post
#4
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 52 Joined: 17-July 05 From: hong kong Member No.: 9,520 |
QUOTE(HmmZ @ Dec 27 2005, 08:46 AM) Not too hard: CODE print "<tr><td>Column 1</td><td>Column 2</td></tr>"; $query = mysql_query("SELECT * FROM table"); while($getArray = mysql_fetch_array($query)){ print "<tr><td>$getArray[number]</td><td>$getArray[name]</td></tr>";} Note that while{} is an ongoing loop, it will load any number of records wich will display a full list* of each record, showing number and the name attached to it. * To limit the number of results change the query by: CODE $query = mysql_query("SELECT * FROM table LIMIT 10 the above code would limit the number of results (rows) to 10 * To order the number of results change the query by: CODE $query = mysql_query("SELECT * FROM table ORDER BY number DESC"); the above code would order the list by number descending * To do both: CODE $query = mysql_query("SELECT * FROM table ORDER BY number DESC LIMIT 10"); any questions ill gladly answer Your method is good to deal with large data. Are there any other easy methods to show only 1 record with corresponding no. easily? |
|
|
|
Dec 27 2005, 03:39 PM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 436 Joined: 21-January 05 From: Koronadal City, Philippines Member No.: 3,358 |
Try this code. It might help.
CODE $db = mysql_connect ("localhost", "username", "password");
mysql_select_db ("database_name"); $query=mysql_query("SELECT field1,field2 FROM table WHEN no=17"); while($row=mysql_fetch_row($query)){ echo $row[0].'<br>'.$row[1]; } |
|
|
|
Dec 29 2005, 04:31 PM
Post
#6
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 52 Joined: 17-July 05 From: hong kong Member No.: 9,520 |
QUOTE(leiaah @ Dec 27 2005, 11:39 PM) Try this code. It might help. CODE $db = mysql_connect ("localhost", "username", "password"); mysql_select_db ("database_name"); $query=mysql_query("SELECT field1,field2 FROM table WHEN no=17"); while($row=mysql_fetch_row($query)){ echo $row[0].'<br>'.$row[1]; } thx a lot |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 8th October 2008 - 05:41 AM |