Hello,
i am new in php.
i want to get value from url and retrieve the info from database to other page,
please help.
here is url value
PHP Code:
http://localhost/ad_Display.php?id=1&cat=1&ut=s
where cat = category and ut = usertype
here is my code.
PHP Code:
<?php
include_once ("dbconnect.php");
$id = "";
if (isset($_GET['id'])) {
$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
}
$id = preg_replace('#[^0-9]#i', '', $id);
$sql_post = mysql_query("SELECT * FROM adpost WHERE id='$id' LIMIT 1");
while($row = mysql_fetch_array($sql_post)){
$postid = $row["id"];
$category = $row["category"];
$usertype = $row["usertype"];
$adtitle = $row["adtitle"];
$cond = $row["cond"];
$price = $row["price"];
$stype = $row["stype"];;
$sloc = $row["sloc"];
$sarea = $row["sarea"];
$slandmark = $row["slandmark"];
$postdate = $row["postdate"];
$convertedTime = ($myObject -> convert_datetime($postdate));
$whenPost = ($myObject -> makeAgo($convertedTime));
}
if (isset($_GET['category'])) {
$category = $_GET['category'];
}
if (isset($_GET['usertype'])) {
$usertype = $_GET['usertype'];
}
$sql = mysql_query("SELECT * FROM adpost WHERE category='$category' AND usertype='s' ORDER BY postdate DESC LIMIT 5" );
$adDisplayList = "";
$numRows = mysql_num_rows($sql);
if ($numRows < 1) {
$adDisplayList = "There are no Ad in this Category yet. You can be the first to post.";
} else {
$adDisplayList .= '<a href="http://p2p.wrox.com/ad_Display.php?id=' . $postid . '&cat=' . $category . '&ut=' . $usertype . '"><div id="adlist" onmouseover="this.style.background=\'#555\';" onmouseout="this.style.background=\'#333\';">
<table width="100%" height="100%" border="0">
<tr>
<td width="18%" rowspan="3" valign="middle"><div style="width: 95px; height: 90px; padding-left:5px;"><img src="http://p2p.wrox.com/images/photo_not_available_small.jpg" width="100" height="90" /></div></td>
<td height="39" colspan="3" valign="top"><p>
<div style="padding-left:10px;"><font class="fontsz1" color="#C93"><strong> ' . $adtitle. '</strong></font> - ' . $cond . '</div></td>
</tr>
<tr>
<td height="24" colspan="3"> <font class="fontsz" color="#999"> ' . $sloc. ' | ' . $sarea. ' | ' . $slandmark . ' </font></td>
</tr>
<tr>
<td width="32%" height="24"><div id="prctab"> ' . $price . ' </div></td>
<td width="25%"> <font class="fontsz" color="#999"> ' . $whenPost . ' </font></td>
<td width="25%"> <font class="fontsz" color="#999"> ' . $stype . ' </font></td>
</tr>
</table>
</div></a>';
}
?>
I want to display all ad using category and user type. but getting error undefined index: category & usertype
plz help.
thanks