problem with a page processed several times

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
lucapelle98
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Mar 08, 2018 2:56 am

Thu Mar 08, 2018 3:07 am

Hello to all, i'm an italian student and i have been studying php for a month.
My problems are:
1. Process the php page multiple times
2. exchange values from one combobox to another, for example the first combobox with the second one
I would need only one example, the rest i try to do it alone

I hope you answer me, thanks!

here is the code: (the comments of the code are in Italian)
<?php
include_once("daticonnessione.php");
$cn = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME);
if(!$cn)
{
//errore di connessione DB
echo "ATTENZIONE ERRORE DI CONNESSIONE AL DATABASE";
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body
{
background: white;
}
p
{
font: 15px Calibri;
}
table
{
table-layout: auto;
border-spacing: 10px;
border-collapse: separate;
border: 10px;
}
td
{
text-align: center;
}
</style>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Gestione frequenta</title>
</head>
<body>
<form class="form-horizontal" action="GestioneFrequenta.php">
<legend>Form Inserimento</legend>
<table>
<tbody>
<tr>
<td>
<div class="form-group">
<label class="col-md-4 control-label" for="select">Anno Scolastico</label>
<div class="col-md-4">
<select id="annoscol" name="selas" class="form-control" onchange="javascript: document.form.submit();">

<?php
$queryAS = mysqli_query($cn, "SELECT AnSc FROM iscritto");
//echo "<select name=\"select\">";
echo "<option value = '-1'> scegli</option value>";
while($res = mysqli_fetch_array($queryAS))
{
echo "<option value='{$res['AnSc']}'>{$res['AnSc']}</option>" ;
}
//$var = select.options[select.selectedIndex].value;
//echo "</select>";
?>
</select>
</div>
</div>
</td>
<!-- FUNZIONA -->




<td>
<div class="form-group">
<label class="col-md-4 control-label" for="select">Corso</label>
<div class="col-md-4">
<select id="select" name="select" class="form-control" onchange="Funzione1(this.value)">
<?php
//if(isset($var))
//{
if($_GET['selas'] != null)
{

$queryCorso = mysqli_query($cn, "SELECT Nome FROM corsi, iscritto WHERE corsi.Cod_C = iscritto.Cod_C AND iscritto.AnSc = ". tmp);
//echo "<select name=\"select\">";
echo "<option value = '-1'> scegli</option value>";
while($res = mysqli_fetch_array($queryCorso))
{
//visualizzazione nome dei corsi
echo "<option value='{$res['Nome']}'>{$res['Nome']}</option>" ;
}
//echo "</select>";
//}
//else
//{
//echo "<option value = '-1'>campo vuoto</option value>";
//}
}
else
{
echo "errore";
}
?>
<script>
function Funzione1()
{
var tmp = document.getElementById("select");
}
</script>
</select>
</div>
</div>
</td>

<td>
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Incontro</label>
<!--da gestire con i codici degli incontri -->
<div class="col-md-4">
<select id="selectbasic" name="selectbasic" class="form-control">
<?php
$queryNInc = mysqli_query($cn, "SELECT N_Inc FROM incontri, corsi WHERE incontri.Cod_C = iscritto.Cod_C AND corsi.Cod_C = ". $var);
echo "<select name=\"select\">";
echo "<option value = '-1'> scegli</option value>";
while($res = mysqli_fetch_array($queryNInc))
{
echo "<option value='{$res['Cod_I']}'>{$res['Cod_I']}</option>" ;
}
echo "</select>";
?>
</select>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Classe</label>
<!--caricare con classi -->
<div class="col-md-4">
<select id="selectbasic" name="selectbasic" class="form-control">
<?php
$queryClasse = mysqli_query($cn, "SELECT AnSc FROM Iscritto");
echo 'free user sql='.$queryAS.'<br>';
die();
echo "<select name=\"select\">";

while($res = mysqli_fetch_assoc($queryAS) or die ("non posso eseguire la query"))
{
echo "<option value=\"".$res['AnSc']."</option>";
}
echo "</select>";
?>
</select>
</div>
</div>
</td>
<td>
</td>
<td>
<div class="form-group">
<label class="col-md-4 control-label" for="selectbasic">Studente</label>
<div class="col-md-4">
<select id="selectbasic" name="selectbasic" class="form-control" onchange="">
<option value="1">Option one</option>
<option value="2">Option two</option>
<option value="3">Option three</option>
</select>
</div>
</div>
</tr>
<tr>
<td>


<td>
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Ore presenza</label>
<div class="col-md-4">
<input id="textinput" name="textinput" type="number" value="0" class="form-control input-md" >
</div>
</div>
</td>


</tr>

</table>

<!-- Bottone -->
<div class="form-group">
<div class="col-md-4">
<button id="singlebutton" name="singlebutton" class="btn btn-primary">Conferma</button>
</div>
</div>
</form>
</body>
</html>

chorn
php-forum Fan User
php-forum Fan User
Posts: 505
Joined: Fri Apr 01, 2016 2:18 am

Thu Mar 08, 2018 4:22 am

1. Process the php page multiple times
Just hit F5 or CTRL+R on your keyboard.
2. exchange values from one combobox to another
Just switch the statements.

User avatar
phpRob
New php-forum User
New php-forum User
Posts: 65
Joined: Mon Feb 26, 2018 7:15 am

Thu Mar 08, 2018 7:26 am

Sorry but most people don't have the time to go through all that code, clean it up, and solve it for you, which is why you've gotten these responses so far. You didn't bother to clean up you code before posting it to minimize the effort we'd have to take to help you. Please do some additional learning and investigation on your own, and don't be discouraged from coming back. We have to balance how far we will go to help someone, and make judgement calls about whether it's worth it. Make it worth it to be helped. I will make these quick additional observations...
--get rid of all the commented-out garbage
--format the code (submit using the "code" tags in your post)
--I did not see your Javascript (it could be muddled in there)
--the "for" property for an html label element is to reference the other element's "id" attribute--not the type of the element (not "select" or "input")

User avatar
zaim
New php-forum User
New php-forum User
Posts: 29
Joined: Sat Jan 06, 2018 9:05 am
Location: Kedah, Malaysia.

Thu Mar 08, 2018 8:01 am

Hello,

First of all, welcome!

It is a good practice that you have started your journey using a framework (Bootstrap). Trust me, you are doing well! (At some point, you might want to learn pure CSS too! You can make changes by your own if the framework has limited resource).

1. For your 'process the PHP page multiple times' is barely described. I could have wonder; "Eh? Maybe an 'onchange' event of JavaScript?", "You mean 'F5'?", etc. You could explain it with more details attached or visualize it using a picture or so.

2. You mean like, transfer the selected data from box A to box B, right? You could use array on that; First, assign all your data as an array then when a selected data is picked. Add the picked array to box B and delete it from box A. You can refer here to remove the selected array ( http://php.net/manual/en/function.unset.php ). Well, that's how I would do. I could just give you an idea but you might wanted to get the rest done on your own.

Cheers! :)

[EDIT]

For you labeling, it's actually incorrect. You see, each label must be pointed to an unique id attribute of each input. You can get an example from the documentation ( https://getbootstrap.com/docs/4.0/compo ... /#overview ).
Sorry if my answers aren't top notch but I will try my best to help anyone in need. :oops:

chorn
php-forum Fan User
php-forum Fan User
Posts: 505
Joined: Fri Apr 01, 2016 2:18 am

Thu Mar 08, 2018 11:05 pm

We have to balance how far we will go to help someone, and make judgement calls about whether it's worth it. Make it worth it to be helped.
Nice statement altogether. Maybe i'll try to share this next time.

Post Reply