how to use rewrite url using htaccess for the following code - javascript

index to intermediate file is going well but it does not pass to statefinder file, please someone help me, its give error 'Object not found!' while the URL is right which are - 'bank-details/Abhyudaya-Cooperative-Bank-Limited'.
Please tell me what is I doing wrong
index.php
<script>
$('#bank_name').change(function(){
$('#form1').submit();
});
</script>
<?php
$res = mysqli_query($conn,$sql);
echo '<div id="div3">';
echo '<form id="form1" method="get" action="imtermediate1.php">';
echo '<img src="images/2.png" style="margin-left:30px">';
echo '<select id="bank_name" name="bank_name">';
echo '<option value="">SELECT BANK NAME</option>';
while($r = mysqli_fetch_array($res))
{
//echo $r['bank_name'];
$name = $r['bank_name'];
$name2 = explode(" ",$name);
//$name3 = implode($name2,'.');
$name5 = "";
for($i = 0; $i<count($name2); $i++)
{
$name3 = $name2[$i];
$name4 = ucfirst(strtolower($name3));
$name5 .= $name4;
}
echo '<option value="'.$name5.'">'.$name.'</option>';
}
imtermediate1.php
<?php
$name = $_GET['bank_name'];
$pieces = preg_split('/(?=[A-Z])/',$name);
$pieces2 = implode($pieces,"-");
$piece3 = ltrim($pieces2,"-");
?>
<script>
var name = "<?php echo $piece3;?>";
window.location = "./" + name;
</script>
statefinder.php
<script>
$('#state').change(function(){
$('#form2').submit();
});
</script>
<?php
$name = $_GET['bank_name'];
$pieces = strtoupper($name);
$piece2 = explode("-",$pieces);
$piece3 = implode($piece2," ");
echo '<form id="form2" method="get" action="imtermediate2.php">';
echo '<img src="images/3.png"><select name="bank_name">';
echo '<option value="'.$name.'">'.$piece3.'</option>';
echo '</select><img src="images/4.png"><br>';
$sql = "SELECT DISTINCT state FROM `TABLE 6` WHERE bank_name='$piece3' ORDER BY state ";
echo '<img src="images/2.png"><select name="state" id="state"><option>Select State Name</option>';
$res = mysqli_query($conn,$sql);
print_r($res);
while($r = mysqli_fetch_array($res))
{
echo '<option>'.$r['state'].'</option>';
}
echo '</select><img src="images/5.png"><br>';
echo '<img src="images/2.png" style="margin-left:-28px"><select><option>District</option></select><br>';
echo '<img src="images/2.png" style="margin-left:-28px"><select><option>Branch</option></select><br>';
echo '</form>';
?>

Related

how to insert both value and content of dropdown select into database?

