I have a table where I am displaying data from mysql. On the first column I have a checkbox. My php code is going to do something with the selected rows, but the problem is that my submit form doesn't work and i don't know why.
HTML code:
echo "<div class='container-fluid'>
<div class='table-responsive'>
<table class='fancyTable' id='myTable05'>
<thead>
<tr>
<th>Aviz</th>
<th>id</th>
<th>Denumire produs</th>
<th>Pret RON</th>
<th>U/M</th>
<th>Cantitate</th>
<th>Firma</th>
<th>Delegat</th>
<th>Mentiuni1</th>
<th>Mentiuni2</th>
<th>Cota TVA</th>
<th>Vsaloare</th>
<th>TVA</th>
<th>Facturat RON</th>
<th>Termen plata</th>
<th>Persoana contact</th>
<th>Pret ofertat</th>
<th>Reducere acordata</th>
<th>Nr comanda</th>
<th>Termen de livrare</th>
<th>Nr zile scadente ramase</th>
</tr></thead>";
while($row_comanda_afisare = mysqli_fetch_array($result_comanda_afisare)){
echo "<tbody><tr class='grid'>
<td>
<form action='includes/aviz.inc.php' method='post'>
<input type='checkbox' name='aviz_id[]' value='". $row_comanda_afisare['id']. "' />
</td>
<td>". $row_comanda_afisare['id']. "</td>";
echo "<td>". $row_comanda_afisare['denumire_produs']. "</td>";
echo "<td>". $row_comanda_afisare['pretRON']. "</td>";
echo "<td>". $row_comanda_afisare['U_M']. "</td>";
echo "<td>". $row_comanda_afisare['cantitate']. "</td>";
echo "<td>". $row_comanda_afisare['firma']. "</td>";
echo "<td>". $row_comanda_afisare['delegat']. "</td>";
echo "<td>". $row_comanda_afisare['mentiuni1']. "</td>";
echo "<td>". $row_comanda_afisare['mentiuni2']. "</td>";
echo "<td>". $row_comanda_afisare['cota_tva']. "</td>";
echo "<td>". $row_comanda_afisare['valoare']. "</td>";
echo "<td>". $row_comanda_afisare['tva']. "</td>";
echo "<td>". $row_comanda_afisare['facturatRON']. "</td>";
echo "<td>". $row_comanda_afisare['termen_plata']. "</td>";
echo "<td>". $row_comanda_afisare['persoana_contact']. "</td>";
echo "<td>". $row_comanda_afisare['pret_ofertat']. "</td>";
echo "<td>". $row_comanda_afisare['reducere']. "</td>";
echo "<td>". $row_comanda_afisare['nr_comanda']. "</td>";
echo "<td>". $row_comanda_afisare['termen_livrare']. "</td>";
//numarul de zile scadente
$sql_date = "SELECT DATEDIFF(termen_livrare, CURRENT_DATE) FROM comanda WHERE id=$row_comanda_afisare[id]";
$result_date = mysqli_query($conn, $sql_date);
while($row_date = mysqli_fetch_array($result_date)){
$zile_scadente = $row_date['DATEDIFF(termen_livrare, CURRENT_DATE)'];
}
echo '<td>'.$zile_scadente. '</td></tr>';
}
echo "<input type='submit' value='aviz'></form></tbody></table></div></div></div>";
?>
<script src="lib/jquery/jquery.min.js"></script>
<script src="js/jquery.fixedheadertable.js"></script>
<script>
$('#myTable05').fixedHeaderTable({
altClass: 'odd',
footer: true,
fixedColumns: 1,
});
</script>
</section>
The problem is that when i press on the submit button it is not taking me to the includes/aviz.inc.php file...does anyone know why?
Related
i am trying this from 5hrs don't know i am going wrong.My table echos results but not echo total for the same.
<table width="102%" border="0">
<tr>
<th><b>Amount</b></th>
<th ><strong>County</strong></th>
</tr><?php
(this fetches data ...$row = mysqli_fetch_array($res) or die(mysqli_error($db)))
echo "<tr>";
echo "<td>" . $price . "</td>";
echo "<td>" . $rui['county'] . "</td>";
echo "</tr>";
(I get these entreis correct )
}
}
(Below table is not echoed)
echo "<tr>";
echo "<td> .<b>Total </b>. </td>";
echo "<td>" .$x. "</td>";
echo "<td></td>";
echo "</tr>";
?></table>
Remove the } } after the closing tag of the tr.
if you can't close the whole PHP block then you probably did something wrong in your syntax.
I don't know if you have more code or not, if you do - post it so we will get more accurate view of your code.
<table width="102%" border="0">
<tr>
<th><b>Amount</b></th>
<th ><strong>County</strong></th>
</tr>
<?php
(this fetches data ...$row = mysqli_fetch_array($res) or die(mysqli_error($db)))
echo "<tr>";
echo "<td>" . $price . "</td>";
echo "<td>" . $rui['county'] . "</td>";
echo "</tr>";
(I get these entreis correct )
(Below table is not echoed)
echo "<tr>";
echo "<td> .<b>Total </b>. </td>";
echo "<td>" .$x. "</td>";
echo "<td></td>";
echo "</tr>";
}
?>
</table>
You can remove the wrong bracket, OR check that the two bracket are opened when fetching data
<table width="102%" border="0">
<tr>
<th><b>Amount</b></th>
<th ><strong>County</strong></th>
</tr><?php
//(this fetches data ...$row = mysqli_fetch_array($res) or die(mysqli_error($db)))
echo "<tr>";
echo "<td>" . $price . "</td>";
echo "<td>" . $rui['county'] . "</td>";
echo "</tr>";
//(I get these entreis correct )
//(Below table is not echoed)
echo "<tr>";
echo "<td> .<b>Total </b>. </td>";
echo "<td>" .$x. "</td>";
echo "<td></td>";
echo "</tr>";
?>
</table>
I am echoing to my website possible checkbox values that are in a table JobChoose like this
<?php
$got = mysql_query("SELECT * FROM JobChoose");
$checkbox = '';
while ($row = mysql_fetch_assoc($got)) {
$checkbox .= '<li><input type="checkbox" id="Jobselect" name="Job" value = "' . $row['Job'] . '">' . $row['Job'] . '</input></li>';
} ?>
<?php echo $checkbox;?>
When a checkbox is selected is inserted to a customer info.
But when i am trying to to get selected value back nothing appears when i click to a customer although it appears in mysql database
echo "<td align='center' class='hidden'>". $row["Job"] ."</td>";
<script type='text/javascript'>
$('#tabled').on('click', 'tr', function () {
$("#Jobselect").val($(this).find("td").eq(19).html());
});
</script>
Also i fetch search results into a table like this
<?php
$sql = "SELECT * FROM new_record WHERE surname LIKE
'%".$_POST["search"]."%' or name LIKE'%".$_POST["search"]."%' or
barcode LIKE'%".$_POST["search"]."%'"; $result =
mysqli_query($connect, $sql); if(mysqli_num_rows($result) > 0) {
while($row = $result->fetch_assoc()){
echo "<tr>";
echo "<td >". $row["id"] ."</td>";
echo "<td>". $row["surname"] ."</td>";
echo "<td>". $row["name"] ."</td>";
echo "<td>". $row["company_name"] ."</td>";
echo "<td>". $row["firm"] ."</td>";
echo "<td>". $row["address"] ."</td>";
echo "<td>". $row["town"] ."</td>";
echo "<td>". $row["tk"] ."</td>";
echo "<td>". $row["country"] ."</td>";
echo "<td>". $row["telephone"] ."</td>";
echo "<td>". $row["fax"] ."</td>";
echo "<td>". $row["mobile"] ."</td>";
echo "<td>". $row["mail"] ."</td>";
echo "<td>". $row["web_site"] ."</td>";
echo "<td>". $row["barcode"] ."</td>";
echo "<td>". $row["visitors"] ."</td>";
echo "<td align='center' class='hidden'>". $row["custId"] ."</td>";
echo "<td align='center' class='hidden'>". $row["trn_date"] ."</td>"; echo "<td align='center' class='hidden'>".
$row["HowToFindUs"] ."</td>"; echo "<td align='center'
class='hidden'>". $row["Job"] ."</td>";
echo "</tr>";
} } else {
echo 'Data Not Found'; } ?>
To get selected checkbox value you should try below code :
<?php
$got = mysql_query("SELECT * FROM JobChoose");
$checkbox = '';
while ($row = mysql_fetch_assoc($got)) {
$checkbox .= '<li><input type="checkbox" name="Job[]" value = "' . $row['Job'] . '">' . $row['Job'] . '</input></li>';
} ?>
<?php echo $checkbox;?>
Here in your case you have place id for all checkboxes are same which was not correct.
Also in JS you should try below code :
echo "<td align='center' class='hidden'>". $row["Job"] ."</td>";
<script type='text/javascript'>
$('input[type=checkbox]').click(function () {
if($(this).is(':checked')) {
alert($(this).val());
}
});
</script>
Please try this.
Solved !!!
I passed data to table with
echo "". $row["Job"] ."";
And then
$('input[type=checkbox]').each(function(){ var str =
$('#check').val(); var strarray = str.split(',');
if($.inArray($(this).val(),strarray)!=-1){
$(this).prop("checked","checked"); } else {
$(this).prop("checked",""); } });
I'm having a dynamic data which is stored in a table in HTML..Now I need a hyperlink or button in every row of the table.so that I should perform some operations.
for($i = 0; $i < $index_pointer; $i++)
{
echo '<tr>';
echo "<td>". $brands[$i]. "</td>";
echo "<td>". $models[$i]. "</td>";
echo "<td>". $years[$i]. "</td>";
echo "<td>". $categories[$i]. "</td>";
echo "<td>". $frames_size[$i]. "</td>";
echo "<td>". $frames_type[$i]. "</td>";
echo "<td>". $wheels_size[$i]. "</td>";
echo "<td>". $colors[$i]. "</td>";
echo "<td>". $genders[$i]. "</td>";
echo "<td>". $origins[$i]. "</td>";
echo "<td>"."<a href=""/>"."</td>";
echo '</tr>';
}
How to achieve this?
I'll delete this answer immediatly if this is not what you want or if this isn't the issue but is this what you want?:
for($i = 0; $i < $index_pointer; $i++)
{
echo '<tr>';
echo "<td>". $brands[$i]. "</td>";
echo "<td>". $models[$i]. "</td>";
echo "<td>". $years[$i]. "</td>";
echo "<td>". $categories[$i]. "</td>";
echo "<td>". $frames_size[$i]. "</td>";
echo "<td>". $frames_type[$i]. "</td>";
echo "<td>". $wheels_size[$i]. "</td>";
echo "<td>". $colors[$i]. "</td>";
echo "<td>". $genders[$i]. "</td>";
echo "<td>". $origins[$i]. "</td>";
echo "<td><a href='URL'>The text that's clickable</a></td>";
echo '</tr>';
}
Read more here: http://www.w3schools.com/tags/tag_a.asp
Try this.
mysql_connect("localhost", "root", "ameex") or die(mysql_error());
mysql_select_db("admin") or die(mysql_error());
$result =
mysql_query("SELECT * FROM details") or die(mysql_error());
echo "";
echo " TitleImageDescription"; $dir="images/";
while($row = mysql_fetch_array( $result )) {
echo "";
echo $row['title'];
echo "";
echo "<img src='$dir/$row[image]' width=100px height=100px><br>";
echo"</td><td>";
echo $row['description'];
echo '<td>Edit</td>
<td>Delete</td>';
echo "</td></tr>"; }
I have created a search function. It can find address by the full text but how do I go about to make the query search by parts of the address ? For e.g. the full address is paya lebar Road Blk27, how do I make it so that the user can just type in paya and it would still show up ?
SearchForm
<h2>View Patient Records</h2>
<body>
<form action="display_patient.php" method="post">
<p>Select:
<select name="patient_var" >
<?php
$value = array(view_all, name, address);
foreach ($value as $option)
{
echo '<option value="'.$option.'"' . (isset($_POST['patient_var']) && $_POST['patient_var'] == $option ? ' selected' : '') . '>' . $option . '</option>';
}
?>
</select>
<input type="text" name="typed" value="" />
<input type ="submit" value="submit" />
</form>
</p>
<p>
<?php
if (isset($_POST['patient_var'])) {
$type = $_POST['typed'];
$select = $_POST['patient_var'];
if ($select == 'view_all') {
echo "<table border='1'>";
echo "<tr>\n";
echo "<th>ID</th>\n";
echo "<th>Patient Name</th>\n";
echo "<th>Age</th>\n";
echo "<th>NRIC</th>\n";
echo "<th>Birth Date</th>\n";
echo "<th>Medical Allergies</th>\n";
echo "<th>Medical History</th>\n";
echo "<th>Phone</th>\n";
echo "<th>Address</th>\n";
echo "<th>Doctor Assigned</th>\n";
echo "</tr>";
$pat_set = default_patient();
while ($mo = mysqli_fetch_array($pat_set)) {
echo "<tr>";
echo "<td>" . $mo['id'] . "</td>";
echo "<td>". $mo['name'] . "</td>";
echo "<td>". $mo['age'] . "</td>";
echo "<td>". $mo['nric'] . "</td>";
echo "<td>". $mo['birthdate'] . "</td>";
echo "<td>". $mo['medical_allergies'] . "</td>";
echo "<td>". $mo['medical_history'] . "</td>";
echo "<td>". $mo['phone'] . "</td>";
echo "<td>". $mo['address'] ."</td>";
echo "<td>". $mo['doctor_assigned'] . "</td>";
echo "</tr>";
}
}
else {
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>ID</th>\n";
echo "<th>Patient Name</th>\n";
echo "<th>Age</th>\n";
echo "<th>NRIC</th>\n";
echo "<th>Birth Date</th>\n";
echo "<th>Medical Allergies</th>\n";
echo "<th>Medical History</th>\n";
echo "<th>Phone</th>\n";
echo "<th>Address</th>\n";
echo "<th>Doctor Assigned</th>\n";
echo "</tr>";
$patients_set =
find_patients($select, $type);
while ($row = mysqli_fetch_array($patients_set))
{ echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>". $row['name'] . "</td>";
echo "<td>". $row['age'] . "</td>";
echo "<td>". $row['nric'] . "</td>";
echo "<td>". $row['birthdate'] . "</td>";
echo "<td>". $row['medical_allergies'] . "</td>";
echo "<td>". $row['medical_history'] . "</td>";
echo "<td>". $row['phone'] . "</td>";
echo "<td>". $row['address'] ."</td>";
echo "<td>". $row['doctor_assigned'] . "</td>";
echo "</tr>"; }
}
}//end of if post submit
?>
</p>
In Mysql For searching whether a column has specific string use LIKE
Example
SELECT * FROM table WHERE column LIKE '%somestring%';
In your case just try this
$typed = $_POST['typed'];
and make Mysql query like this
$query = "select * from table where Address LIKE '%".$typed."%' ";
Use LIKE '%$searchParam%' instead of = $searchParam
You forgot to post your function: find_patients($select, $type);
But I guess you need a partial string query for an address varchar field which looks something like this:
select * from MyTable where myColumn like '%myPartialString%';
This type of query will return all rows that have "MyPartialString" within.
I am new to PHP and I have problem. I have a table with check boxes. I need to add if statement inside the check box.
echo "<div class='table1'>
<table>
<tr>
<td></td>
<td>Module code</td>
<td>Module Title</td>
<td>Option</td>
</tr>";
echo "<form action='confirmsubmission.php' method='post'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input type='checkbox' name='check[]'
value='".$row['module_id']."' />" . "</td>";
echo "<td>" . $row['module_id'] . "</td>";
echo "<td>" . $row['module_title'] . "<a href=# content='".$row['description']."'
class='tooltip'><span title='Module Description'><img src='images/i.png'/></span>
</a>". "</td>";
echo "<td>" . $row['module_choice'] . "</td>";
echo "</tr>";
}
echo "</table></div>";
Below is a If statement I need to add after value='".$row['module_id']."'
if($row['module_choice']=='Mandatory'){ echo "checked=\"true\""; }
A bit of a mouthful, but try:
...
echo "<td>" . "<input type='checkbox' name='check[]' value='".$row['module_id']."'".($row['module_choice']=='Mandatory' ? 'checked="true"' : "")." />" . "</td>";
...
Even though I'll advise you to use a templating system (Smarty, etc.), you can do the following code:
echo "<div class='table1'>
<form action='confirmsubmission.php' method='post'>
<table>
<tr>
<td></td>
<td>Module code</td>
<td>Module Title</td>
<td>Option</td>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input type='checkbox' name='check[]'
value='".$row['module_id']."'";
if($row['module_choice']=='Mandatory'){
echo " checked='checked' ";
}
echo "/>" . "</td>";
echo "<td>" . $row['module_id'] . "</td>";
echo "<td>" . $row['module_title'] . "<a href=# content='".$row['description']."'
class='tooltip'><span title='Module Description'><img src='images/i.png'/></span>
</a>". "</td>";
echo "<td>" . $row['module_choice'] . "</td>";
echo "</tr>";
}
echo "</table></form></div>";