Displaying more than one value using php and mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Manoj Kumar
Forum Newbie
Posts: 8
Joined: Thu Jan 12, 2012 6:00 am

Displaying more than one value using php and mysql

Post by Manoj Kumar »

Hi all... I'm trying to display the values retrieved from a database and the result should look like
Name
Address
Profession etc., I'm able to display only one row for the duplicated records using mysql_fetch_assoc(). But i would like to display all the rows. Help me out .
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Displaying more than one value using php and mysql

Post by Celauran »

Please post the code you're using.
Manoj Kumar
Forum Newbie
Posts: 8
Joined: Thu Jan 12, 2012 6:00 am

Re: Displaying more than one value using php and mysql

Post by Manoj Kumar »

Here is the code:
$search_company = $_POST['search_company'];
$sql_co = "SELECT * from customer_tb WHERE comp_name = '$search_company'";
$rs_co = mysql_query($sql_co);
$data_co = mysql_fetch_assoc($rs_co);
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Displaying more than one value using php and mysql

Post by Celauran »

Escape your data before passing it into a query.

Code: Select all

$search_company = mysql_real_escape_string($_POST['search_company']);
$sql_co = "SELECT * from customer_tb WHERE comp_name = '$search_company'";
$rs_co = mysql_query($sql_co);
while ($row = mysql_fetch_assoc($rs_co))
{
  // do stuff here
}
Manoj Kumar
Forum Newbie
Posts: 8
Joined: Thu Jan 12, 2012 6:00 am

Re: Displaying more than one value using php and mysql

Post by Manoj Kumar »

Thanks so much. It's working fine now.
Post Reply