i want to insert both value and content of dropdown select into a database table. i can insert the value with no problem but i have no idea how to insert the content. i've been searching similar questions and probably it can be done by adding javascript. but i haven't learned about that yet so i have no clue how to use it.
<form action="hitung.php" method="POST" id="formid">
<?php
$query = "SELECT nama FROM alternatif";
$result = mysqli_query($conn, $query);
for ($i=0; $i < $row = mysqli_fetch_array($result) ; $i++) {
?>
<tr>
<th><?php echo $row['nama'] ?></th>
<?php
$select = mysqli_query($conn, "SELECT * FROM kriteria");
$count = mysqli_num_rows($select);
for ($j=0; $j < $count ; $j++) {
?>
<td>
<select class="btn-secondary" name="subkrt[<?php echo $i ?>][<?php echo $j ?>]" required>
<option value="" style="display:none;" required>-Pilih-</option>
<?php
$query = mysqli_query($conn, "SELECT pv_alternatif.pv_subkriteria, subkriteria.nama FROM pv_alternatif INNER JOIN subkriteria ON pv_alternatif.id_alternatif = subkriteria.id WHERE id_kriteria=$j+1");
while ($a = mysqli_fetch_array($query)) {
?>
<option value="<?php echo $a['pv_subkriteria']; ?>"><?php echo $a['nama']; ?></option>
<?php
}
?>
</select>
</td>
<?php
}
}
?>
</tr>
</form>
so both value and content are fetched from two different tables of my database. and hitung.php is code to insert into database.
include 'koneksi.php';
include 'fungsi.php';
$jmlsub = array();
$qwery = mysqli_query($conn, "SELECT nilai FROM pv_kriteria");
while ($row = mysqli_fetch_array($qwery)){
$rows[] = $row['nilai'];
$jmlsub[] = 0;
}
$query = "SELECT nama FROM alternatif";
$result = mysqli_query($conn, $query);
$a = mysqli_query($conn, "SELECT * FROM nilai_alt");
for ($i=0; $i < $row = mysqli_fetch_array($result) ; $i++) {?>
<?php
$select = mysqli_query($conn, "SELECT * FROM kriteria");
$count = mysqli_num_rows($select);
for ($j=0; $j < $count ; $j++) {
if(isset($_POST['subkrt'][$i][$j])){
$matriks[$i][$j] = $_POST['subkrt'][$i][$j] * $rows[$j];
$value = $matriks[$i][$j];
$jmlsub[$i] += $value;
$id_alternatif = getIDAlternatif($i);
$id_kriteria = getKriteriaID($j);
if (mysqli_num_rows($a)==0) {
$b = "INSERT INTO nilai_alt VALUES('',$id_alternatif,$id_kriteria,$value)";
} else {
$b = "UPDATE nilai_alt SET nilai_alternatif=$value WHERE id_alternatif = $id_alternatif AND id_kriteria = $id_kriteria";
}
$rsult = mysqli_query($conn,$b);
if (!$rsult) {
echo "Gagal memasukkan / mengupdate nilai alternatif";
exit();
}
}
}
}
$jmlAlternatif = getJumlahSubKriteria();
for ($i=0; $i < ($jmlAlternatif); $i++) {
$id_alternatif = getIDAlternatif($i);
$query = "INSERT INTO ranking VALUES ($id_alternatif,$jmlsub[$i]) ON DUPLICATE KEY UPDATE nilai=$jmlsub[$i]";
$result = mysqli_query($conn,$query);
if (!$result) {
echo "Gagal mengupdate ranking";
exit();
}
}
header('Location: hasil_subkrt.php');
?>
tables:
Any help will be greatly appreciated. Thanks.
As you said you "can insert the value with no problem", so it is simple to pass all the value and content to the selected option value as a string
using json_encode(...), then in hitung.php you just convert it back to array or object using json_decode(...)
If you have a array, example:
$a = array('pv_subkriteria' => 'the value', 'nama' => 'the name');
Then just
<option value='<?php echo htmlentities(json_encode($a)); ?>'><?php echo $a['nama']; ?></option>
Then in your case in hitung.php,
...
$a = json_decode(html_entity_decode($_POST['subkrt'][$i][$j]), true);
...
More info, generally your code has nested loop and query database in loop, you need to think more about better query way to reduce number of loops to increase performance.
Edited and added an example using some php functions that might help you:
<?php
$a = array('pv_subkriteria' => 'the value', 'nama' => 'the name');
$str = htmlentities(json_encode($a));
$a2 = json_decode(html_entity_decode($str), true);
print_r($a2);
?>

Infinite loop display iteration database entries

