Forum Moderators: coopster

Message Too Old, No Replies

using php mysql and pagination

         

littlehelp

11:23 pm on Dec 28, 2008 (gmt 0)

10+ Year Member



i am using pagination mysql db and php and my form will give me the results for the last item in my paginated list but not for any other item in my list, i know there is a simple fx for this but am unsure because of the pagination as to how to do this.
while ($i = mysql_fetch_array($result))
{

//foreach($i as $j)
//{
//$item[$_POST[$i[Fitem]]] = "SELECTED";
echo '<td>'.$i[Fitem].'<input type=hidden name="item" value="'.$i[Fitem].'"></b></p></td>';
echo '<td>'.$i[fEffect] .'</b></p></td>';
echo '<td>'.$i[fCost] .'<input type=hidden name="cost" value="'.$i[fCost].'"></b></p></td>';
//}
$quantity[$_POST['quantity']] = "SELECTED";
echo "<td><p><select name=\"quantity\" id=\"select2\">
<option value=\"0\">0</option>
<option value=\"1\">1</option>
<option value=\"2\">2</option>
<option value=\"3\">3</option>
<option value=\"4\">4</option>
<option value=\"5\">5</option>
<option value=\"6\">6</option>
<option value=\"7\">7</option>
<option value=\"8\">8</option>
<option value=\"9\">9</option>
<option value=\"10\">10</option>
</select></p></b></p></td></tr>";

}
//}
//echo '</tr>';
echo '<tr><td><input type="submit" name="Submit" value="Purchase"></td></tr></form></table>';
echo $pagination." ";


in my form file this is the code to display the results
if ($_POST['Submit'] == 'Purchase')
{
include"header.php";

echo "<br />This is the quantity you requested: ".$_POST['quantity']."<br />";
echo "This is the item you requested: ".$_POST['item']."<br />";
echo "This is the cost of the item you requested: ".$_POST['cost'];
}


i have it up and u can see it it is <snip>
just try to select one of the first items in the list and then try to select the end item. the last item will work but not the first item.
Thanks in advance for any help with this.

[edited by: dreamcatcher at 1:22 am (utc) on Dec. 29, 2008]
[edit reason] No personal urls, thanks. [/edit]

coopster

3:51 pm on Jan 1, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, littlehelp.

You are overwriting your input variables on each iteration of the loop.

echo '<td>'.$i[Fitem].'<input type=hidden name="item" value="'.$i[Fitem].'"></b></p></td>'; 
echo '<td>'.$i[fEffect] .'</b></p></td>';
echo '<td>'.$i[fCost] .'<input type=hidden name="cost" value="'.$i[fCost].'"></b></p></td>';

You need to either give them different names or make them an array of values. I'm guessing an array so have a look at the PHP online manual page describing how to build arrays in HTML forms with PHP [php.net].

g1smd

4:42 pm on Jan 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There are a lot of mis-matched HTML closing tags in that code snippet, and a few nesting errors.

Take a look via the HTML validator as they may give you some funky display results.