Page 1 of 1

Make a Listview with different criterias

Posted: Tue Sep 25, 2007 5:02 am
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 |

Posted: Tue Sep 25, 2007 5:20 am
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.

Posted: Tue Sep 25, 2007 6:20 am
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.