I have php code,that fetch and show entries from database.I need to display them while they shuffling until something happened /pressing a button ect./
something like this- http://jsfiddle.net/ZDsMa/1/
here is my code
<?php
$winners = [];
$conn = mysqli_connect("localhost", "admin", "admin", "lottary");
$sql = "SELECT * FROM users ORDER BY RAND() ";
$result = $conn->query($sql);
while ( $row = $result->fetch_assoc()) {
$id = $row['id'];
$firstname = $row['first_name'];
$lastName = $row['last_name'];
$points = $row['point'];
$all =$id.' '.$firstname. ' '.$lastName. ' '.$points;
?>
<input class="form-control" size="40" name="id" type="text" value="<?php echo $all; ?>">
<?php }
$conn->close();
?>
Here is jquery script that shuffle database entries,with stop/start button
<div class="demo">
<div id="roll"></div><input type="hidden" id="mid" value="">
<p><input type="button" class="btn" id="start" value="Start"> <input type="button" class="btn" id="stop" value="Stop"></p>
<div id="result"></div>
</div>
start_btn.click(function(){
$.getJSON('data.php',function(json){
if(json){
//var obj = eval(json);//By eval () function can be converted into JSON string object
var len = json.length;
_gogo = setInterval(function(){
var num = Math.floor(Math.random()*len);
//var id = obj[num]['id'];
var id = json[num].id;
//var v = obj[num]['mobile'];
var v = json[num].mobile;
$("#roll").html(v);
$("#mid").val(id);
},100);
stop_btn.show();
start_btn.hide();
}else{
$("#roll").html('System can not find the data source, first import the data.');
}
});
//_gogo = setInterval(show_number,100);
});});
stop_btn.click(function(){
clearInterval(_gogo);
var mid = $("#mid").val();
$.post("data.php?action=ok",{id:mid},function(msg){
if(msg==1){
var mobile = $("#roll").html();
$("#result").append("<p>"+mobile+"</p>");
}
stop_btn.hide();
start_btn.show();
});
});
Try this code:
maybe that work
just replace while by foreach
<?php
$conn = new mysqli("localhost", "admin", "admin", "lottary");
$sql = "SELECT * FROM `users` ORDER BY RAND()";
$result = $conn->query($sql);
$fetch = $result->fetch_array();
foreach($fetch as $row) {
$id = $row['id'];
$firstname = $row['first_name'];
$lastName = $row['last_name'];
$points = $row['point'];
$all = $id.' '.$firstname. ' '.$lastName. ' '.$points;
?>
<input class="form-control" size="40" name="id" type="text" value="<?php echo $all; ?>">
<?php
}
$conn->close();
?>

Comparing JavaScript variable with PHP array

<link type="text/css" rel="stylesheet" href="style_downloads.css" />
<script>
function theFunction(e){
var x = e.target.innerHTML;
document.write(x);
}
</script>
<a onclick="theFunction(event)" href="">Electromagnetic Theory</a>
<a onclick="theFunction(event)" href="">Manufacturing Technology-I</a>
<?php
$con = mysqli_connect('localhost', 'root');
if (!$con) echo "Connection Failed";
mysqli_select_db($con, 'test') or die(mysqli_error($con));
$q = "SELECT * FROM tb1";
mysqli_query($con, $q) or die(mysqli_error($con));
$result = mysqli_query($con, $q);
$num = mysqli_num_rows($result);
for ($i = 1; $i <= $num; $i++) {
$row = mysqli_fetch_array($result);
if(?>
<script>x</script>
<?php==$row['coursename'])
{ ?>
<div id="downloads"> <span id="pdfname"><?php echo $row['pdfname'] ?></span> <img src="download.png" id="downloadbtn"> </div>
<?php
}
}
mysqli_close($con);
?>
Here I want to compare var x of js to $row['coursename'] ie mysql db table entry.
Basically this code is targetting to display db table entry according to onclick event.
Example:
When I click on Electromagnetic Theory, File displayed on page should be correspending to this course name only.
<link type="text/css" rel="stylesheet" href="style_downloads.css" />
<script>
function theFunction(e)
{
var itemName = e.target.innerHTML;
$.ajax({
url : "/ajaxAction.php",
type : "POST",
data : {'itemName':itemName},
dataType: 'json',
success: function (response) {
console.log("response",response)
if(response.type == "success") {
$("#downloads").html('');
$("#downloads").html(response.result);
return false;
}
}
});
}
</script>
<a onclick="theFunction(event)" href="">Electromagnetic Theory</a>
<a onclick="theFunction(event)" href="">Manufacturing Technology-I</a>
<div id="downloads">
<span id="pdfname"><?php echo $row['pdfname'] ?></span>
<img src="download.png" id="downloadbtn">
</div>
<?php
create file ajaxAction.php
incluede connection.php
$itemName = $_POST['itemName'];
$con = mysqli_connect('localhost', 'root');
if (!$con)
echo "Connection Failed";
mysqli_select_db($con, 'test') or die(mysqli_error($con));
$q = "SELECT * FROM tb1";
mysqli_query($con, $q) or die(mysqli_error($con));
$result = mysqli_query($con, $q);
$num = mysqli_num_rows($result);
for ($i = 1; $i <= $num; $i++) {
$row = mysqli_fetch_array($result);
if($itemName == $row['coursename'])
{
$res = ' <span id="pdfname"><?php echo $row['pdfname'] ?></span>
<img src="download.png" id="downloadbtn">';
}
}
echo json_encode("type":"success","result":$res);
mysqli_close($con);
?>

