Page 1 of 1

multiple viewing of mysql data

Posted: Wed Jan 18, 2006 5:27 am
by cooper3000
I have a business directory in the making. I am having problems with displaying the results.

When a query is executed I can return the basic details I have asked for, however I wish for a few extras to be viewable.

I have 2 database entry types:
- Basic Entry
- Advanced entry

All of there details are stored in the same table with one column titled 'paid'. If the business is an advanced entry the row will state 'paid', if they are a basic entry it will state 'unpaid'.

All good so far....

So, when the query is executed I firstly want to display the following details for advanced listing:

Business Name
Address
Telephone
Fax
Email
Website
Features
Category

and then followed by the basic entry details:

Business Name
Address
Telephone
Category

In regards to the order, that is easy enough, but how do i display the 2 separate results together. i have managed to get it to work and be able to view one or the other but not together.

Can anyone help?

Cooper

Posted: Wed Jan 18, 2006 5:40 am
by raghavan20
The problem is clear but how do you want to display...
some thing like...
advanced listings:
Business Name Address Telephone Fax Email Website Features Category
1st record
2nd record
and so on...

normal listings:
Business Name Address Telephone Category
1st record
2nd record
and so on...

else you want something like this...
Business Name Address Telephone Fax Email Website Features Category
advanced entry has all these fields filled
normal entry has null in email, website and features fields
here is the code...

Code: Select all

$query = "select * from table_name";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
	if (result["paid"] == "paid"){
		echo "$result['businessname']\t $result['Address']\t $result['Telephone']\t $result['Fax']\t $result['Email']\t $result['Website']\t $result['Features']\t $result['Category']";
	}else{
echo "$result['businessname']\t $result['Address']\t $result['Telephone']\t \t \t \t \t \t \t \t \t $result['Category']";
	}	
}

Posted: Wed Jan 18, 2006 5:44 am
by cooper3000
i would prefer the first way you mentioned, rather than having empty fields (I would rather they were not displayed.)

Cheers

Cooper

Posted: Wed Jan 18, 2006 6:14 am
by raghavan20
you have to consider pagination for this model...

Code: Select all

$query = "select * from table_name";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
	if (result["paid"] == "paid"){
		echo "$result['businessname']\t $result['Address']\t $result['Telephone']\t $result['Fax']\t $result['Email']\t $result['Website']\t $result['Features']\t $result['Category']";
}

mysql_data_seek($result, 0);
while($row = mysql_fetch_assoc($result)){
	if (result["paid"] != "paid"){
echo "$result['businessname']\t $result['Address']\t $result['Telephone'] \t $result['Category']";
	}	
}

Posted: Wed Jan 18, 2006 6:49 am
by cooper3000
This has worked except for one thing, the first result shows the full details for only the first advanced listing, and everything else as basic entry?

Any ideas why that may be? I have followed your example exactly except for adding an extra } at the end.

Cheers

Cooper :oops:

Posted: Wed Jan 18, 2006 9:04 am
by cooper3000
I have done it:

while($row = mysql_fetch_assoc($result)){
if (result["paid"] == "paid"){
echo "$result['businessname']\t $result['Address']\t $result['Telephone']\t $result['Fax']\t $result['Email']\t $result['Website']\t $result['Features']\t $result['Category']";
}
}

mysql_data_seek($result, 0);
while($row = mysql_fetch_assoc($result)){
if (result["paid"] != "paid"){
echo "$result['businessname']\t $result['Address']\t $result['Telephone'] \t $result['Category']";
}
}

All i did was add the '}' in bold (bold to show you which one).

Thanks very much for all your help

Cooper