I am looking for help with IF statements
Posted: Sun Sep 30, 2007 6:09 pm
I am trying to make a pge pull a list from a mysql db and display results I also have buttons to sort by the different types and I am using 4 pages with 36 records each i am using $_GET such as index.php?page=1 and so on... also the ability to list only record from a specific company such as ford chevy and what not here is the code I have
Now it doesnt seem to work and I think I am doing the if's wrong but im not sure Can someone help?
Code: Select all
<?php
mysql_connect($dbhost,$dbuser,$dbpass) or die("Unable to connect");
@mysql_select_db($dbname) or die ("Unable to select database");
if ($page = '1') {
$query="SELECT * from $tbl_listings LIMIT 0, 36";
}
else
{
}
if ($page = "2"){$query="SELECT * from $tbl_listings LIMIT 36, 72";
}
else
{
}
if ($page = "3"){$query="SELECT * from $tbl_listings LIMIT 72, 144";
}
else
{
}
if ($page = "4"){$query="SELECT * from $tbl_listings LIMIT 144, 288";
}
else
{
}
if ($company <> ""){
$query="SELECT
*
FROM
$tbl_listings
WHERE
`make`='$company'";
}
else
{
}
if ($orderby = "`year`"){$query="SELECT * from $tbl_listings ORDER BY `listings`.`year` ASC";
}
else
{
}
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$milage=mysql_result($result,$i,"milage");
$model=mysql_result($result,$i,"model");
$year=mysql_result($result,$i,"year");
$price=mysql_result($result,$i,"price");
$imgmain=mysql_result($result,$i,"imgmain");
?>
<tr>
<td width="34%" height="20" style="border-left-width: 1; border-right-width: 1; border-top-width: 1" bordercolor="#FFFFFF">
<center>
<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="50%">
<tr>
<td width="100%">
<p align="center">
<a href="http://">
<img border="0" src="<?php echo $imgmain; ?>" width="150" height="100"></a><br>
[<a style="font-family: Verdana; text-decoration: none; font-size: 8pt"href="loadcar.php?id=<?php echo $id; ?>" onClick="OpenPopup('loadcar.php')">Enlarge</a>]<br><a style="font-family: Verdana; text-decoration: none; font-size: 8pt"href="emainform.php?id="<?php echo $id; ?></a></td>
</tr>
</table>
</center>
</td>
<td width="16%" height="20" style="border-left-width: 1; border-right-width: 1; border-top-width: 1" bordercolor="#FFFFFF">
<p align="center"><?php echo $year; ?></td>
<td width="16%" height="20" style="border-left-width: 1; border-right-width: 1; border-top-width: 1" bordercolor="#FFFFFF">
<p align="center"><?php echo $model; ?></td>
<td width="17%" height="20" style="border-left-width: 1; border-right-width: 1; border-top-width: 1" bordercolor="#FFFFFF">
<p align="center"><?php echo $milage; ?></td>
<td width="17%" height="20" style="border-left-width: 1; border-right-width: 1; border-top-width: 1" bordercolor="#FFFFFF">
<p align="center">$<?php echo $price; ?></td>
</tr>
<?
$i++;
}
mysql_close(mysql_connect($dbhost,$dbuser,$dbpass));
?>