Connection of two tables

I have a problem with making a query to MYSQL which will combine two tables.
Mainly I want to through such a query
<?php
require_once 'dbconnect.php';
$wynik = mysql_query("SELECT * FROM users")
or die('Błąd zapytania');
/*
wyświetlamy wyniki, sprawdzamy,
czy zapytanie zwróciło wartość większą od 0
*/
if(mysql_num_rows($wynik) > 0) {
/* jeżeli wynik jest pozytywny, to wyświetlamy dane */
echo "<table cellpadding=\"2\" border=1>";
while($r = mysql_fetch_assoc($wynik)) {
echo "<tr>";
echo "<td><a href='pokaz.php?id=".$r['userId']."'>".$r['userName']."</a></td>";
echo "</tr>";
}
echo "</table>";
}
?>
and after clicking on the link, the pictures that this user added showed me
the file pokaz.php looks like this
my tables
Please, let someone ask me this question, I will be grateful
use mysqli:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$wynik = mysqli_query($con, "select `user`.userId, `user`.userName, `pictures`.image_name from `user` inner join `user_uploads` on `user_uploads`.user_id_fk = `user`.id");
/*
wyświetlamy wyniki, sprawdzamy,
czy zapytanie zwróciło wartość większą od 0
*/
if($wynik) {
if (mysqli_num_rows($wynik) > 0) {
;
/* jeżeli wynik jest pozytywny, to wyświetlamy dane */
echo "<table cellpadding=\"2\" border=1>";
while ($r = mysqli_fetch_assoc($wynik)) {
$imgName = $r['image_name'];
echo "<tr>";
echo "<td><a href='pokaz.php?id=" . $r['userId'] . "'>" . $r['userName'] . "</a></td>";
echo "<img src='/uploads/$imgName' />";
echo "</tr>";
}
echo "</table>";
}
}
?>
UPDATE:
if you want to show images in pokaz.php for each user:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$wynik = mysqli_query($con, "select `user`.userId, `user`.userName, `pictures`.image_name from `user` inner join `user_uploads` on `user_uploads`.user_id_fk = `user`.id");
/*
wyświetlamy wyniki, sprawdzamy,
czy zapytanie zwróciło wartość większą od 0
*/
if($wynik) {
if (mysqli_num_rows($wynik) > 0) {
;
/* jeżeli wynik jest pozytywny, to wyświetlamy dane */
echo "<table cellpadding=\"2\" border=1>";
while ($r = mysqli_fetch_assoc($wynik)) {
$imgName = $r['image_name'];
echo "<tr>";
echo "<td><a href='pokaz.php?id=" . $r['userId'] . "'>" . $r['userName'] . "</a></td>";
echo "<img src='/uploads/$imgName' />";
echo "</tr>";
}
echo "</table>";
}
}
?>
pokaz.php
<?php
if(isset($_GET['userId'])){
$userId = $_GET['userId'];
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$query = "select image_name from user_uploads";
$result = mysqli_query($con, $query);
if($result){
while($row = mysqli_fetch_assoc($result)){
$imgName = $row['image_name'];
echo "<img src='/uploads/$imgName' /></br>";
}
}
}

Replace div contents with jQuery on form submit within PHP loop

