Jump to content
xisto Community
Sign in to follow this  
kakingho

How To Read Specific Row From Table according where no=xx

Recommended Posts

For example...a table have 2 columns, 100 rowsfor column i.e. no, nameI want to get corresponding name when no=17How to write this php coding??

Share this post


Link to post
Share on other sites

Not too hard:

 

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:

$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:

$query = mysql_query("SELECT * FROM table ORDER BY number DESC");
the above code would order the list by number descending

 

* To do both:

$query = mysql_query("SELECT * FROM table ORDER BY number DESC LIMIT 10");

any questions ill gladly answer

Share this post


Link to post
Share on other sites

Not too hard:

 

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:

$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:

$query = mysql_query("SELECT * FROM table ORDER BY number DESC");
the above code would order the list by number descending

 

* To do both:

$query = mysql_query("SELECT * FROM table ORDER BY number DESC LIMIT 10");

any questions ill gladly answer

215958[/snapback]

Your method is good to deal with large data.

Are there any other easy methods to show only 1 record with corresponding no. easily?

Share this post


Link to post
Share on other sites

Try this code. It might help.

$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];}

Share this post


Link to post
Share on other sites

Try this code.  It might help.

 

$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];}

216091[/snapback]


thx a lot :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.