Question

I have two pages. in one page i get data from database and show the product's name, address and etc. and each one of products have a button, show details. when button clicked it should redirect to another page for example 2.php and grab the selected row's product id and send it to another page and show details of products there. I want to use query string but when I click at more details at each row, it only shows the last row's details. I searched a lot but could not solve the problem. here is my code:

 echo '<form id="formsell" method="post" action="2.php?fid='.$_POST['fid'].'>';
  $r=mysql_query("select melk.melk_id,melk.melktype,melk.city,melk.khiaban,melk.area,melk.darjdate
 ,villa.room_count,villa.floor_count,villa.floor_number, foroosh.price from melk
 inner join villa on melk.melk_id=villa.melkid inner join foroosh on villa.melkid=foroosh.melkid where contracttypeid='1' and melktypeid='1' ");
 echo mysql_error();
 echo "<div class='items'>";

while($row=mysql_fetch_array($r))
{ 
echo "<div class='itemcont'>
<div class='m_sum'>
<div style='width:180px; height:auto; overflow:hidden; text-align:center; direction:rtl; float:right;'>
<h1 class='redtitr'>$row[city]   $row[khiaban]</h1>
  مساحت:  <span class='text'>$row[area]</span>  متر   <br/>
تعداد اتاق:  <span class='text'>$row[room_count]</span>";
echo "<input type='hidden' name='fid' id='$row[melk_id]' value='$row[khiaban]' />
 <span style='color:#0054a0; margin:6px auto; padding-top:10px; font-size:16px; text-align:center; background:url(../img/pdGreyDivider.jpg) repeat-x left top; font-weight:bold; display:block;'>";
 echo hyphenate($row[price]);
 echo "
 </span><span class='text'>تومان</span>
</div>

<input type='submit' value='جزئیات بیشتر' name='sdetail' id='sdetail'/>
  }


 if (isset($_POST['sdetail']))
   {
    $_POST['fid'];
   }

and in 2.php and I will show details with the id:

<?php 
echo $_GET['fid'];
?>
Was it helpful?

Solution

I am giving you just an example to use this process. Code for show all products.

$query=mysql_query("select * from main ");
while($row=mysql_fetch_assoc($query)){
echo $row['uname'];
$idd=$row['id'];
echo '<a href="show.php?id='.$idd.'">show detail</a>';
}

Code for show.php

<?php echo $_GET['id']; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top