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 .
Displaying more than one value using php and mysql
Moderator: General Moderators
-
Manoj Kumar
- Forum Newbie
- Posts: 8
- Joined: Thu Jan 12, 2012 6:00 am
Re: Displaying more than one value using php and mysql
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
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);
$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
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
Thanks so much. It's working fine now.