Is there anyone who knows to duplicate a IF CONDITION through looping? Please. I really need your help.. This is my first time to encounter thing like this? Help will be appreciated thanks.
<?php
for($x=0; $fetchImageDirectoryRow = mysqli_fetch_assoc($fetchImageDirectory); $x++){
$directory = $fetchImageDirectoryRow['Image_Path'];
list($c, $apache24, $htdocs, $sp, $uploadItem, $imageFilename) = explode('/', $directory);
$uploadItem = $uploadItem."/".$imageFilename;
$imageGet = glob($uploadItem);
foreach($imageGet as $imagePath){
$attName = uniqid();
echo '<td>';
echo "<img src= '".$imagePath."' class='readyToPostImage'/><br><br>";
echo "<input type='text' placeholder='Enter New Price (eg. 300)' class='newPriceInput'/><br><br>";
echo "<a class='addMore'>add more photos</a>";
echo "<input type='file' class='browseCustom' multiple/><br>";
echo "<input type='submit' name='".$attName."' class='btn btn-success' value='Post to Peónline'/>";
echo '</td>';
How can I duplicate this IF Condition? Is there a function to copy the statement through looping.
if(isset($_POST[$attName])){
mysqli_query($connection, "UPDATE collateral c LEFT JOIN loan_assignment a ON (a.item_id = c.item_id) LEFT JOIN pawnshop b ON (a.pawnshop_id = b.pawnshop_id) SET c.post_status = '1' where status_type = 'FORECLOSED' and b.email_address = '".$login_session."' and image_path = '".$directory."';");
mysqli_close($connection);
}
}
}
?>
Related
pls help me..
im trying to input value with this code :
$attr_checklist = $flagTriwulan[$i] ? "hidden" : '';
echo "<td class='basicTable padding10 textCenter' style=\"font-size:13px;\"> <center>
<input type='radio' ".$attr_checklist." name='nilaikuantitatif[<?php echo [$i]; ?>]'
value='5'></center>
<br>".$skala5[$i]." </br>
</td>";
this when im submit :
if(isset($_POST['cmdSubmit']))
{
$aspek_a = $_POST['aspek_a'];
$nilaikuantitatif = $_POST['nilaikuantitatif'];
$multi = new MultipleIterator();
$multi->attachIterator(new ArrayIterator($aspek_a));
$multi->attachIterator(new ArrayIterator($nilaikuantitatif));
foreach($multi as $key => $value)
{
list($aspek_a, $nilaikuantitatif) = $multi->key();
list($aspek_a, $nilaikuantitatif) = $value;
$queryInsAspek = "insert into kpi_kuantitatif
(idDivisi,idDepartment,idEmployee,idPenilai,bulan,tahun
,aspek, nilaikuantitatif,submitBy, inputDT)
select".$idDivisi.",".$idDepartment.",".$idEmployee_C.",".$idEmployee.",".$bulan.",".$tahun.",'". $aspek_a."','".$nilaikuantitatif."',".$userID.", getdate()";
$resultInsAspek = sqlsrv_query($conn, $queryInsAspek);
}
so, i want if hidden then the value nilaiKuantitatif becomes 0, but if not hidden the value nilaiKuantitatif becomes 5
sorry for my bad english..pls help
Assuming that you mean you want the value in this code to be 0 in the event $attr_checklist == "hidden"...
$attr_checklist = $flagTriwulan[$i] ? "hidden" : '';
echo "<td class='basicTable padding10 textCenter' style=\"font-size:13px;\"> <center>
<input type='radio' ".$attr_checklist." name='nilaikuantitatif[<?php echo [$i]; ?>]'
value='5'></center>
<br>".$skala5[$i]." </br>
</td>";
Change this...
value=`5`
To...
value='<?php echo $attr_checklist == "hidden" ? 0 : 5; ?>'
issue for days now.
I have a form with multiple checkboxes, I will never know how many rows will be in the form, and I am aware that an empty checkbox will not post to the processing page. I have also tried providing a hidden value to the checkbox to no avail...
I know there is a straightforward method to this, please assist:
The following code is on the form:
echo "<td><center><input type='checkbox' checked='checked' name='jce_pnt_id[]' value='$jce_pnt_id' onclick='return false;' /><br>$jce_pnt_id</center></td>";
echo "<td title='Task Complete ?'><center><input type='hidden' name='tr_g[]' value='25'>";
if($jce_ins_complete < '100' || $jce_ins_act_complete == '0')
{
echo "<input type='checkbox' name='tr_g[]' id='$jce_pnt_id' value='100'>";
}
else
{
echo "<input type='checkbox' name='tr_g[]' id='$jce_pnt_id' value='100' checked='checked'>";
}
echo "</center></td>";
Here is a screenshot (look at the red circled column):
Here is the processing snippet (not working):
$jce_pnt_id = $_POST['jce_pnt_id'];
$tr_g = $_POST['tr_g']; // jce_pnt_act_complete
foreach ($tr_g as $id => $trg) {
//if(empty($trg)) { $trg = "0"; }
$queryg = "UPDATE `jce_pnt` SET `jce_pnt_act_complete` = '$trg' WHERE `jce_pnt_id` = '$jce_pnt_id[$id]'";
$resultg = mysqli_query($cxn,$queryg);
}
* The value writes to the wrong ID in the database.
I have this code now, but whenever I get to the page my entire text.txt file gets deleted. I am using sessions to get the information from a page from another php document. This is the 3rd page it directs to after information is input.
I would like choose which line to delete from the text file from an input form, but I cannot seem to get it working. Any suggestions? thanks
<?php
$tekstFil = fopen("test.txt","r");
$t = 0;
while (!feof($tekstFil)) {
$informasjonLinje = fgets ($tekstFil);
echo "$t : $informasjonLinje <br/>";
$t++;
}
fclose($tekstFil);
$fil = file("test.txt");
echo "<br/>";
echo "<form action='' type='get'>";
echo "Velg hvilken linje med informasjon du vil slette: ";
echo "<input type='number' name='linjeNummer' value=''>";
echo "<input type='submit' name='slett' value='slett'>";
echo "</form>";
if(isset($_GET["slett"])) {
echo "Du valgte å slette linje nummer: " . $_GET["linjeNummer"];
}
$linjeNummer = $_GET["linjeNummer"];
unset($fil[4]);
$fil = array_values($Fil);
$tekstFil = fopen("test.txt", "w");
foreach ($fil as $verdi) {
fwrite($tekstFil, $verdi);
}
fclose($tekstFil);
Please try this code. There could be much simpler ways but just modified your code
<?php
$tekstFil = fopen("test.txt","r");
$t = 0;
$buffer = array();
while (!feof($tekstFil)) {
$informasjonLinje = fgets ($tekstFil);
$buffer[] = $informasjonLinje;
echo "$t : $informasjonLinje <br/>";
$t++;
}
fclose($tekstFil);
$fil = file("test.txt");
echo "<br/>";
echo "<form action='' type='get'>";
echo "Velg hvilken linje med informasjon du vil slette: ";
echo "<input type='number' name='linjeNummer' value=''>";
echo "<input type='submit' name='slett' value='slett'>";
echo "</form>";
if(isset($_GET['slett'])) {
echo "Du valgte å slette linje nummer: " . $_GET["linjeNummer"];
$linjeNummer = $_GET["linjeNummer"];
//unset($fil[4]);
//$fil = array_values($Fil);
$tekstFil = fopen("test.txt", "w");
unset($buffer[$linjeNummer]);
$buffer1 = implode("", $buffer);
fwrite($tekstFil, $buffer1);
fclose($tekstFil);
}
unset($buffer);
?>
Please try not to reload the page since you're used GET method.
this is my another problem, thi is my code:
for($d = 0; $d < $cnt; $d++){
$fetchit = mysql_query("SELECT * FROM ar_subkategori WHERE id_subkategori = $detail_sub[$d]");
$datafetch = mysql_fetch_array($fetchit);
$id_values = $datafetch['id_subkategori'];
if ($id_values == $getsubsel['id_subkategori']){
echo "<input type='checkbox' name='checkbox[]' id='checkbox' value='$getsubsel[id_subkategori]' checked> <span style='font-size:10px; color:#FFA412;'>[ID: $getsubsel[id_subkategori]]</span> $getsubsel[nama_subkategori] <span style='color:#FFA412; font-style:italic; font-size:12px;'>*Ini adalah sub dari ID: $getsubsel[id_subkategori_induk]</span></br>";
}
}
if ($id_values != $getsubsel['id_subkategori']){
echo "<input type='checkbox' name='checkbox[]' id='checkbox' value='$getsubsel[id_subkategori]'> <span style='font-size:10px; color:#FFA412;'>[ID: $getsubsel[id_subkategori]]</span> $getsubsel[nama_subkategori] <span style='color:#FFA412; font-style:italic; font-size:12px;'>*Ini adalah sub dari ID: $getsubsel[id_subkategori_induk]</span></br>";
}
The problem is the value form $id_values is always show ID = 30, while that the value should be show is 1, 5, 10, 30. How to fix it?
Thanks before, Salam..
If you want an array variable to be shown inside "" you must surrond it with {} like this:
"{$getsubsel['id_subkategori']}"
That's why you are seeing the variable name instead of it value.
May be this ..
$fetchit = mysql_query("SELECT * FROM ar_subkategori WHERE id_subkategori = $detail_sub[" . strval($d) . "]");
or
$fetchit = mysql_query("SELECT * FROM ar_subkategori WHERE id_subkategori = $detail_sub['{$d}']");
try like this
$fetchit = mysql_query("SELECT * FROM ar_subkategori WHERE id_subkategori = '".$detail_sub[$d]."'");
I am really having a hard time figuring out why if(isset($_POST['next'])) isn't working. How can I call something like that within a function?
function questions($result){
$options = array('A','B','C','D','E');
echo "Please click 'Next'";
echo "<p class = 'button'><input type='submit' name='next' value='Next'/></p>";
while($row = $result->fetch_assoc()){
if(isset($_POST['next'])) {
echo "<h4>".$row['question']."</h4>";
foreach($options as $option){
$text = $row[$option];
if($text)
echo "<br/><input type = 'radio' name = 'ans' value = '$option'>".$text."<br/>";
}
echo "<p class = 'button'><input type='submit' id='submit' class = 'answer' name='submitAns' value='Submit' /></p>";
if(isset($_POST['submitAns'])){
$answer = $row['answer'];
if($_POST('ans') == $answer) {
echo "<h4>Correct!</h4>";
} else {
echo "<h4>Incorrect. Correct answer is: ".$answer."</h4>";
}
echo "<p class = 'button'><input type='submit' id='next' name='next' class = 'answer' value='Next' /></p>";
}
}
}
if(isset($_POST['next'])){
echo "End of questions for this exam";
}
}
Checking to see if a variable exists (isset) and checking to see whether a variable actually contains something (empty) are two different things. Try this:
function questions($result){
$options = array('A','B','C','D','E');
echo "Please click 'Next'";
echo "<p class = 'button'><input type='submit' name='next' value='Next'/></p>";
while($row = $result->fetch_assoc()){
if($_POST && isset($_POST['next']) && !empty($_POST['next'])) {
// ....
}