My table is not filling all the data i need. Is missing some columns be filled with form multiple. The column where the th is Renault need to be the same for all the rest are empty.
In next picture, you can see when i select options in dynamic selectbox multiple and submit, is only filling in the first column when the expectable is fill all the columns selected.
Next is the code where is giving the value of the select box multiple.
if ($consulta !=0) {
}//
else{
echo "";
}
#$s1= $_POST['s1'];
if( is_array($s1)){
while (list ($key, $val) = each ($s1)) {
}
}//
else{
echo "";
}
/////////////////
#$s2= $_POST['s2'];
if( is_array($s2)){
?>
Next is the code where data is filled in the html table. That line of code<td align=\"center\" bgcolor='FFFFFF'> need to be associate the result of: <?php echo "$key => $val1\n";?> to which form:
The result of <?php echo "$key => $val1\n";?>
0 => Renault 1 => Opel 2 => Mercedes 3 => Audi
The expected output is missing.
Renault
<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">
Opel
<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">
Mercedes
<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">
Audi
<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">
That is dynamic, will get the values from mysql database and i can select which i want.
There is all the table where is filled the data. Static and dynamic.
<table>
<tbody>
<tr>
<th>Parametro:</th>
<?php
while (list($key, $val1) = each ($s2)) {
?>
<th><?= htmlspecialchars($val1, ENT_HTML5 | ENT_COMPAT, 'UTF-8') ?></th>
<?php
echo "$key => $val1\n";
?>
<?php
}
?>
The values down of the Parametro:
{
echo("<tr>
<td align=\"center\" bgcolor='FFFFFF'>$utilizador</td>
<td align=\"center\" bgcolor='FFFFFF'>
<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">
");
Code from the form:
$con = mysqli_connect( "localhost","root","","teste" ); // ◄■ CONNECT TO DATABASE.
$dat_menuid = mysqli_query( $con,"SELECT * FROM menu WHERE menuId = '".$menuId."'" ) // ◄■ MENUIDs.
or die( mysqli_error($con) );
$con1 = mysqli_connect( "localhost","root","","teste" ); // ◄■ CONNECT TO DATABASE.
$idtem = mysqli_query($con1, "SELECT MAX(id_tem) as id_tem FROM tem")
or die( mysqli_error($con) );
// Print out result
while($row = $idtem->fetch_assoc())
$toEcho = $row["id_tem"];
//echo $toEcho;
$toEchosave = $toEcho + 1;
$_SESSION['myvar'] = $toEchosave;
$options = array( "0.00","0.05","0.10","0.15","0.20","0.25","0.30","0.35","0.40","0.45","0.50","0.55","0.60","0.65","0.70","0.75","0.80","0.85","0.90","0.95","1" ); // ◄■■ OPTIONS ARE STATIC (ALWAYS THE SAME).
while ( $row_menuid = mysqli_fetch_array( $dat_menuid ) ) // ◄■ DISPLAY <SELECT>s.
{ echo "<select class='sumselect' name='corp_resp&{$row_menuid['menuId']}&{$_SESSION['UtilizadorID']}&{$dateTime}&{$toEchosave}' multiple>"; // ◄■■ CORP_RESP&1,CORP_RESP&2.
foreach ($options as $opt)
echo "<option value='$opt'>$opt</option>\n";
echo "</select>\n";
} ?>
</form>
</td>
</tr>
<?php } ?>
<?php }
}
}
?>
<div id='sum'></div>
<br><br><br>
</tbody>
</table>
follow this code
<?php
$sql = "SELECT * FROM menu WHERE $id = menuIdPai ORDER BY menuId ";
$consulta = mysql_query($sql);
while ($mostrar = mysql_fetch_array($consulta)) {
$id = $mostrar['menuId'];
$utilizador = $mostrar['menuNome'];
?>
<tr>
<td align=\"center\" bgcolor='FFFFFF'>Test1</td>
<td align=\"center\" bgcolor='FFFFFF'>Test2</td>
<td align=\"center\" bgcolor='FFFFFF'>Test3</td>
<td align=\"center\" bgcolor='FFFFFF'>Test4</td>
</tr>
<?php
}
?>
this is main format if work then update your code . you add 2 td but your main th 4 so need 4 td
your this tag not close
<td align="center" bgcolor='FFFFFF'>
<form onsubmit="return validate();" id="teste" method="post" action="teste.php">
so close this in your script
<div id='sum'></div>
<br><br><br>
</form>
</td>
</tr>
move this code before end loop
foreach ($options as $opt)
echo "<option value='$opt'>$opt</option>\n";
echo "</select>\n";
} ?>
</form>
</td>
</tr>
<?php } ?>
<?php }
}
}
?>
<div id='sum'></div>
<br><br><br>
</tbody>
</table>
Related
I need suggestion.
I have an list of position from database, displayed in table and in the last table row is an option to select "TAK" - YES and "NIE" - NO, please tell me is it possible and if it, how to send and receive it all selected to "TAK" fields at file wypozyczalnia.php
<form action='wypozyczalnia.php' method='post'>
<table width="1000px" align="center" border="1">
<tr>
<th width="250px">Tytuł</th>
<th width="250px">Autor</th>
<th width="300px">Opis</th>
<th width="200px">Dostępność</th>
</tr>
<?php
//sprawdzanie czy taka zmienna jest ustawiona w sesji, jest to dla nowo wchodzących na stronę
if(isset($_SESSION['blad'])) echo $_SESSION['blad'];
//wyświetlanie wyników gdy zmienna ile zwróciła przynajmniej 1 rząd
if ($ile>=1)
{
//pętle wyświetlająca wszystkie zwrócone z zapytania wpisy
for ($i = 1; $i <= $ile; $i++)
{
//pobranie rzędu jako tablicę asocjacyjną
$row = mysqli_fetch_assoc($rezultat);
//przypisanie każdej kolumny do odpowiedniej zmiennej
$title = $row['title'];
$author = $row['author'];
$description = $row['description'];
$available = $row['available'];
echo
"<tr>
<td> ".$title." </td>
<td> ".$author." </td>
<td> ".$description." </td>
<td>";
if($available==1)
{
echo "TAK";
}
else
{
echo "NIE";
}
"</td>
</tr>";
if(isset($_SESSION['zalogowany']) && ($_SESSION['zalogowany']==true) && $available==1)
{
echo
"<select name='idksiazki[]' >
<option name='NIE'>NIE</option>
<option name='TAK'>TAK</option>
</select>";
}
}
}?>
</table>
<?php
if(isset($_SESSION['zalogowany']) && ($_SESSION['zalogowany']==true))
{
echo "<br /> <input type='submit' name='zapis' value='wypożyczam'></form>";
}
?>
</form>
At the moment you have multiple forms - one per table row, so each <select is inside its own form. You can't submit multiple forms at once from a HTML page. Also your existing forms seem to be missing the </form> tag so they will be invalid anyway.
Therefore, to be able to submit all the <select values at the same time, you need a single form, which has the entire table contained within it.
For example:
<form action='wypozyczalnia.php' method='post'>
<table>
<?php
if ($ile>=1)
{
//pętle wyświetlająca wszystkie zwrócone z zapytania wpisy
for ($i = 1; $i <= $ile; $i++)
{
//pobranie rzędu jako tablicę asocjacyjną
$row = mysqli_fetch_assoc($rezultat);
//przypisanie każdej kolumny do odpowiedniej zmiennej
$title = $row['title'];
$author = $row['author'];
$description = $row['description'];
$available = $row['available'];
echo
"<tr>
<th> ".$title." </th>
<th> ".$author." </th>
<th> ".$description." </th>
<th>";
if($available==1)
{
echo "TAK";
}
else
{
echo "NIE";
}
"</th>";
if(isset($_SESSION['zalogowany']) && ($_SESSION['zalogowany']==true) && $available==1)
{
echo "<th>
<select name='idksiazki[]' >
<option value=$i;>NIE</option>
<option value=$i;>TAK</option>
</select>
</th>";
}
echo "</tr>";
}
}
?>
</table>
</form>
P.S. A note about HTML semantics: <th> is mean to indicate a table heading, e.g. the title of a column, or the main heading within a row. It should not be used for every cell in your table. <td> is for normal table cells. If you wish to make the text bold, use CSS instead.
I am new to PHP, hoping for some help please.
I am trying to populate an HTML dropdown list with data from my SQL database.
I would like to be able to select an item from a dropdown list that would then fill an HTML table with the associated record from the database.
So far I have managed to connect to my database and retrieve all of the data from the relevant table.
Can someone please help me set this up to work through the dropdown list?
Thanks
<?php
$username = 'root';
$password = '';
$conn = new PDO( 'mysql:host=localhost; dbname=Oaktown', $username, $password );
$sql ="SELECT RoundNumber, RoundDate, HomeTeam, HomeTeamScore, AwayTeam, AwayTeamScore FROM Fixture";
$statement = $conn->prepare( $sql );
$statement->execute();
$results = $statement->fetchAll( PDO::FETCH_ASSOC );
?>
<h2>Competitions</h2>
<article>
<p id="TableHeader1">Fixture Information</p>
<P>Select Round and Game number from the dropdown list under Round Number.</P>
<br>
<br><form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<p id="TableHeader2">Round Number
<select style="width:250px"></select> <input class="button"
type="submit" name="Get" value="Get Fixture Results"></p>
<p id="TableHeader2">Results</p>
<table class="table">
<tr><td><b>Round Number:</b></td>
<?php foreach( $results as $row ){
echo "<td>";
echo $row['RoundNumber'];
}
?>
</tr>
<tr>
<td><b>Round Date:</b></td>.
<?php foreach( $results as $row ){
echo "<td>";
echo $row['RoundDate'];
}
?>
</tr>
<tr>
<td><b>Home Team:</b></td>
<?php foreach( $results as $row ){
echo "<td>";
echo $row['HomeTeam'];
}
?>
</tr>
<tr>
<td><b>Home Team Score:</b></td>
<?php foreach( $results as $row ){
echo "<td>";
echo $row['HomeTeamScore'];
}
?>
</tr>
<tr>
<td><b>Away Team:</b></td>
<?php foreach( $results as $row ){
echo "<td>";
echo $row['AwayTeam'];
}
?>
</tr>
<tr>
<td><b>Away Team Score:</b></td>
<?php foreach( $results as $row ){
echo "<td>";
echo $row['AwayTeamScore'];
}
?>
<td colspan="2><?php echo $message; ?>"></td>
</tr>
</table>
</form>
Using a similar block of code like the one you use for the tables you can do something like this:
<select>
<?php foreach( $results as $row ){
echo "<option value='" . $row['value column'] . "'>" . $row['text column'] . "</option>";
}
?>
</select>
if you don't have or need a pair of values then you can simply do this:
<select>
<?php foreach( $results as $row ){
echo "<option>" . $row['text column'] . "</option>";
}
?>
</select>
My purpose is search book type from input keyboard and count it. I have error: counting the number of book is right but when print, it miss some result. For example, I put 'f' it show 7 result( right) however it print only 2 two result. Here is my code:
<form action="" method="POST">
Enter type of book here:<input type="text" size="20" name="sbt"> <br />
<input type="submit" name="sb" value="Search">
</form>
<table align="center" border="1" width="600">
<thead><tr align="center">
<tr align="center">
<td><b>Book ID</b></td>
<td><b>Book Title</b></td>
<td><b>Book Author</b></td>
<td><b>Pulished Year</b></td>
<td><b>Book Type</b></td>
<td><b>Status</b></td>
</tr>
<?php
if (isset($_POST['sb'])) {
$s="";
if ($_POST['sbt'] == null) {
echo "Please re-enter <br>";
} else
{
$s = $_POST['sbt'];
}
$q = "SELECT * FROM book WHERE book_type LIKE '%$s%' ";
$r= mysqli_query($conn,$q);
while($row = mysqli_fetch_array($r)) {
?>
<tr align="center">
<td><?php echo $row['book_no'];?></td>
<td><?php echo $row['book_title'];?></td>
<td><?php echo $row['book_author'];?></td>
<td><?php echo $row['book_year'];?></td>
<td><?php echo $row['book_type'];?></td>
<td>
<?php
if ($row['book_quantity'] == 1) {
echo "Available";
}
else {
echo "Not available";
}
?>
</td>
<?php
$c=" SELECT COUNT(DISTINCT(book_no)) AS totaltype FROM book WHERE book_type LIKE '%$s%'";
$s= mysqli_query($conn, $c);
if (mysqli_num_rows($s)> 0 )
{
$row2= mysqli_fetch_array($s);
echo " Total book type result:"."{$row2['totaltype']}";
}
}
?>
<?php } ?>
</table>
Remove "%" before $s and try.
for example:
$query = mysql_query("SELECT * FROM table WHERE the_number LIKE '$yourPHPVAR%'");
Insert Is Fine But if I select this value from database All Values are fine but single values fetch array problem I don't know how to solve this task. Please Update this code asap.
This Is Insert Code .....
<?php
if(isset($_POST['sendmessage'])){
$entermessage = $_POST['teachermessage'];
$checkbox_user = $_POST['usernameallcheckbx'];
$arr = implode(',',$checkbox_user);
//$arr2 = explode(',',$arr);
$insert = mysql_query("INSERT into usermessages(fromteacher,toparent,messages) VALUES('".$_SESSION['username']."','$arr','$entermessage')");
if($insert == 1){
echo "<h1>successful</h1>";
}
else{
echo mysql_error();
}
}
?>
<form method="post">
<div style="float:left; width:450px;"><br/><br/>Message: <br/>
<textarea style="width:400px; height:300px;" name="teachermessage"></textarea><br/>
<input type="submit" value="Send" name="sendmessage" /></div>
<div style="float:left; with:200px; padding-top:55px;">
<table>
<tr>
<?php
$select_query1 = mysql_query("SELECT * FROM register_user WHERE teacher='$teachername'");
while($chckbx=mysql_fetch_array($select_query1))
{
?>
<td><?php echo "<input type='checkbox' name='usernameallcheckbx[]' value=". $chckbx['userid']." />"; ?></td>
</tr>
<tr>
<td><?php echo $chckbx['parent_fname']." ".$chckbx['parent_lname']; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</form>
And This Is Select Code....
<h2>Messages</h2>
<?php
$select_query3 = mysql_query("SELECT * FROM usermessages");
$fetch= mysql_fetch_array($select_query3);
$data=$fetch['toparent'];
$arr=explode(',',$data);
//$userids=explode(',',$data);
$sessionshow=$_SESSION['userid'];
$userids=in_array("$sessionshow",$arr);
$select_query2 = mysql_query("SELECT * FROM usermessages WHERE toparent in ('$userids')='".$_SESSION['userid']."'");
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Teacher Name</th>
<th>Message</th>
</tr>
<?php
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo "<tr>";
echo "<td>".$fetch_data=$fetch_name2['fromteacher']."</td>";
echo "<td>".$fetch_data=$fetch_name2['messages']."</td>";
echo "</tr>";
}
?>
</table>
I have only put this as an answer to show some incorrect code - remove fetch data from your loop as it doesn't do anything
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo "<tr>";
echo "<td>".$fetch_name2['fromteacher']."</td>";
echo "<td>".$fetch_name2['messages']."</td>";
echo "</tr>";
}
even better is use of a HEREDOC:
while($fetch_name2=mysql_fetch_array($select_query2))
{
echo <<<EOF
<tr>
<td>{$fetch_name2['fromteacher']}</td>
<td>{$fetch_name2['messages']}</td>
</tr>
EOF;
}
I really can't figure out what you're trying to do, but maybe this is the query you want:
SELECT * FROM usermessages WHERE FIND_IN_SET('$sessionshow', toparent)
FIND_IN_SET(str, strlist) searches the comma-separated list in strlist for an element that equals str, and returns the position in the list; if it's not found it returns 0, which counts as false.
I can't see any purpose to any of the code that uses $select_query3.
I have an html page that gets data from 'hs_hr_employee' table and lays the info in a table on a web page. Then I have another table 'rights' which gets info from 4 columns from the 'hs_hr_employee' table and stores them in columns. In addition to those 4, the 'rights' table has an extra column 'Permissions'.
Now, I have a combobox with 4 options. When I click the 'Save' button I want to store the value select in the combobox and save it in the 'rights' table in relation to the user.
(Each user has a combobox next to it).
Updated code:
<?php
$connection = mysql_connect('localhost','admin','root');
if( isset($_POST['submit']) )
{
if( isset( $_POST['cb_permissions'] ) && is_array( $_POST['cb_permissions'] ))
{
foreach( $_POST['cb_permissions'] as $emp_number => $permission)
{
$sql = "UPDATE `your_permission_table` SET permission='".mysql_real_escape_string($permission)."' WHERE emp_number='".mysql_real_escape_string($emp_number)."'";
echo __LINE__.": sql: {$sql}\n";
mysql_query( $sql );
}
}
}
?>
<p style="text-align: center;">
<span style="font-size:36px;"><strong><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 128, 128);">File Database - Administration Panel</span></span></strong></span></p>
<p style="text-align: center;">
</p>
<head>
<style type="text/css">
table, td, th
{
border:1px solid #666;
font-style:Calibri;
}
th
{
background-color:#666;
color:white;
font-style:Calibri;
}
</style>
</head>
<form method="post" action="admin.php">
<?php
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('users', $connection);
$result = mysql_query("SELECT emp_number, employee_id, emp_lastname, emp_firstname FROM hs_hr_employee");
echo "<center>";
echo "<table >
<tr>
<th>Employee Number</th>
<th>Employee ID</th>
<th>Surname</th>
<th>Name</th>
<th>Permissions</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['emp_number'] . "</td>";
echo "<td>" . $row['employee_id'] . "</td>";
echo "<td>" . $row['emp_lastname'] . "</td>";
echo "<td>" . $row['emp_firstname'] . "</td>";
echo "<td> <select name='cb_permissions['".$row['emp_number']."'><option value='all'>All</option> <option value='remote'>Remote Gaming</option> <option value='landbased'>Landbased Gaming</option> <option value='general'>General Gaming</option> </select> </td>";
echo "</tr>" ;
}
echo "</table>";
echo "</center>";
echo mysql_query('INSERT into rights(Emp_num, ID, Name, Surname) SELECT emp_number, employee_id, emp_firstname, emp_lastname FROM hs_hr_employee');
$_POST['cb_permissions'];
mysql_close($connection);
?>
<p style="text-align: center;">
</p>
<p style="text-align: center;">
</p>
<p style="text-align: right;">
<input name="Save_Btn" type="button" value="Save" />
</p>
</form>
Any help on how I can do it?
Screenshot to get a basic idea of what I'm doing:
First of all, you should move connection code at the very top of your documents:
$connection = mysql_connect('localhost','admin','root');
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('users', $connection);
Next, you have to wrap your table inside tag:
<form method="post" action="target_url.php>
<table>
...
</table>
<input type="submit" name="submit" value="Save"/>
</form>
After that, you would store employee_id or emp_number (depending on what table key you will use for setting permission) somewhere on your form:
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['emp_number']; ?></td>
<td><?php echo $row['employee_id']; ?></td>
<td><?php echo $row['emp_lastname']; ?></td>
<td><?php echo $row['emp_firstname']; ?></td>
<td><select name="cb_permissions['<?php echo $row['emp_number']; ?>']">
<option value='all'>All</option>
<option value='remote'>Remote Gaming</option>
<option value='landbased'>Landbased Gaming</option>
<option value='general'>General Gaming</option>
</select></td>
</tr>
<?php
}
Then, on your target_url.php, you will have to do:
If target_url.php is the same as your form, then code below should be placed at the very top of your document.
<?php
if( isset($_POST['submit']) )
{
if( isset( $_POST['cb_permissions'] ) && is_array( $_POST['cb_permissions'] ))
{
foreach( $_POST['cb_permissions'] as $emp_number => $permission)
{
$sql = "UPDATE `your_permission_table` SET permission='".mysql_real_escape_string($permission)."' WHERE emp_number='".mysql_real_escape_string($emp_number)."'";
echo __LINE__.": sql: {$sql}\n";
mysql_query( $sql );
}
}
}
?>
That's it.
i suggest:
Use require_once( "db_connect.php" ) <- in this file make connection
Use smarty & html_options to show this drop down.
1 time your will learn this, next - using. Code will start be organized ...
Maybe to complex for starter. But this is right Way.