I tried to look into the similar topics but couldn't find a solution, done everything I learned but its giving me same error always, & here's the code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable();
} ); //this is where its pointing for error
</script>
I don't think I'm missing something, but there must be any other mistake...can anyone of you please point out ?
This is the error details:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in /var/www/vhosts/tradeglobus.com/httpdocs/companies_list.php on line 41
#Alex: here's the full code
$isSeller = ((isset($PageType) && $PageType == "sellers") ? "1" : "0");
if(isset($searchType) && $searchType == "companies")
{
//--------- Show Products Here -----------//
$Query = clsCompanies::searchCompany($keyword, $Limit, $Offset, $countryID);
$companies_list = $objDatabase->runStoredProcedure($Query);
//----------------------------------------//
}
else
{
//--------- Show Products Here -----------//
$Query = clsCompanies::getCompaniesForDetailPages($IndustryId, $isSeller, $Limit, $Offset);
$companies_list = $objDatabase->runStoredProcedure($Query);
//----------------------------------------//
}
if(count($companies_list))
{
$Cnt = 0;
foreach($companies_list as $company)
{
$Cnt++;
echo '<tr>
<td ' . ((($Cnt % 2) == 0) ? "class='Even'" : "class='Odd'") . ' ">
<style type="text/css" title="currentStyle">
#import "http://www.tradeglobus.com/search/demo_page.css";
#import "http://www.tradeglobus.com/search/demo_table.css";
</style>
<script type="text/javascript" language="javascript" src="http://www.tradeglobus.com/search/jquery.js"></script>
<script type="text/javascript" language="javascript" src="http://www.tradeglobus.com/search/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
<body id="dt_example">
<div id="container">
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>Company</th>
<th>Description</th>
<th>Membership Status</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr class="gradeX">
<!-- TD for Company Logo STARTS -->
<td rowspan="3" valign="top" width="75px" valign="middle" align="center">
<img src="' . clsPresent::checkImageExistance(BASE_HOST . DEFAULT_COMPANY_LOGO_PATH . $company['company_logo_thumb']) . '" width="75px" height="75px" alt="productImage" />
</td>
<!-- TD for Company Logo ENDS -->
<!-- TD for Company Name & Description STARTS -->
<td rowspan="2" width="450px" align="left" style="line-height: 15px;">
<h4 ><a style="font-size:16px;" href="' . BASE_HOST . 'companies_details/' . $company['MemberID'] . '/' . clsPresent::removeSpecialChars($company['company_name']) . '.htm">' . $company['company_name'] . '
</a></h4><br/>' . ((strlen($company['company_introduction']) > 165) ? substr(strip_tags($company['company_introduction']), 0, 162) . '...' : $company['company_introduction']) .'
</td>
<!-- TD for Company Name & Description ENDS -->
<!-- TD for Company Flag & Package STARTS -->
<td valign="top" >
<div style="float: left; line-height: 25px;"><div class="flags f_' . $company['CountryID'] . '"></div> ' . $company['Country'] .'</div><br/>
</td>
<!-- TD for Company Flag & Package ENDS -->
<td class="center"><img src="' . BASE_HOST . DEFAULT_PACKAGE_IMAGE_PATH . $company['imagePath'] . '" alt="Package Image" width="101px" height="24px" /></td>
</tr>
</table>
<tr>
<td valign="top" style="line-height: 15px;">
<div>';?>
<?php
if(isset($_SESSION['userID']) && $_SESSION['userID'] != ""){ ?>
<a style="vertical-align: top;" class="contactNow" href="<?php echo BASE_HOST; ?>contactmember.php?to=<?php echo $company['MemberID']; ?>&from=<?php echo $_SESSION['userID']; ?>&subject=Contact Request"></a>
<?php } else { ?>
<a style="vertical-align: top;" class="contactNowB" href="<?php echo BASE_HOST; ?>signin.php"></a>
<?php }
echo '</div>
</td>
</tr>
</table>
</td>
</tr>';
}
echo '<tfoot>
<tr>
<th>';
if(isset($PageType) && $PageType != ""){
echo' <span style="float: left; padding-left: 10px;">' . (( $PageNo > 1 ) ? '<-- Back' : "" ) . '</span>
<span style="float: right; padding-right: 10px;">Next --></span>';
}else{
echo' <span style="float: left; padding-left: 10px;">' . (( $PageNo > 1 ) ? '<-- Back' : "" ) . '</span>
<span style="float: right; padding-right: 10px;">Next --></span>';
}
echo ' </th>
</tr>
</tfoot>';
}
else
{
echo '<tr>
<td align="center" valign="top">
<h1 style="font-size: 16px; color: #003466;">No companies were found for this category.</h1>
</d>
</tr>';
}
?>
You need to quote out '
$('#example').dataTable();
Should be
echo '<tr>
/*...further code...*/
$(\'#example\').dataTable();
';
Since its inside a PHP string.
You have no error in your JavaScript code. JavaScript does not compile, it gets interpreted by the browser. You won't see Parse error displayed in the page for JavaScript, you'll see errors logged to the browser console (WebInspector/Firebug etc.).
Your error is somewhere in your PHP code, and I doubt that the line number is pointing to the correct location. If you need more help debugging that, post the entire PHP source code in your question.
Related
I have a table on my website, which gets data from a database, in the table I have delete buttons on a row, I have just made the table searchable with jQuery, but now I can't figure out how to keep the delete buttons.
index.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta charset="utf-8">
<meta name="description" content="Inventar">
<meta name="author" content="Martin Eide Bjørndal">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="/src/css/style.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
<button class="back" onclick="window.location='../'">
<img src="/src/icons/back.png">
</button> <!-- Tilbake knapp -->
<button class="ny_inventar" onclick="window.location='/admin/brukere/ny'">
<img src="/src/icons/add.png">
</button> <!-- Ny Bruker knapp -->
<div class="container-fluid" id="utskjekkcontainer">
<div class="row justify-content-center">
<div class="col-mv-10 bg-light mt-5 rounded p-3">
<h1 class="text-primary p-2">Brukere</h1>
<hr>
<div class="form-inline">
<label for="search" class="font-weight-bold lead text-dark">Søk</label>
<input type="text" name="search" id="search_text" class="form-control form-control-lg rounded-0 border-primary" placeholder="Søk...">
</div>
<hr>
<?php
include "../../src/fn/init.php";
$stmt=$conn->prepare("SELECT * FROM brukere");
$stmt->execute();
$result=$stmt->get_result();
?>
<table class="table table-hover table-light table-striped" id="table_data">
<thead>
<tr>
<th>#</th>
<th>Fornavn</th>
<th>Etternavn</th>
<th>Utskjekket</th>
<th>Admin</th>
<th>Slett</th>
</tr>
</thead>
<tbody>
<?php while($row=$result->fetch_assoc()){ ?>
<tr>
<td><?php echo $row["id"]; ?></td>
<td><?php echo $row["fornavn"]; ?></td>
<td><?php echo $row["etternavn"]; ?></td>
<td><?php echo $row["utskjekket"]; ?></td>
<td><?php echo $row["is_admin"]; ?></td>
<td>Slett</td>
</tr>
<?php }
$conn->close();
?>
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#search_text').keyup(function(){
var search = $(this).val();
$.ajax({
url:'action.php',
method:'post',
data:{query:search},
success:function(response){
$('#table_data').html(response);
}
});
});
});
</script>
</body>
</html>
action.php:
<?php
include "../../src/fn/init.php";
$output = "";
if(isset($_POST["query"])){
$search = $_POST["query"];
$stmt = $conn->prepare("SELECT * FROM brukere WHERE fornavn LIKE CONCAT('%',?,'%') OR etternavn LIKE CONCAT('%',?,'%') OR id LIKE CONCAT('%',?,'%')");
$stmt->bind_param("sss",$search, $search, $search);
} else {
$stmt=$conn->prepare("SELECT * FROM brukere");
};
$stmt->execute();
$result=$stmt->get_result();
if($result->num_rows>0){
$output = "<thead>
<tr>
<th>#</th>
<th>Fornavn</th>
<th>Etternavn</th>
<th>Utskjekket</th>
<th>Admin</th>
<th>Slett</th>
</tr>
</thead>
<tbody>";
while($row=$result->fetch_assoc()){
$output .= "
<tr>
<td>".$row["id"]."</td>
<td>".$row["fornavn"]."</td>
<td>".$row["etternavn"]."</td>
<td>".$row["utskjekket"]."</td>
<td>".$row["is_admin"]."</td>
<td>".Slett."</td>
</tr>";
};
$output .= "</tbody>";
echo $output;
} else {
echo "<h3>No match found!</h3>";
};
?>
This is the search script, the problem is in the while loop where the link is added, I can't figure out how to make it work.
The a tag is not added as a plain-text to the output string, you need to rewrite that line, concatenate strings parts to variables parts correctly.
Try replacing:
$output .= "
<tr>
<td>".$row["id"]."</td>
<td>".$row["fornavn"]."</td>
<td>".$row["etternavn"]."</td>
<td>".$row["utskjekket"]."</td>
<td>".$row["is_admin"]."</td>
<td>".Slett."</td>
</tr>";
with:
$output .= "
<tr>
<td>".$row["id"]."</td>
<td>".$row["fornavn"]."</td>
<td>".$row["etternavn"]."</td>
<td>".$row["utskjekket"]."</td>
<td>".$row["is_admin"]."</td>
<td><a href='delete.php?id=".urlencode($row['id'])."' onclick='return confirm('Er du sikker?');'>Slett</a></td>
</tr>";
To allow PHP to echo the id from the table result you need to just simply do a php echo
Slett
You don't have to url encode at this stage as you are just simply building the href of an a:link
You can use it
<?php
include "../../src/fn/init.php";
$output = "";
if(isset($_POST["query"])){
$search = $_POST["query"];
$stmt = $conn->prepare("SELECT * FROM brukere WHERE fornavn LIKE CONCAT('%',?,'%') OR etternavn LIKE CONCAT('%',?,'%') OR id LIKE CONCAT('%',?,'%')");
$stmt->bind_param("sss",$search, $search, $search);
} else {
$stmt=$conn->prepare("SELECT * FROM brukere");
};
$stmt->execute();
$result=$stmt->get_result();
if($result->num_rows>0){
$output = "<thead>
<tr>
<th>#</th>
<th>Fornavn</th>
<th>Etternavn</th>
<th>Utskjekket</th>
<th>Admin</th>
<th>Slett</th>
</tr>
</thead>
<tbody>";
while($row=$result->fetch_assoc()){
$output .= "
<tr>
<td>".$row["id"]."</td>
<td>".$row["fornavn"]."</td>
<td>".$row["etternavn"]."</td>
<td>".$row["utskjekket"]."</td>
<td>".$row["is_admin"]."</td>
<td>Slett </td>
</tr>";
};
$output .= "</tbody>";
echo $output;
} else {
echo "<h3>No match found!</h3>";
};
I have this code:
<?php
session_start();?>
<!DOCTYPE html>
<html>
<head>
<title>Narcis Bet</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css" type="text/css">
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<header>
<div id="top">
<img src="images/logo.png" width="400" height="140" alt="logo"/>
<?php
if(!isset($_SESSION['utilizator']))
{
?>
<div id="topright">
<form action="api/login.php" method="POST" id="toprightt">
<input type="text" name="username"/>
<input type="password" name="password"/>
<input type="submit" value="Login"/>
</form>
</div>
<img src="images/facebook.png" alt="facebook"/>
Contact
Termeni și condiții
</div>
</header>
<?php
if(isset($_SESSION['eroare']))
{
echo $_SESSION['eroare'];
unset($_SESSION['eroare']);
}
}
else
{
echo "<h1 id="."topright".">Bun venit,".$_SESSION['utilizator']."</h1>";
?>
<form action="api/logout.php" id="toprightl">
<input type="submit" value="Logout"/>
</form>
<nav class="nav">
<ul>
<li>Pariuri</li>
<li>Loto</li>
<li>Despre</li>
<li>Regulament</li>
</ul>
</nav>
<section class="main">
<table class="tableright" id="talon">
<tr>
<th>Cod</th>
<th>Eveniment</th>
<th>Data</th>
<th>Cota</th>
</tr>
</table>
<table class="table1" >
<thead>
<tr><th colspan="6" class="th1">FOTBAL</th></tr>
<tr>
<th>Cod.</th>
<th>Eveniment</th>
<th>data</th>
<th >1</th>
<th >X</th>
<th >2</th>
</tr>
</thead>
<?php
$handle = #fopen("../res/fotbal.txt", "r");
if ($handle)
{
while (($buffer = fgets($handle, 4096)) !== false)
{
$pariu=json_decode($buffer,true);
echo "<tr>";
echo "<td id='cod'>".$pariu["id"]."</td>";
echo "<td id='ev'>".$pariu['eveniment']."</td>";
echo "<td id='data'>".$pariu['data']."</td>";
echo "<td class='td1' onclick='FUNCTIE(".$pariu["id"].",\"".$pariu["eveniment"]."\",\"".$pariu["data"]."\",'1')>".$pariu['1']."</td>";
echo "<td class='td1' onclick='FUNCTIE(".$pariu["id"].",\"".$pariu["eveniment"]."\",\"".$pariu["data"]."\",'X')>".$pariu['X']."</td>";
echo "<td class='td1' onclick='FUNCTIE(".$pariu["id"].",\"".$pariu["eveniment"]."\",\"".$pariu["data"]."\",'2')>".$pariu['2']."</td>";
/*echo "<td class='td1'><button onclick='FUNCTIE(".$pariu["id"].",\"".$pariu["eveniment"]."\",\"".$pariu["data"]."\",'1')".$pariu['1']."</button></td>";
echo "<td class='td1'><button onclick='FUNCTIE(".$pariu["id"].",\"".$pariu["eveniment"]."\",\"".$pariu["data"]."\",'X')".$pariu['1']."</button></td>";
echo "<td class='td1'><button onclick='FUNCTIE(".$pariu["id"].",\"".$pariu["eveniment"]."\",\"".$pariu["data"]."\",'2')".$pariu['1']."</button></td>";
*/
echo "</tr>";
}
if (!feof($handle))
{
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
} ?>
</table>
</section>
</body>
</html>
and the function in javascript:
function FUNCTIE(id,eveniment,data,tip_pariu)
{
var table=document.getElementById('talon');
if(table)
{
table.innerHTML+="<tr><td>"+id+"</td><td>"+eveniment+"</td><td>"+data+"</td><td>"+tip_pariu+"</td><tr>";
}
}
and i get this error(uncaught syntaxerror unexpected token }) when i press on the td with onlick function.Please help me !I dont know why i get this error!.......................................................................................................................................................................................................................................................................................................................................................
unless they are all numbers, keywords, functions, or variable names, you should wrap your calls in quotes. so code becomes... also there is a ' left out.
... ... ...
echo "<td class='td1' onclick='FUNCTIE(\"".$pariu["id"]."\",\"".$pariu["eveniment"]."\",\"".$pariu["data"]."\",1)'>".$pariu["1"]."</td>";
... ... ...
maybe that will work
While browsing a website i found an interesting feature that i like to have in my application.It is like displaying search result on same page without refreshing the page. When someone fills the last field of the form it shows the search result on the same page without refreshing the page.The form has no submit button or any link to submit the form data when someone fills the last field it search result and display the result. I want to implement this feature in my application i built in PHP. I know this can be done by Javascript & Ajax but i don't have enough knowledge of these languages. I just learned HTML,CSS,PHp & MySql. Let me show u my code
HTML:
<form action="do_search.php" method="post"/>
Enter Number:<input type="text" name="roll" id="roll">
<input type="submit" value="search record"/>
do_search.php:
<?php
include 'includes/dbConnect.php';
?>
<?php
$roll = $_POST['roll'];
$result = mysql_query( "SELECT * FROM students WHERE Roll_No = '$roll'" ) or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
?>
<table width="100%" bgcolor="#F7F7F7" border="0">
<?php
if ($num_rows!=0)
{
?>
<tr style="text-align:left;">
<td width="7%" align="center" bordercolor="#CCCCCC" bgcolor="#996600" class="heading"><strong>#</strong></td>
<td width="13%" align="left" bordercolor="#CCCCCC" bgcolor="#996600" class="heading"><strong>Roll No</strong></td>
<td width="29%" align="left" bordercolor="#CCCCCC" bgcolor="#996600"class="heading"><strong>Name</strong></td>
<td width="23%" align="left" bordercolor="#CCCCCC" bgcolor="#996600" class="heading"><strong>Father Name</strong></td>
<td width="16%" align="center" bordercolor="#CCCCCC" bgcolor="#996600" class="heading"><strong>Class</strong></td>
<td width="12%" align="center" bordercolor="#CCCCCC" bgcolor="#996600" class="heading"><strong>Section</strong></td>
</tr>
<?php
//$counter = 1;
while ($get_info = mysql_fetch_row($result))
{
print '<tr class="text-data">';
print '<td align="center" valign="top">' . $get_info[0] . '</td>';
print '<td align="left" valign="top">
<a href="edit_Student.php?roll_no=' . $get_info[1] . '" style="color:#000"><b>' . $get_info[1] . '</b></td>';
print '<td align="left" valign="top">'. $get_info[2] . '</td>';
print '<td align="left" valign="top">' . $get_info[3] . '</td>';
print '<td align="center" valign="top">' . $get_info[4] . '</td>';
print '<td align="center" valign="top">' . $get_info[5] . '</td>';
print '</tr>';
//$counter++;
}
}
else
{
?>
<tr style="text-align:left;">
<td align="center" colspan="7">
No Student Found !
</td>
</tr>
<?php
}
?>
</table>
This is working fine for me and display the record on do_search.php page. I want my form has no submit button option & when someone enter the form field Enter Roll Number it should display the record on same page and display all the record from database. Can anyone please help me for this. Thanks in advance
You can do that with jQuery ajax.
<form action="do_search.php" method="post"/>
Enter Number:<input type="text" name="roll" id="roll">
</form>
<div id="result"></div>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
$("#roll").change(function() {
$.post("do_search.php", { roll:$("#roll").val() })
.done(function( data ) {
$("#result").html(data);
});
});
</script>
Use Jqyery keydown() Method
$("input").keydown(function(){
//Do display logic
// Use Ajax and get the data for the value enter and update your html content
});
http://www.w3schools.com/jquery/event_keydown.asp
my table contain large number of dynamic rows when i print or print preview it i get only table thead on only first page using window.print() function ..but i want table thead on each print page... help?
<div id="printablediv" >
<div style="padding:8px;font-size: 13px;">
<center>
<?php
$sumMul = 0;
$sumBil = 0;
?>
<?php $total = $total_ni = $total_aa = $total_pe = $total_bak = $total_cnt = 0; ?>
<table cellpadding="0" cellspacing="0" border="1" style="font-size: 13px;" >
<thead id="head">
<tr bgcolor="#333333" style="color:#black;font-weight: bold;">
<th width="100" align="center">Donor</th>
<th width="100" align="center">Loan No.</th>
<th width="120" align="center">Value Date</th>
<th width="90" align="center">Curr</th>
<th width="150" align="center">Multilateral</th>
<th width="150" align="center">Bilateral</th>
<th width="150" align="center">Forex</th>
<th width="150" align="center">Multilateral</th>
<th width="150" align="center">Bilateral</th>
</tr>
</thead>
<?php $previousValue = $list[0]->LOAN_ID; ?>
<?php $flag = 0; ?>
<?php foreach ($list as $key => $val): ?>
<tr>
<td align="center"><?php echo $val->EX_DONOR_CODE; ?></td>
<td align="center"><?php echo $val->LOAN_ID; ?></td>
<td align="center"><?php echo $val->VALUE_DATE; ?></td>
<td align="center"><?php echo $val->TRANSACTION_CURRENCY_CODE; ?></td>
<td align="right"><?php
if ($val->DONOR_TYPE == 'MULTILATERL') {
$sumMul += $val->COMMIT_CUR_AMT;
echo $val->COMMIT_CUR_AMT;
}
?></td>
<td align="right"><?php
if ($val->DONOR_TYPE == 'BILATERAL') {
$sumBil += $val->COMMIT_CUR_AMT;
echo $val->COMMIT_CUR_AMT;
}
?></td>
<td align="right"><?php //reports::report1_5Forex($val->TRANSACTION_CURRENCY_CODE ,$val->VALUE_DATE) ?></td>
<td align ="right"></td>
</tr>
<?php $previousValue = $val->LOAN_ID ?>
<?php endforeach; ?>
</table>
<input type="button" value="Print" id="prt" onclick="javascript:printDiv('printablediv')" />
</div>
i got javascript code here:
<script language="javascript" type="text/javascript">
function printDiv(divID) {
var divElements = document.getElementById(divID).innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML =
"<body>" +
divElements + "</body>";
$('#prt').hide();
window.print();
$('#prt').show();
document.body.innerHTML = oldPage;
}
You should use thead and tbody to print the table header on each page http://www.w3.org/TR/html4/struct/tables.html#edef-THEAD
Table rows may be grouped into a table head, table foot, and one or
more table body sections, using the THEAD, TFOOT and TBODY elements,
respectively. This division enables user agents to support scrolling
of table bodies independently of the table head and foot. When long
tables are printed, the table head and foot information may be
repeated on each page that contains table data.
If this doesn't work, the browser vendors doesn't implement the standard correctly.
So here we go. I have a page that lists a bunch of unscored sports games. Here is the query I run to generate the page.
<div id="NFL">
<?php
foreach ($conn->query("SELECT * FROM game_data WHERE sport='NFL' AND awayscore IS NULL ORDER BY date DESC") as $NFL) {
echo '<form method="post" action="update_score.php">
<table class="table table-bordered">
';
echo '
<thead>
<tr>
<th width="5%" class="head0">Rotation</th>
<th width="45%" class="head1">Team</th>
<th width="10%" class="head0">Money Line</th>
<th width="10%" class="head1">Spread</th>
<th width="10%" class="head0">Over/Under</th>
<th width="10%" class="head1">Score</th>
</tr>
</thead>';
echo '
<tr>
<td colspan="6">
';
$date = date_create($NFL['date']);
echo date_format($date, 'l F jS Y \# g:iA');
echo '
</td>
</tr>';
echo '
<tr>
<td>'.$NFL['awayrotation'].'</td>
<td>'.$NFL['awayteam'].'</td>
<td>'.$NFL['awaymoneyline'].'</td>';
echo '
<td>
';
if ($NFL['awaymoneyline'] > 0) {
$line = $NFL['line'] * -1;
echo $line;
}
elseif ($NFL['awaymoneyline'] < 0) {
echo $NFL['line'];
} ;
echo '
</td>';
echo '
<td>'.$NFL['total'].'</td>
<td><input type="text" required name="awayscore"></input></td>
</tr>';
echo '
<tr>
<td>'.$NFL['homerotation'].'</td>
<td>'.$NFL['hometeam'].'</td>
<td>'.$NFL['homemoneyline'].'</td>';
echo '
<td>
';
if ($NFL['homemoneyline'] > 0) {
$line = $NFL['line'] * -1;
echo $line;
}
elseif ($NFL['homemoneyline'] < 0) {
echo $NFL['line'];
} ;
echo '
</td>';
echo '
<td>'.$NFL['total'].'</td>
<td><input type="text" required name="homescore"></input></td>
</tr>';
echo '
<tr><td colspan="6" align="right"><input type="hidden" name="id" value="'.$NFL['id'].'"><span style="padding-right:15px"><input type="submit" value="Submit Score"></span></td></tr>
</table>
</form>';
}
?>
</div>
This is what I'm looking to do, I would like to have a button to submit multiple forms. Only though if they have placed a value in the score. Is this possible? I have read about doing multiple forms based off names but these forms are being created dynamically. I look forward to your insight.
here try this
I placed a counter that increments by one per SQL result processed This will also be a key we will use later
The counter is now added to the end of the name fields of the inputs (in front of a "-" to be exploded later)
At the bottom of the script is a little code how I would handle the back end information
<?php
$count = "0";
echo '<form method="post" action="update_score.php"><table class="table table-bordered">';
foreach ($conn->query("SELECT * FROM game_data WHERE sport='NFL' AND awayscore IS NULL ORDER BY date DESC") as $NFL) {
$count = $count+1;
echo '<thead>
<tr>
<th width="5%" class="head0">Rotation</th>
<th width="45%" class="head1">Team</th>
<th width="10%" class="head0">Money Line</th>
<th width="10%" class="head1">Spread</th>
<th width="10%" class="head0">Over/Under</th>
<th width="10%" class="head1">Score</th>
</tr></thead>';
echo '<tr><td colspan="6">';
$date = date_create($NFL['date']);
echo date_format($date, 'l F jS Y \# g:iA');
echo '</td></tr>';
echo '<tr><td>'.$NFL['awayrotation'].'</td><td>'.$NFL['awayteam'].'</td><td>'.$NFL['awaymoneyline'].'</td>';
echo '<td>';
if ($NFL['awaymoneyline'] > 0) {
$line = $NFL['line'] * -1;
echo $line;
}
elseif ($NFL['awaymoneyline'] < 0) {
echo $NFL['line'];
} ;
echo '</td>';
echo '<td>'.$NFL['total'].'</td><td><input type="text" required name="awayscore-$count"></input></td></tr>';
echo '<tr><td>'.$NFL['homerotation'].'</td><td>'.$NFL['hometeam'].'</td><td>'.$NFL['homemoneyline'].'</td>';
echo '<td>';
if ($NFL['homemoneyline'] > 0) {
$line = $NFL['line'] * -1;
echo $line;
}
elseif ($NFL['homemoneyline'] < 0) {
echo $NFL['line'];
} ;
echo '</td>';
echo '<td>'.$NFL['total'].'</td><td><input type="text" required name="homescore-$count"></input></td></tr>';
echo '<tr><td colspan="6" align="right"><input type="hidden" name="id-$count" value="'.$NFL['id'].'"><span style="padding-right:15px">';
}
echo '<input type="hidden" name="count" value="$count">'
echo '<input type="submit" value="Submit Score"></span></td></tr></table></form>'
// back end
$counter = 0;
while ($counter++ < $_POST['count'])
{
$name = $_POST["name-$counter"];
$awayscore = $_POST["awayscore-$counter"];
$homescore = $_POST["homescore-$counter"];
$id = $_POST["id-$counter"]; // considering you may need to get rid of the count
$name = explode("-", $name);
$name = $name[0];
// ect ect
// enter in to data base
//clear all data in strings
}
?>
Sorry about that this was due to haters :|
more to the point yes the back end code is for your passer (the code the form is pointed at)
NB: your PHP style is older than what most use now, close to what I use - just check that all tutorials you use give you references to PHP 5.3 and when in doubt go to php.net and check the function calls for version use - syntax and alternate options