I am making a table for booking time, I have put times as checkboxs, checboxs are all from one form, and I wand that user can select one checkbox and after submit the form, checkbox becomes unselectable or disappears from. I tried to validate if data is found on database and then make it disappear or unselecteble, but it was not successful.
my table looks like this:
http://i.imgur.com/hQdbl.jpg?1
Actually date and time come from another table on database. This is my php code for each check bos:
echo"
<input type='radio' name='datetime' value='". $row['day1']." ".$row['time1']."'>
<p>". $row['day1'] ,"</p><br/>". $row['time1'] ."
can you please help me :-\
If I got your question right you meant something like this?
if($_POST['datetime'] != ($row['day1'] . " " . $row['time1'])) {
echo"
<input type='radio' name='datetime' value='". $row['day1']." ".$row['time1']."' disabled>
<p>". $row['day1'] ,"</p><br/>". $row['time1'] ."
// etc
} else {
echo"
<input type='radio' name='datetime' value='". $row['day1']." ".$row['time1']."'>
<p>". $row['day1'] ,"</p><br/>". $row['time1'] ."
}
Related
I guess the title got complicated, I got a Userlist where a table shows users and it should get a option to delete the user. So I requested all users from the database, and placed them in a table, but a delete-button should be next to every user, to delete it. I would like to call the button-text "delete" but to gain the ID of the user, I thought of giving the value-attribute the database-id to send that value to the $_POST var.
This is what I made so far:
if ($con) {
$sql = "SELECT * FROM user ";
$ergebnis = $con->query($sql);
while ($zeile = $ergebnis->fetch_assoc())
{
echo "<table>
<tr><td><h4> User: " . $zeile["user"] . "</h4></td></tr>
<tr><td> <form action='admin.php' method='post'> <input type='submit' name='delete' value='" . $zeile["id"] . "'></td></tr> </form>
</table>";
}
}
The list as an image:
So every user has it's ID as an value, have a $_POST varaiable to work with. But of course, the text shouldn't be the value but something like "delete". Is there an alternative way to do it?
I hope you get my question..
Make your form as:
<form action='admin.php' method='post'>
<input type='submit' name='delete' value='Delete user'>
<input type='hidden' name='user_id' value='" . $zeile["id"] . "'>
</form>
<!-- Also not that first you close `form` and only then - `td-tr` -->
On server side you will have user id in $_POST['user_id'].
My table consists of 15 records which divided in 2 pages, however, those radio buttons in first page will not be checked as shown in image below.
Output
Here the code used in view page:
<?php foreach($rights->result() as $row){
echo "<label class='radio-inline'><input type='radio' name='rightRBtn[".$perm_id."]' value='$row->id'".(($row->id == $right_id) ? " checked='checked'":'')." />" . $row->description."</label>";
}?>
Browser source view shows the radio button box is actually checked too.
<td><label class='radio-inline'><input type='radio' name='rightRBtn[22]' value='0' checked='checked' />none</label><label class='radio-inline'><input type='radio' name='rightRBtn[22]' value='1' />view</label> </td>
Does anyone know what is the problem?
Simplify foreach() loop code by apply simple if-else and save yourself from some unnecessary quotes adjustment.
<?php foreach($rights->result() as $row){
if($row->id == $right_id){
echo "<label class='radio-inline'><input type='radio' name='rightRBtn[".$perm_id."]' value='$row->id' checked/>" . $row->description ."</label>";
}else{
echo "<label class='radio-inline'><input type='radio' name='rightRBtn[".$perm_id."]' value='$row->id'/>" . $row->description ."</label>";
}
}
?>
At my local end it's working:-
Code i used:-https://prnt.sc/ht9mzb (i just use json_decode and json_encode to make it stdclassobject array as you have)
output:-https://prnt.sc/ht9m1n
My workaround for this issue is to remove the responsive: true
$('#dataTables-example').DataTable({
// responsive: true
});
Basically I make a calculation and use a hidden value to put it into an input field.
So I've tried to recreate my problem in the code below as to not give away the actual code I'm working with since it's a bit more sensitive.
The question is whether it's possible to get the hidden value inside the disabled box without having to click the send button twice.
If I'm asking the impossible just say so I'll figure something out.
<form action='test.php' method='post'>
<?php
#$result = #$_POST['number1'] * #$_POST['number2'];
echo "<input type='text' name='number1'>
<input type='text' name='number2'>
<input type='text' value='"; if(isset($_POST['value'])) echo $_POST['value']; echo"' disabled>
<input type=hidden name='value' value='" . $result . "'>"
?>
<br>
<input type=submit>
</form>
do you expect the $result in the disabled input if the $_POST["value"] is not set?
echo "<input type='text' value='" .(isset($_POST['value'])?$_POST['value']:$result)."' disabled>";
I am trying to scale my table in PHP for a mobile web app, and i have quite a lot of fields echoed out.
Is there a neat way to style these as they are too far right at the minute
echo "<table cellspacing=\"0\" class=\"recordsTableBG\"> <thead class=\"recordsTableHeader\" >";
echo '<tr class="alternateRowColor">';
echo '<tr><th>id</th><th>amount</th><th>submission</th><th>project_id</th><th>status</th><th>description</th><th>delete</th></tr></thead>';
//echo "<form method='post' action=\"pmsystem.php?page=sentbox\">".
echo "<form method='post' action=\"viewrecordsemp1.php\">".
" <input type=\"hidden\" name=\"deleteMessage\" value=\"yes\">".
" <input type=\"hidden\" name=\"id\" value=\"$id\">".
"<td><b>$id </b> <br></td>".
"<td>$amount</a><br/></td>".
"<td>$submission</a><br/></td>".
"<td>$project_id</a><br/></td>".
"<td>$status</a><br/></td>".
"<td>$description</a><br/></td>".
" <input type=\"hidden\" name=\"thisPage\" value=\"$thisPage\">".
" <td> <input type=\"image\" src=\"images/delete.jpg\" alt=\"Delete contact\" onClick = \"return confirm('$first_name are you sure you want to delete this message?')\";></td>".
" </form>";
echo "</table>";
echo "<hr = '1'>";
I'm not exactly sure what data is in these fields, but you could echo maybe the 3 most essential columns and have the rest of the data put into an invisible <div> that takes up the screen. The <div> is unhidden when the entry is clicked and all the options are neatly displayed. This would mean you would have to have a separate set of PHP code to run on mobile, you have to keep the table format pretty much the same if you want to just do a mobile stylesheet.
But keep in mind that many mobile phone users use the phone horizontally to browse the web on non-mobile-specific sites. Unless your site is specifically designed for mobile or the text still goes offscreen in horizontal view, consider leaving it the way it is unless people are complaining.
For the last 4 hours I've been struggling to get something to work. I checked SO and other sources but couldn't find anything related to the subject. Here is the code:
<?php
$email=$_SESSION['email'];
$query1="SELECT * FROM oferte WHERE email='$email'";
$rez2=mysql_query($query1) or die (mysql_error());
if (mysql_num_rows($rez2)>0)
{
while ($oferta = mysql_fetch_assoc($rez2))
{
$id=$oferta['id_oferta'];
echo "<input type='radio' name='selectie' value='$id' id='$id'> <a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a>";
echo "</br>";
}
echo "</br>";
//echo "<input type=\"button\" id=\"cauta\" value=\"Vizualizeaza\" onclick=\"window.location.href='oferta.php?id={$oferta['id_oferta']}'\" />";
//echo " <input type=\"button\" id=\"cauta\"value=\"Modifica\" onclick=\"window.location.href='modifica.php?id={$oferta['id_oferta']}'\" />";
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
echo "</form>";
echo "</div>";
}
else
{
}
?>
The while drags all of the user's entries from the database and creates a radio button for each one of them with the value and id (because I don't really know which one is needed) equal to the entry's id from the db. I echoed that out and the id is displayed as it should so no problems there.
The delete script works ok as well so I won't attach it unless you tell me to. All good, no errors, until I try to delete an entry. Whatever I choose from the list of entries, it will always delete the last one. Note that I have two other inputs echoed out, those will be the "view" and "modify" buttons for the entry.
I really hope this is not JavaScript related because I have no clue of JS. I think this will be of major help to others having this problem. Please let me know if I need to edit my question before downrating. Thanks!
After edit:
This is the delete script, which as I said earlier works fine.
<?php
if (isset($_GET['id']))
{
$id = $_GET['id'];
echo $id;
require_once('mysql_connect.php');
$query = "DELETE FROM oferte Where id_oferta = '$id'";
mysql_query($query) or die(mysql_error());
//header('Location: oferte.php');
}
else
{
//header('Location: oferte.php');
}
?>
The session is started as well, like this:
<?php
session_start();
?>
The reason the last $id is deleted is because this line is outside/after the while loop:
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
You want to move this line inside the loop so that you have a button that executes delete for each radio button.
Update:
To have links to delete and
echo "<input type='radio' name='selectie' value='$id' id='$id'> ";
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a> ";
echo "<a href='delete.php?id=$id'>delete</a>";
Also I do not think the radio button is needed here at all since you are not really doing anything with it. You could simply echo out the value of your choice and have these links as follows:
echo $oferta['denumire_locatie'] . ' '; // replace $oferta['denumire_locatie'] with something of your choice
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a> ";
echo "<a href='delete.php?id=$id'>delete</a>";
echo "<br />";
The problem, in this case, is JavaScript related, yes. What I recommend you to do is to simply add a Remove link for each item.
echo "<a href='oferta.php?id={$oferta['id_oferta']}'>{$oferta['denumire_locatie']}</a>";
echo " - <a href='delete.php?id={$oferta['id_oferta']}'>Remove</a>";
echo "</br>";
Your $id is outside your while() loop.
The last one is getting deleted because the $id has the last one's value when the loops is exited.
Include all your code :
echo "</br>";
//echo "<input type=\"button\" id=\"cauta\" value=\"Vizualizeaza\" onclick=\"window.location.href='oferta.php?id={$oferta['id_oferta']}'\" />";
//echo " <input type=\"button\" id=\"cauta\"value=\"Modifica\" onclick=\"window.location.href='modifica.php?id={$oferta['id_oferta']}'\" />";
echo " <input type=\"button\" id=\"sterge\" value=\"Sterge\" onclick=\"window.location.href='delete.php?id=$id'\" />";
Inside your while loop.
When the rendered html reaches the browser, it will be something like this:
<input type='radio' name='selectie' value='1' id='1'> <a href='oferta.php?id=1'>TEXT</a>
<input type='radio' name='selectie' value='2' id='2'> <a href='oferta.php?id=2'>TEXT</a>
<input type='radio' name='selectie' value='3' id='3'> <a href='oferta.php?id=3'>TEXT</a>
<input type='radio' name='selectie' value='4' id='4'> <a href='oferta.php?id=4'>TEXT</a>
<br/>
<input type="button" id="sterge" value="Sterge" onclick="window.location.href='delete.php?id=5'" />
With this markup you won't be able to accomplish what you want without using javascript to update the onclick attribute whenever you select a radio button.
On the other hand, instead of using the client-side onclick event you can use the button's default behaviour, which is to submit the form.
You'll just have to set the action attribute:
<form method="post" action="http://myurl.php">
and write the myurl.php page which will just read the posted variable $_POST['selectie'] and call the delete method with the posted id.