hi,
i'm a newbie programmer and i just built a website with a poll. the page is completely in html and linked to the php script processing the poll result in the action attribute of the form tag. my problem is the results of the poll comes up in a new page but i need the results of the poll to appear just under the poll itself on the same page. can anybody help me with that?

ei.. if you want you're result on the same page use:

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];"></form>

then you're php code for the result on the top of you're html..
hope this help :)

enim

i thought about this option, but that would mean i have to put the php and html code on the same page, right? is there any way i could do this without putting the php and html codes on the page?

like:

<?php
//index.php
<form action="otherPage.php" method="post"><form>
?>

<?php
//otherPage.php
if($result)
{
// use meta tag here or header("Location: index.php");
}
?>

is that what you mean.. processing from other page

enim

yes this is exactly what i mean. the problem is that when i code this way, the result of the poll does not appear right underneath the poll questions but instaed on a different page. do you have any suggestions as to how i could solve this problem


like:

<?php
//index.php
<form action="otherPage.php" method="post"><form>
?>

<?php
//otherPage.php
if($result)
{
// use meta tag here or header("Location: index.php");
}
?>

is that what you mean.. processing from other page

enim

$dbh=mysql_connect ("localhost", "user", "pwd") or die('Cannot connect to the database because: ' . mysql_error());

mysql_select_db ("dbname"); 
// display records page wise code starts:

$adjacents = 3;
$tbl_name="feedback";

$display = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($display));
$total_pages = $total_pages[num];

/* Setup vars for query. */

$targetpage = "dispfeed.php"; 	//your file name  (the name of this file)
$limit = 5; 			//how many items to show per page
$page = $_GET['page'];

if($page) 
	$start = ($page - 1) * $limit; //first item to display on this page
else
	$start = 0;		//if no page var is given, set start to 0


/* Get data. */

$display = "SELECT * FROM $tbl_name order by id desc LIMIT $start, $limit";
$rs = mysql_query($display);
	
/* Setup page vars for display. */

if ($page == 0) $page = 1;		//if no page var is given, default to 1.
$prev = $page - 1;			//previous page is page - 1
$next = $page + 1;			//next page is page + 1
$lastpage = ceil($total_pages/$limit);	//lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;		//last page minus 1
	
/* 
Now we apply our rules and draw the pagination object. 
We're actually saving the code to a variable in case we want to draw it more than once.
*/

$pagination = "";
if($lastpage > 1)
{	
	$pagination .= "<div class=\"pagination\">";

	//previous button
	if ($page > 1) 
//		$pagination.= "<a href=\"$targetpage?page=$prev\">? previous</a>"; (if display by asc...)
		$pagination.= "<a href=\"$targetpage?page=$prev\">? NEXT</a>";
	else
//		$pagination.= "<span class=\"disabled\">? previous</span>"; (if display by asc...)
		$pagination.= "<span class=\"disabled\">? NEXT</span>";	

	//pages

	if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
	{	
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page)
				$pagination.= "<span class=\"current\">$counter</span>";
			else
				$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
		}
	}

	elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
	{
		//close to beginning; only hide later pages
		if($page < 1 + ($adjacents * 2))		
		{
			for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
		}
		//in middle; hide some front and some back

		elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
		}
		//close to end; only hide early pages
		else
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
			}
		}
	}
		
	//next button
	if ($page < $counter - 1) 
//		$pagination.= "<a href=\"$targetpage?page=$next\">next ?</a>"; (if display by asc...)
		$pagination.= "<a href=\"$targetpage?page=$next\">PREV ?</a>";
	else
//		$pagination.= "<span class=\"disabled\">next ?</span>"; (if display by asc...)
		$pagination.= "<span class=\"disabled\">PREV ?</span>";

	$pagination.= "</div>\n";		
}

// display records page wise code ends:

if (mysql_num_rows($rs)>0)
{
	while($row=mysql_fetch_array($rs))
	{
	?>
</p>
</p>
<table width = "62%" height="164"  border="1" align="center" cellpadding="1" cellspacing="1">
	<tr>
		<td width="10%" height="23"  valign="top" bgcolor="#0099FF" class="style27"><span class="style22"> Id. </span></td>
		<td colspan="4"  valign="top" class="style27"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[0];?></span></div></td>


	<td width="26%" rowspan="9" align="center" valign="middle">
	<!-- <a href = "<?php echo $row[9];?>"> -->
<img src = "<?php echo $row[9];?>"  width="125" height="125" border=0 />
	</a>
	</td>
	</tr>
	<tr class="style27">
		<td height="23" valign="top" bgcolor="#0099FF" class="style18"><span class="style28"> Name </span></td>
		<td colspan="4" valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[1];?></span></div></td>
	</tr>
	<tr class="style27">
		<td height="23" valign="top" bgcolor="#0099FF" class="style18"><span class="style28"> Email </span></td>
		<td colspan="4" valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><a href = "mailto:<?php echo $row[2];?>"><?php echo $row[2];?></a></span></div></td>
	</tr>
	<tr class="style27"><td height="23" valign="top" bgcolor="#0099FF" class="style18"><span class="style28">Gender </span></td>
	  <td colspan="4" valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[3];?></span></div></td>
    <tr class="style27">
		<td height="23"  valign="top" bgcolor="#0099FF" class="style18"><span class="style28">Hobbies</span></td>
		<td width="16%"  valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[4];?></span></div></td>
		<td width="16%"  valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[5];?></span></div></td>
		<td width="15%"  valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[6];?></span></div></td>
		<td width="17%"  valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[7];?></span></div></td>
  </tr>
	<tr class="style27">
		<td height="23" valign="top" bgcolor="#0099FF" class="style18"><span class="style28"> Age </span></td>
		<td colspan="4" valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[8];?></span></div></td>
	</tr>

	<tr class="style27">
		<td height="23" valign="top" bgcolor="#0099FF" class="style18"><span class="style28"> Comments </span></td>
		<td colspan="4" valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[10];?></span></div></td>
	</tr>

	<tr class="style27">
		<td height="23" valign="top" bgcolor="#0099FF" class="style18"><span class="style28"> Date&Time </span></td>
		<td colspan="4" valign="top" class="style18"><div align="justify"><span class="style27"><font face = tahoma><?php echo $row[11];?></span></div></td>
	</tr>


</table>

	<?php
	}
}
else
{
	echo "<font color = red size=5> No Records Founded!</font>";
}

?>

<center><?=$pagination?></center>

put the table in a form and only put the method example:
<form name="Form1" method="POST"> and do not put any action and in the form put a submit button with name = "submit"
that is how when submit button is pressed then the page will submit on herself

Thanks a lot !!!!!!!!!!!!!!!!!!!
It is workinggggggggggggggggg

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.