I'm trying to find a way to upload a value to SQL using a checkbox but no luck
this is my code:
/////////////////////////// FOR RXTRA ////////////////////////////////////////////////////////////
$sql = "SELECT ext_id,ext_price,ext_name,ext_description FROM tbl_extra ORDER by ext_id ASC";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
$number = mysql_num_rows($result);
$i = 0;
while ($number > $i) {
$ID = mysql_result($result,$i,"ext_id");
$NA= mysql_result($result,$i,"ext_name");
$PR= mysql_result($result,$i,"ext_price");
$DES= mysql_result($result,$i,"ext_description");
//this part chack if the value is "0" and show with "tooltip" the value\/
if ( $PR == 0 ) {
print ''.$NA.'<span>' .' free '.'</span>!';
} else {
print ''. $NA .'<span>' .' add '.' '. $PR .' $ '. '</span>!';
}
print "<input style='width: 30px; height: 15px;' type='checkbox' name='extra[]' value='$NA'></td>\n";
//this java calculate the value add to extra ant outpot the total extra that pass to sql table
print "<input type='hidden' name='item_name'/>";
print "<input type='hidden' name='amount'/>";
print "<input style='width: 30px; height: 15px;' type='checkbox' onClick='ReadForm (this.form, false);' value='+$PR'></td>\n";
$i++;
}
?>
</div></div>
<?
} else {
}
?>
<!----->
<div class="item_add_cart">
<span class="title">total extra $</span>
<div class="content">
<?
print "<input style='color:#000;font-size:13px;' size='7' name='tot' type='text'/>";
?>
</div></div>
<!----->
my problem is that I have two table's one is the total price and one is the names I try to insert all value with one checkbox and it's not working
If I create 2 checkboxes and click on them then the value uploads ok
but I need only one checkbox that sends value from $NA to Table ext_name and total price from name='tot' to ext_price table
Please note that the above code doesn't work, #Majid Fouladpour suggests the following code instead.
/////////////////////////// FOR RXTRA ////////////////////////////////////////////////////////////
$sql = "SELECT ext_id,ext_price,ext_name,ext_description FROM tbl_extra ORDER by ext_id ASC";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
$number = mysql_num_rows($result);
$i = 0;
while ($number > > $i) {
$ID = mysql_result($result,$i,"ext_id");
$NA= mysql_result($result,$i,"ext_name");
$PR= mysql_result($result,$i,"ext_price");
$DES= mysql_result($result,$i,"ext_description");
//this part chack if the value is "0" and show with "tooltip" the value\/
if ( $PR == 0 ) {
print ''.$NA.'' <a href="#" class="tooltip2">'.$NA.'<span>' .' free '.'!';
.'</span></a>!';
} else {
print ''. <a href="#" class="tooltip2">'. $NA .'' '<span>' .' add '.' '. $PR .' $ '. '!';
</span></a>!';
}
print "\n";<input style='width: 30px; height: 15px;' type='checkbox' name='extra[]' value='$NA'></td>\n";
//this java calculate the value add to extra ant outpot the total extra that pass to sql table
print "";
<input type='hidden' name='item_name'/>";
print "";<input type='hidden' name='amount'/>";
print "\n";
<input style='width: 30px; height: 15px;' type='checkbox' onClick='ReadForm (this.form, false);' value='+$PR'></td>\n";
$i++;
}
?>
total >
</div></div>
<?
} else {
}
?>
<!----->
<div class="item_add_cart">
<span class="title">total extra $</span>
<div class="content";
>
<?
print "<input style='color:#000;font-size:13px;' size='7' name='tot' type='text'/>";
?>
>
</div></div>
<!----->
(I've made this answer community wiki so the rep doesn't go to me)
Related
I am having trouble in loading time. I tried removing the first if-else statement and it works Very fast but not when added back. I have more than 40000 rows in the tables.
while ($qry->fetch()){
$form .= "
<div class='formSections' id='formSections-$formSectionCounter'>
<h4 style='text-align: center; color: white; width: 100%; font-size: 20px; margin: 10px auto;'>$sname</h4>
";
$qry2 = $con->prepare("SELECT FieldId, FieldName, FieldType, FieldFilter, DisplaySubSection from qrp.agency_webform_section_fields where SectionId = ? ORDER BY FieldOrder ASC");
// $response_array['data'] .= $con->error;
$qry2->bind_param("s", $sid);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0)
{
$qry2->bind_result($fid, $fname, $ftype, $ffilter, $DisplaySubSection);
while ($qry2->fetch())
{
if($DisplaySubSection != ''){
$form .= "
<h4 style='text-align: center; color: white; width: 100%; font-size: 20px; margin: 10px auto;'>$DisplaySubSection</h4>
";
}
unset($defval);
unset($dov);
unset($doid);
unset($iof);
unset($reqf);
$qry3 = $con->prepare("SELECT DefaultValue,IncludeOnForm,Required from qrp.agency_webform_fields where WebformId = ? and FieldId = ?");
$qry3->bind_param("ss", $wfid, $fid);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0)
{
//FOUND FIELD IN Webform
$qry3->bind_result($defval, $iof, $reqf);
$qry3->fetch();
if ($defval != '')
{
$qry4 = $con->prepare("SELECT OptionValue,OptionId from qrp.agency_webform_field_options where OptionId = ?");
$qry4->bind_param("s", $defval);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0)
{
$qry4->bind_result($dov, $doid);
$qry4->fetch();
}
else
{
$dov = $defval;
}
}
}
$form .= "
<div class='BothinputsAndLabelsAndCheckbox'>
<div class='inputsAndLabels'>
<label>$fname</label>";
if ($ftype == 'String' || $ftype == 'INT'){
$form .= "
<input name='$fid-default' id='$fid-default' type='text' class='' value='$dov' data-toggle='tooltip' data-placement='top' title='If you set an answer here, it will be the default value in the form'>
";
} else if ($ftype == 'Date'){
$date = date('Y-m-d', strtotime($dov));
$form .= "
<input name='$fid-default' id='$fid-default' type='date' class='' value='$date' data-toggle='tooltip' data-placement='top' title='If you set an answer here, it will be the default value in the form'>
";
} else if ($ftype == 'Checkbox'){
$form .= "
<input name='$fid-default' id='$fid-default' type='checkbox' class='' value='$dov' data-toggle='tooltip' data-placement='top' title='If you set an answer here, it will be the default value in the form'>
";
} else if ($ftype == 'SelectList'){
$form .= "
<select name='$fid-default' id='$fid-default' class='' data-toggle='tooltip' data-placement='top' title='If you set an answer here, it will be the default value in the form'>";
$qry3 = $con->prepare("SELECT OptionValue,OptionId,FieldFilterId from qrp.agency_webform_field_options where FieldId = ? Order By OptionValue");
$qry3->bind_param("s", $fid);
$qry3->execute();
$qry3->store_result();
$form .= "<option value=''>Please Select an Option</option>";
if ($qry3->num_rows > 0)
{
$qry3->bind_result($optv, $optid, $filid);
while ($qry3->fetch())
{
if (!isset($defval))
{
$form .= "<option value='$optid' id='$filid' class='$filid'>$optv</option>";
}
else
{
if ($doid == $optid)
{
$form .= "<option value='$optid' id='$filid' class='$filid' selected>$optv</option>";
}
else
{
$form .= "<option value='$optid' id='$filid' class='$filid'>$optv</option>";
}
}
}
}
$form .= "
</select>
";
}
$form .= "
</div>"; // end inputsAndLabels div
$form .= "
<div class=''>
<div class='includeDiv'>
<input type='checkbox' class='includeButton' id='$fid-include' data-value='$fid' name='$fid-include' "; if ($iof > 0){ $form .= " checked"; }$form .= " data-toggle='tooltip' data-placement='top' title='If you set an answer here, it will be the default value in the form'>
<label class='' for='$fid-include'> Include</label>
</div>";
if ($ftype != 'Checkbox'){
$form .= "
<div class='requiredDiv'>
<input type='checkbox' class=' requiredButton' id='$fid-required' data-value='$fid' name='$fid-required' "; if ($reqf > 0){ $form .= " checked"; }$form .= " data-toggle='tooltip' data-placement='top' title='If you set an answer here, it will be the default value in the form'>
<label class='' for='$fid-required'> Require </label>
</div>
";
}
$form .= "
</div>
</div>
";
}
}
$form .= "
</div> <!-- close formSections -->
";
$formSectionCounter++;
}
If you are doing a loop over 40000 Rows, this is basically not a problem. The Problem begins if, for every fetched row, you prepare a new SQL Statement to select related information for each row id. In your example, you are creating at least 40000 times the number of rows in subsequent SQL selects, new select statements, and that is slowing down the page load
You can solve it, by extending your first SQL Statement with a Left Join or a subselect to get all Data within one SQL fetch iteration.
I suggest saving your results into arrays. Don't mix up SQL preparation and HTML Markup. This makes the code much cleaner, and once you got your data with optimized SQL into arrays, you can search for the problem much better. Create your HTML Markup as usual with nested loops, but inside those loops access your Arrays, which you have prefilled with the Data from the Database.
When i keep search field blank and hit on search button, then show all results from mysql database, Why.... here is my php code....
I want to create it, when i keep search field blank and click search button... have to show error "no search result" and want to create disallowed white spacing search and need extra one HTML button for all Entries. By one click so that i get all entries......
please help me....
<?php
$con=mysql_connect('localhost', '1093913', 'tanim1996');
$db=mysql_select_db('1093913');
if(isset($_POST['button'])){ //trigger button click
$search=$_POST['search'];
$query=mysql_query("select * from iconic19 where student_id like '%{$search}%' || name like '%{$search}%' || phone like '%{$search}%' || blood like '%{$search}%' || district like '%{$search}%' ");
if (mysql_num_rows($query) > 0) {
while ($row = mysql_fetch_array($query)) {
echo "<tbody>";
echo "<tr>";
echo "<td data-label='Student ID'>".$row['student_id']."</td>";
echo "<td data-label='Name' style='font-weight:bold;' >".$row['name']."</td>";
echo "<td data-label='Mobile No'>"."<a href='tel:".$row['phone']."'>".$row['phone']."</a>"."</td>";
echo "<td data-label='Blood' style='color:red; font-weight:bold;' >".$row['blood']."</td>";
echo "<td data-label='Email'>"."<a href='mailto:".$row['email']."'>".$row['email']."</a>"."</td>";
echo "<td data-label='District'>".$row['district']."</td>";
echo "</tr>";
echo "</tbody>";
}
}else{
echo "<div class='error-text'>No results</div><br><br>";
}
}else{ //while not in use of search returns all the values
$query=mysql_query("select * from iconic19");
while ($row = mysql_fetch_array($query)) {
}
}
mysql_close();
?>
Its Html Code
<form id="nbc-searchblue1" method="post" enctype="multipart/form-data" autocomplete="off">
<input id='wc-searchblueinput1' placeholder="Search Iconic..." name="search" type="search" autofocus>
<br>
<input id='nbc-searchbluesubmit1' value="Search" type="submit" name="button">
<div class="view-all"> Show all</div>
</form>
Its css Code..
.view-all a {
background: red;
padding: 10px;
border-radius: 4px;
color: #fff;
text-decoration: none;
}
<?php
$con=mysql_connect('localhost', '1093913', 'tanim1996');
$db=mysql_select_db('1093913');
if(isset($_POST['button'])){ //trigger button click
$numRows = 0;
if(!empty($_POST['search'])) {
$search = mysql_real_escape_string($_POST['search']);
$query = mysql_query("select * from iconic19 where student_id like '%{$search}%' || name like '%{$search}%' || phone like '%{$search}%' || blood like '%{$search}%' || district like '%{$search}%' ");
$numRows = (int)mysql_num_rows($query);
}
if ($numRows > 0) {
while ($row = mysql_fetch_array($query)) {
echo "<tbody>";
echo "<tr>";
echo "<td data-label='Student ID'>".$row['student_id']."</td>";
echo "<td data-label='Name' style='font-weight:bold;' >".$row['name']."</td>";
echo "<td data-label='Mobile No'>"."<a href='tel:".$row['phone']."'>".$row['phone']."</a>"."</td>";
echo "<td data-label='Blood' style='color:red; font-weight:bold;' >".$row['blood']."</td>";
echo "<td data-label='Email'>"."<a href='mailto:".$row['email']."'>".$row['email']."</a>"."</td>";
echo "<td data-label='District'>".$row['district']."</td>";
echo "</tr>";
echo "</tbody>";
}
} else {
echo "<div class='error-text'>No results</div><br><br>";
}
} else { //while not in use of search returns all the values
$query = mysql_query("select * from iconic19");
while ($row = mysql_fetch_array($query)) {
}
}
mysql_close();
?>
What I have done was creating a new variable $numRows with a default value of 0. If your search is empty there is no query to the database. I escaped your $search variable.
BTW: Please change to mysqli, the mysql extension is no longer supported in newer php versions.
Just check if $_POST['search'] is blank then display your message else execute your query.
<?php
// this is where selecting of number of rooms in database
$sql = mysqli_query($con, 'SELECT * FROM roomtype');
$get_room1 = mysqli_query ($con, "SELECT * from room where status='Activated' and type_id=2");
$get_room2 = mysqli_query ($con, "SELECT * from room where status='Activated' and type_id=3");
$get_room3 = mysqli_query ($con, "SELECT * from room where status='Activated' and type_id=4");
$get_room4 = mysqli_query ($con, "SELECT * from room where status='Activated' and type_id=5");
$standard = mysqli_num_rows($get_room1);
$deluxe = mysqli_num_rows($get_room2);
$family = mysqli_num_rows($get_room3);
$regular = mysqli_num_rows($get_room4);
// this is the loop for the drop down and it will display the number of rooms available
while($row = mysqli_fetch_array($sql))
{
$a=$row['type_id'];
$b = $row['rmtype'];
$_SESSION['room_type'] = $row['rmtype'];
echo '<div style="height: 300px;">';
echo '<div style="float: left; width: 100px; margin-top: 15px; margin-left: 60px;">';
echo "<img width=250 height=200 alt='Unable to View' src='" . $row["image"] . "'>";
echo '</div>';
echo '<div class="well" style="float: right; width: 780px; margin-top: 5px;">';
echo '<div style="float: right;">';
echo '</div>';
echo '<br />';
echo "<label style='margin-left: px;'>Number of rooms:";
echo "<select name='select_no_rooms[]' value='" .$row['rmtype']." ' />";
echo "<option> </option>";
if ($row['rmtype']=="Standard Room")
{
for ($x = 1; $x<=$standard; $x++){
echo "<option name='standard'>$x</option>";}
}
if ($row['rmtype']=="Deluxe Room")
{
for ($x = 1; $x<=$deluxe; $x++){
echo "<option name='deluxe'>$x</option>";}
}
if ($row['rmtype']=="Family Room")
{
for ($x = 1; $x<=$family; $x++){
echo "<option name='family'>$x</option>";}
}
if ($row['rmtype']=="Regular Room")
{
for ($x = 1; $x<=$regular; $x++){
echo "<option name='regular'>$x</option>";}
}
echo "</select>";
}
?>
This is the design of drop down,
add [ ] tag to name tag, so you will get your value in array.
<option name='deluxe[]'>$x</option>
First thing that I notice is that in you select statement, you cannot have value as an attribute. Please check the documentation select tag
And the option tag does not include name attribute. Please check the documentation option tag
If you want to get multiple values from a drop down list. Please check this article
I am trying to keep my pagination based on the query I am using, but my problem is, it only works on the first page of pagination, and after that the query reverts to the standard one without filters (page one shows my filter, but page two show all results). I am wondering if there is an effective method that will carry over my filtered query when I click my pages, I am just at a loss right now as to how to accomplish this. Here is my code currently:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<style type="text/css">
#win-range, #gaa-range, #sv-range{
width: 160px;
font-size: 10px;
margin: 0 auto;
}
#win-range a, #gaa-range a, #sv-range a{
margin-top: 0px !important;
padding: 0 !important;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function(){
$("#win-range").slider({
range: true,
min: 1,
max: 1000,
values: [1, 1000],
slide: function(event, ui) {
// in order to pass the user selected values to your app, we will use jQuery to prepopulate certain hidden form elements, then grab those values from the $_POST
$("#minwins").val(ui.values[0]);
$("#maxwins").val(ui.values[1]);
$("#winamount").val(ui.values[0] + " - " + ui.values[1]);
}
});
$("#winamount").val($("#win-range").slider("values", 0) + " - " + $("#win-range").slider("values", 1));
});
$(function(){
$("#gaa-range").slider({
range: true,
min: 0,
max: 10,
values: [0, 10],
slide: function(event, ui) {
// in order to pass the user selected values to your app, we will use jQuery to prepopulate certain hidden form elements, then grab those values from the $_POST
$("#mingaa").val(ui.values[0]);
$("#maxgaa").val(ui.values[1]);
$("#gaaamount").val(ui.values[0] + " - " + ui.values[1]);
}
});
$("#gaaamount").val($("#gaa-range").slider("values", 0) + " - " + $("#gaa-range").slider("values", 1));
});
$(function(){
$("#sv-range").slider({
range: true,
min: 750,
max: 1000,
values: [750, 1000],
slide: function(event, ui) {
// in order to pass the user selected values to your app, we will use jQuery to prepopulate certain hidden form elements, then grab those values from the $_POST
$("#minsv").val(ui.values[0]);
$("#maxsv").val(ui.values[1]);
$("#svamount").val(ui.values[0] + " - " + ui.values[1]);
}
});
$("#svamount").val($("#sv-range").slider("values", 0) + " - " + $("#sv-range").slider("values", 1));
});
</script>
<?php
include("includes/header.php");
include("includes/mysqli_connect.php");
$minwins = $_POST['minwins'];
$maxwins = $_POST['maxwins'];
$mingaa = $_POST['mingaa'];
$maxgaa = $_POST['maxgaa'];
$minsv = $_POST['minsv'];
$maxsv = $_POST['maxsv'];
$querySelection = $_POST['q'];
// FILTERING YOUR DB
$sortstats = $_GET['sortstats'];
$sortstatslow = $_GET['sortstatslow'];
// pagination
$getcount = mysqli_query ($con,"SELECT COUNT(*) FROM Player");
$postnum = mysqli_result($getcount,0);// this needs a fix for MySQLi upgrade; see custom function below
$limit = 6; //how many blog posts per page you will see.
if($postnum > $limit){
$tagend = round($postnum % $limit,0);
$splits = round(($postnum - $tagend)/$limit,0);
if($tagend == 0){
$num_pages = $splits;
}else{
$num_pages = $splits + 1;
}
if(isset($_GET['pg'])){
$pg = $_GET['pg'];
}else{
$pg = 1;
}
$startpos = ($pg*$limit)-$limit;
$limstring = "LIMIT $startpos,$limit";
}else{
$limstring = "LIMIT 0,$limit";
}
// MySQLi upgrade: we need this for mysql_result() equivalent
function mysqli_result($res, $row, $field=0) {
$res->data_seek($row);
$datarow = $res->fetch_array();
return $datarow[$field];
}
?>
<div class="listingcontainer">
<div class="sidebar">
<h3>Sort By:</h3>
Most Wins
Best Goals Against
Best Save %
<hr/>
<h3>Custom Filter</h3>
<br/>
<div class="custom-filter">
<form name="filters" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="filters">
<label for="winamount">Win Range:</label>
<input type="text" id="winamount" />
<div style="clear:both;"></div>
<input type="hidden" id="minwins" name="minwins" value="0" />
<input type="hidden" id="maxwins" name="maxwins" value="1000" />
<div id="win-range"></div>
<br/>
<label for="gaaamount">GAA:</label>
<input type="text" id="gaaamount" /><br />
<div style="clear:both;"></div>
<input type="hidden" id="mingaa" name="mingaa" value="0" />
<input type="hidden" id="maxgaa" name="maxgaa" value="10" />
<div id="gaa-range"></div>
<br/>
<label for="svamount">SV %:</label>
<input type="text" id="svamount" /><br />
<div style="clear:both;"></div>
<input type="hidden" id="minsv" name="minsv" value="750" />
<input type="hidden" id="maxsv" name="maxsv" value="1000" />
<div id="sv-range"></div>
<input type="submit" name="submit" id="submit"/>
</form>
</div>
</div>
<div class="main-listings">
<h1>Current NHL Goaltenders</h1>
<?php
$result = mysqli_query($con, "SELECT * FROM Player ORDER BY PlayerID ASC $limstring");
if(isset($sortstats)) {
$result = mysqli_query($con,"SELECT * FROM Player ORDER BY $sortstats DESC $limstring ") or die (mysql_error());
}
if(isset($sortstatslow)) {
$result = mysqli_query($con,"SELECT * FROM Player ORDER BY $sortstatslow ASC $limstring ") or die (mysql_error());
}
if(isset($_POST['submit']))
{
$result = mysqli_query($con, "SELECT * FROM Player WHERE Wins BETWEEN '$minwins' AND '$maxwins' AND
GAA BETWEEN '$mingaa' AND '$maxgaa' AND SavePerc BETWEEN '$minsv' AND '$maxsv'
ORDER BY PlayerID ASC $limstring") or die (mysql_error());
}
while($row = mysqli_fetch_array($result)){
$name = $row['LastName'] . ", " . $row['FirstName'];
$wins = $row['Wins'];
$pid = $row['PlayerID'];
$image = $row['Picture'];
$gaa = $row['GAA'];
$sv = $row['SavePerc'];
echo "<div class=\"player-listing\">";
echo "<div class=\"image-holder\">";
echo "<span class=\"helper\"></span>";
echo "<img src=\"admin/thumbs/$image\" alt=\"$name\">";
echo "</div>";
echo "<div style=\"clear:both;\"></div>";
echo "$name";
echo "<table align=\"center\">";
echo "<tr>";
echo "<td style=\"border-bottom: 1px solid #212121;\">Wins</td>";
echo "<td style=\"border-bottom: 1px solid #212121;\">GAA</td>";
echo "<td style=\"border-bottom: 1px solid #212121;\">SV%</td>";
echo "</tr>";
echo "<tr>";
echo "<td>$wins</td>";
echo "<td>$gaa</td>";
echo "<td>.$sv</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
}
// paging links:
echo "<div class=\"paging\">";
if($postnum > $limit){
echo "<span class=\"page-numbers\"><strong>Pages:</strong> </span>";
$n = $pg + 1;
$p = $pg - 1;
$thisroot = $_SERVER['PHP_SELF'];
if($pg > 1){
echo "<< prev ";
}
for($i=1; $i<=$num_pages; $i++){
if($i!= $pg){
echo "$i ";
}else{
echo "$i ";
}
}
if($pg < $num_pages){
// INSERT QUERY STRING VARIBLE TO CARRY OVER DB QUERY
echo "next >>";
}
echo " ";
}
// end paging
echo "</div>";
?>
</div>
<div style="clear:both;"></div>
Save you search filters in session and always check the session value is set for any search or not and pass that data into you query.until and unless nobody reset that search criteria and when your user reset that search criteria to null then put the value blank in the session for that session search variable.
You need to pass all filter conditions to the paginating link, for example
$filter = "minwins={$minwins}&maxwins={$maxwins}&mingaa={$mingaa}&minsv={$minsv}&maxsv={$maxsv}&q={$querySelection}";
if($pg > 1){
echo "<< prev ";
}
for($i=1; $i<=$num_pages; $i++){
if($i!= $pg){
echo "$i ";
}else{
echo "$i ";
}
}
if($pg < $num_pages){
// INSERT QUERY STRING VARIBLE TO CARRY OVER DB QUERY
echo "next >>";
}
In the code for getting filter conditions from $_POST you are using, change it to $_REQUEST because it should get from URL ($_GET).
Ex
$minwins = $_REQUEST['minwins'];
You could always use the below to create a list of URL keys (filters).
foreach($_GET as $key => $value){
$url_keys .= $key . "=" . $value . "&";
}
And then add that into your URL for next/prev page.
echo "next >>";
You will then be passing your filters through the URL and have access to them on the next page.
Currently I have a script that displays the data which is editable and can update the database. I have tried to enter row counts and nothing seem to work. I really like the script to make 3 columns (10 rows per column), please help.
$sql = "SELECT id, pounds FROM price_list ORDER BY id";
$i = 0;
$result = mysql_query($sql);
echo "<form name='prices' method='post' action='updateA.php'>";
while($rows = mysql_fetch_array($result))
{
echo "<body bgColor='#5F5F6B'>";
echo "<table><table border=2 cellspacing=0 cellpadding=1>";
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
echo "<td><font color='#FFFFFF'><font size='2'>DAYS {$rows['id']}: </font><font size='2'><font color='#000000'>PRICE:<input type='text' size='1' name='pounds[$i]' value='{$rows['pounds']}' ></tr>";
++$i;
}
echo "</table>";
echo "<input type='submit' value='Update Prices Band A' />";
echo "</form>";
?>
The above is the original code.
I don't really know what you're trying to do, but this code will generate a list of all the entries in the database with the ability to change them. Note that you'll have to remake your update_a.php file:
<style>
body {
background:#5F5F6B;
color:#fff;
}
</style>
<?php
$result = mysql_query("SELECT id, pounds FROM price_list ORDER BY id");
if (!$sql || mysql_num_rows($result)==0)
echo "Price list is empty";
else {
echo '<form name="prices" method="GET" action="update_a.php">'; // Change your filename!
$i = 0;
while ($rows = mysql_fetch_array($result)) {
echo 'Day '.$rows['id'].' costs ';
echo '<input type="text" name="'.$rows['id'].'" value="'.$rows['pounds'].'"/> pounds'
echo '<br/>'
$i++;
}
echo '<input type="submit" value="Update Prices Band A"/>';
echo "</form>";
}
?>
First of all many thanks to Leonard Pauli, the code worked perfectly in displaying the data but, it wouldn't update the database using my update.php. Below is the revised code and screenshot of what I was trying to archive.
Screenshot of single lined data displayed in 3 columns
<style>
body {
background:#5F5F6B;
color:#fff;
width:800px;
height:550px;
border:2px solid #bbb;
padding:20px;
float:center;
}
input[type="text"] {
width: 30px;
}
.table {
width:180px;
margin:1px;
border:2px solid #bbb;
padding:10px;
float:left;
}
.header {
width:595px;
margin:1px;
border:2px solid #bbb;
padding:10px;
float:left;
}
</style>
<div class="header"><b>Price List for dates from <font color ="yellow"><?php echo "$SPA"; ?> to <?php echo "$EPA"; ?></font></div>
<?php
$dataprice = $_POST['database'];
$datesrange = $_POST['id'];
$result = mysql_query("SELECT id, pounds FROM $dataprice ORDER BY id");
echo '<form name="prices" method="POST" action="update.php">';
$i = 0;
while ($rows = mysql_fetch_array($result)) {
echo '<div class="table">Day <font color="yellow">'.$rows['id'].' </font> costs ';
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
echo "<input type='text' name='pounds[$i]' value='{$rows['pounds']}' > Pounds";
echo '<br/></div>';
$i++;
}
echo "<input type='hidden' name='databases' value='$dataprice'>";
echo '<center><input type="submit" value="Update Prices"/>';
echo '<center><font color="yellow"><br><br><br>IF UPDATING PRICE BAND D, ONLY ENTER THE VALUE OF WHICH
PRICES YOU WANT TO INCREASE BY, <br>EXAMPLE: 7 DAYS, IF CURRENT PRICE IS 30, IF YOU WANT TO
CHARGE 34, ONLY ENTER 4 AND LEAVE EVERYTHING ELSE SET TO 0</b></center>';
echo "</form>";
?>
A bit of an idiot really, completely forgot about CSS styling.