Make a Listview with different criterias

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mollet
Forum Newbie
Posts: 1
Joined: Tue Sep 25, 2007 4:53 am

Make a Listview with different criterias

Post by mollet »

Hello,

iam verynew to php, have some skills in vb and c# so php seems familiar to c# for me.
i would make a listview result for announces. For example car selling announces, you put in which car, wich color, transmission and so on,
then the code make a querry and the viewing of the results should be seltctable, by last entry, by price, should there be 5 / 10 or 20 on every site and if 5 and there are more then five then split into 2 sites.

Thank you very much

Mollet
PS: I only need the part to list the results on different pages if there are more then for example 5 results.
page 1 | 2 | 3 | 4 |
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

By "site" i guess you mean page yes?

Depending on the criteria you want to use in your query the typical structure is:

1. Connect to you database

Code: Select all

$dbLink=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database_name");
2. Setup your query

Code: Select all

$query="SELECT fields FROM table WHERE conditions";
If you are using $variables in your WHERE clause then you will want to enter them as:

Code: Select all

WHERE field_name1='$variable' AND field_name2='$variable2'
3. Execute your query

Code: Select all

$result=mysql_query($query,$dbLink);
4. Fetch results

You will want to use a loop so you could use:

Code: Select all

while($row=mysql_fetch_array($result))
{
      echo $row['field_name'];      //THIS WILL OUTPUT THE VALUE FROM THIS FIELD 
}
This is a very basic query but should give you some insight.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

You may also want to try a search on these forums for pagination. Results should give you examples on how to perform a query and paginate the results.
Post Reply