Page 1 of 1

Displaying more than one value using php and mysql

Posted: Mon Jan 30, 2012 9:53 am
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 .

Re: Displaying more than one value using php and mysql

Posted: Mon Jan 30, 2012 10:24 am
by Celauran
Please post the code you're using.

Re: Displaying more than one value using php and mysql

Posted: Mon Jan 30, 2012 10:36 am
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);

Re: Displaying more than one value using php and mysql

Posted: Mon Jan 30, 2012 10:40 am
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
}

Re: Displaying more than one value using php and mysql

Posted: Mon Jan 30, 2012 10:55 am
by Manoj Kumar
Thanks so much. It's working fine now.