I have this jQuery form being outputted in a PHP while loop if the button has not previously been clicked and just an image with the value if it has, the function is like facebooks like button where when the user clicks the button the icon changes so its not clickable any longer and the value increments by 1. The form submission works but I cannot seem to update the icon image and value count in the feed without effecting all the other buttons and values in the feed… I tried jQuery replaceWith() but it replaces all the #bumpCont divs in the feed…
index.php
<div class="images">
<?php
while($row = $result2->fetch_assoc()){
$path = $row['path'];
$user = $row['user'];
$id = $row['id'];
$desc = $row['desc'];
$update = $row['update_date'];
$bump = $row['bump'];
$timeFirst = strtotime($date);
$timeSecond = strtotime($update);
$timeSecond = $timeSecond + 86400;
$timer = $timeSecond - $timeFirst;
?>
<?php if(empty($desc)){}else{?><div id="desc"><?php echo $desc;?></div><?php }?>
<img id="pic" src="uploads/<?php echo $path;?>"/>
<div id="userCont">
<div id="user"><a rel="external" href="user_profile.php?user='.$user.'"><?php echo $user;?></a></div>
<div id="timer"><?php echo $timer;?></div>
<?php
if(in_array($path, $mypath)) {
echo '<div id="bumpCont"><img id="bump" style="height:55px;right:8px;top: 2px;position: relative;" src="../img/bumpg.png"/><span id="bumpCount">'.$bump.'</span></div>';
}else{
echo '<form method="post" id="bumpF" data-ajax="false">';
echo '<input name="id" data-ajax="false" id="field_'.$id.'" type="hidden" value="'.$id.'" />';
echo '<div id="bumpCont"><input type="image" style="height:55px;right:8px;top: 2px;position: relative; " id="bump" src="../img/bump.png" id="searchForm" onclick="SubmitForm('.$id.');" value="Send" /><span id="bumpCount">'.$bump.'</span></div>';
echo ' </form>';
}
?>
</div>
<?php
}
?>
//Submit Form
function SubmitForm(id) {
event.preventDefault();
var name = $('#field_'+id).val();
console.log(name);
$.post("bump.php", {name: name},
function(data) {
$( "#bumpCont" ).replaceWith( '<div id="bumpCont"><img id="bump" style="height:55px;right:8px;top: 2px;position: relative;" src="../img/bumpg.png"/><span id="bumpCount">' + data + '</span></div>' );
}
Bump.php -
$id = $_POST['name'];
$sessionUser = $_SESSION['userSession'];
// GET USERNAME
$sql = "SELECT * FROM userbase WHERE user_id='$sessionUser'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$myname = $row['username'];
}
}
$bump = 1;
$sql = "SELECT * FROM images WHERE id=$id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$bump = $row['bump'];
$path = $row['path'];
$desc = $row['desc'];
$post_user = $row['user'];
$bump++;
}
}
$bumpC = 0;
$sql = "SELECT * FROM bumped WHERE path='$path' AND myname ='$myname'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$bumpC++;
}
}
echo $bump;
if($bumpC >= 1){
}else{
$sql = "INSERT INTO `bumped` ( `myname`,`path`, `description`, `post_user`) VALUES ( '$myname','$path', '$desc', '$post_user')";
if ($conn->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$sql = "UPDATE images SET update_date='$date' WHERE id=$id";
if ($conn->query($sql) === TRUE) {
} else {
echo "Error updating record: " . $conn->error;
}
$sql = "UPDATE images SET bump=$bump WHERE id=$id";
if ($conn->query($sql) === TRUE) {
} else {
echo "Error updating record: " . $conn->error;
}
}
First look shows me a problem of Elements with same ID in loop.
You could have same class to multiple elements.
<div class="bumpCont"><span class="bumpCount">1</span></div>
<div class="bumpCont"><span class="bumpCount">2</span></div>
Use $(this)
Based on the click on particular element, you can change contents.
$('.bumpCount').click(function(){
$(this).html(parseInt($(this).html) + 1);
});
Hope this helps you.
$('.bumpCount').click(function(){
$(this).html(parseInt($(this).html()) + 1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="bumpCont"><span class="bumpCount">1</span></div>
<div class="bumpCont"><span class="bumpCount">2</span></div>

Categories

Resources