Add blog_details to wp_get_sites list - javascript

I am looking to add blog details to the following dropdown list to replace $site['domain'] in the option value with the detail 'blogname'. I also want to keep $site['domain'] in the option content.
function blavou_existing_sites() {
echo '<div id="blav-wrapper">';
echo '<div class="blav-nav-wrapper">';
echo '<ul class="blav-drop">';
echo '<form action="../">';
echo '<select name="mySelectbox" id="mySelectbox">';
echo '<option value="">Choose Existing</option>';
$sites = wp_get_sites();
foreach ($sites as $site) {
printf( '<option value="http://'.$site['domain'].'/wp-admin/">'.$site['domain'].'</option>');
}
echo '</select>';
echo '<input type="button" onclick="window.open(this.form.mySelectbox.options[this.form.mySelectbox.selectedIndex].value,\'_top\')" value="Confirm">';
echo '</form>';
echo '</ul>';
echo '</div>';
echo '</div>';
}
Help Appreciated!

You can use the get blog details() function:
foreach ($sites as $site) {
$details = get blog details($site['blog_id']);
printf( '<option value="%s">%s (%s)</option>', 'http://'.$site['domain'].'/wp-admin/', $details->blogname, $site['domain'] );
}
This should give you options like "blogname (url)".

Related

Load function in loop

I have an working loadfunction. But when I use this in an loop it won't work, the data is not pulled or the code is not (correctly) triggered. When viewing the console there is no error. So hard to determine why the data is not shown.
In this code when the users selects an item of the first select list the second select list is updated with the corresponding data.
<select class="form-control" id="add_off_relatie_id" name="add_off_relatie_id" onchange="add_contact_table_4()">';
foreach ($rows_adr as $row_adr)
{
echo '<option ';if($row['relatie_id'] == $row_adr['id']) { echo 'selected="selected"';} echo 'value="'.$row_adr['id'].'">'.$row_adr['naam'].'</option>';
}
echo '
</select>
<select class="form-control" id="add_off_contact_id" name="add_off_contact_id" onchange="validate_add_off_table_4()">';
foreach ($rows_cnt as $row_cnt) if($row_cnt['relatie_id'] == $row['relatie_id'])
{
echo '<option ';if($row['contact_id'] == $row_cnt['id']) { echo 'selected="selected"';} echo 'value="'.$row_cnt['id'].'">'.$row_cnt['naam'].'</option>';
}
echo '
</select>
<script type="text/javascript">
function add_contact_table_4()
{
$('#add_off_contact_id').load('includes/dynamic_drop/relatie_contact.php?choice=' + document.getElementById('add_off_relatie_id').value)
}
</script>
But when using the same structure in an for loop and the user select an new item in the first select list the data in the second select list is not updated.
<select class="form-control" id="edit_off_relatie_id['.$i.']" name="edit_off_relatie_id" onchange="edit_contact_table_4(this, '.$i.')">';
foreach ($rows_adr as $row_adr)
{
echo '<option ';if($row_table_4['relatie_id'] == $row_adr['id']) { echo 'selected="selected"';} echo 'value="'.$row_adr['id'].'">'.$row_adr['naam'].'</option>';
}
echo '
</select>
<select class="form-control" id="edit_off_contact_id['.$i.']" name="edit_off_contact_id" onchange="validate_edit_off_table_4(this, '.$i.')">';
foreach ($rows_cnt as $row_cnt) if($row_cnt['relatie_id'] == $row_table_4['relatie_id'])
{
echo '<option ';if($row_table_4['contact_id'] == $row_cnt['id']) { echo 'selected="selected"';} echo 'value="'.$row_cnt['id'].'">'.$row_cnt['naam'].'</option>';
}
echo '
</select>
<script type="text/javascript">
function edit_contact_table_4(selectVeld, nr)
{
$('edit_off_contact_id['+nr+']').load('includes/dynamic_drop/relatie_contact.php?choice=' + document.getElementById('edit_off_relatie_id['+nr+']').value)
}
</script>
Any suggestions would be fantastic.
Square brackets are used to special tasks, like getting attributes, like in input[name=something], so they need to be escaped:
$('edit_off_contact_id\\['+nr+'\\]').load('includes/dynamic_drop/relatie_contact.php?choice=' + document.getElementById('edit_off_relatie_id\\['+nr+'\\]').value)
Or you can change string format for your ids:
<select class="form-control" id="edit_off_relatie_id-' . $i . '" name="edit_off_relatie_id" onchange="edit_contact_table_4(this, ' . $i . ')">';
foreach ($rows_adr as $row_adr)
{
echo '<option ';if($row_table_4['relatie_id'] == $row_adr['id']) { echo 'selected="selected"';} echo 'value="'.$row_adr['id'].'">'.$row_adr['naam'].'</option>';
}
echo '
</select>
<select class="form-control" id="edit_off_contact_id-' . $i . '" name="edit_off_contact_id" onchange="validate_edit_off_table_4(this, ' . $i . ')">';
foreach ($rows_cnt as $row_cnt) if($row_cnt['relatie_id'] == $row_table_4['relatie_id'])
{
echo '<option ';if($row_table_4['contact_id'] == $row_cnt['id']) { echo 'selected="selected"';} echo 'value="'.$row_cnt['id'].'">'.$row_cnt['naam'].'</option>';
}
echo '
</select>
<script type="text/javascript">
function edit_contact_table_4(selectVeld, nr)
{
$(`edit_off_contact_id-${nr}`).load('includes/dynamic_drop/relatie_contact.php?choice=' + document.getElementById(`edit_off_relatie_id-${nr}`).value)
}
</script>

AJAX code to save id value in database

I want to pass this value doctoridclickedRightNow into t_appointmentdetails table. I have made few changes to previous code using AJAX and JS as suggested on How to Pass variable from JavaScript to PHP Page using XMLHTTP . Appointment details are getting inserted into DB and I also want the doctorid of the corresponding doctor to be saved. So with the below changes I am able see the correct values being displayed when I use inspect element in mozilla. Kindly suggest me how to pass this to DB. Thanks in advance.
$sql = "SELECT doctorid, FIRST_NAME,LAST_NAME, Address, Qualification, Specialization, Consultation_Fee, Experience,image_path
from t_doctorprofile";
$results = mysqli_query($db,$sql)
or die('MySQL Error');
echo '<h3 style="color:#674172;margin- left:120px;float:center;display:inline-block"><strong>Available Dentists</strong></h3>';
while($result = mysqli_fetch_assoc($results)){
echo '<div class= "fetch" style="margin-left:120px">';
echo "<img src = 'uploads/".$result['image_path']."' width='150' height='150'>";
echo "<div id='info'>";
echo "<p><strong>".$result['FIRST_NAME']." ".$result['LAST_NAME']."</strong></p></div>";
echo "<p>".$result['Qualification']."</p>";
echo "<p>".$result['Specialization']."</p>";
echo "<p>".$result['Address']."</p>";
echo "<p>"."<b>Consultation Fee-</b>"." ".$result['Consultation_Fee']."</p>";
echo "<p>"."<b>Experience-</b>"." ".$result['Experience']."years"." </p>";
echo "<button class='btn btn-success btn-lg' id='$result[doctorid]' data-toggle='modal' data-target='#myModal' onclick='AssignDoctorIdClicked(id)'>
Appointment</button>";
echo "<script>var doctoridclickedRightNow;</script>";
echo "</div>";
echo '<form action="appointment_insert.php" method="POST">';
echo "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content' style='background-color:#F1A9A0'>";
echo "<div class='modal-header'>";
echo "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>";
echo "<h4 class='modal-title' id='myModalLabel' style='text-align:center; color:#fff'>
<strong>Book Appointment</strong></h4><br>";
echo "</div><br><br>";
echo "<div class='modal-body'>";
script for AssignDoctorIdClicked function:
<script>
function AssignDoctorIdClicked(id) {
console.log(id);
var doctoridclickedRightNow = id;
console.log(doctoridclickedRightNow);
</script>
appointment_insert.php page
if (isset($_POST["submit"])) {
$login_user = $_SESSION['username'];
$datetime = $_POST['datetime'];
$info = $_POST['info'];
$recieved_1 = $_GET['FIRST_NAME'];
$query = mysqli_query($db, "INSERT INTO t_appointmentdetails (patient_name,datetime,info) VALUES ('$login_user','$datetime','$info');");
$insertedDataBoolean = true;
if($insertedDataBoolean){
echo "Name: " . $recieved_1 . " booked successfully.";
}
else{
echo "Data-insertion error.";
}
}

JQuery/javascript doubleclick=do something on each div from foreach() php

I have this PHP file:
foreach($allfiles as $file) {
echo '<div class="file" id="file' . $file->id . '">';
echo '<div id="checkbox"><img src="images/delete.png" width="15" height="15"></img></div>';
echo '<div id="filename">'. $file->name . '</div>';
echo '<div id="size">| '. $file->size . ' </div>';
echo '<div id="created">'. $file->created . '</div>';
echo '<div id="download"><img src="images/download.png" width="18" height="18"></img></div>';
echo '</div>';
?>
<script>
var id = <?php echo $file->id; ?>
</script>
<?php
}
and this JS file
$('#file' + id).dblclick(function() {
alert(1);
});
What I'm trying to do is that when div "file" + the file id is clicked, it will alert "1" (or open the file).
The problem is that now it only alerts 1 when I doubleclick the last div I have, while it is supposed to be done on all of them.
Is there a solution like foreach div called file + something do ? when doubleclicked.
Sorry if this was very unclear :D
You can use data-* prefixed custom attribute like
echo '<div class="file" data-id="' . $file->id . '">';
Bind your event using the common class and then fetch data-idusing .data()
$('.file').on('dblclick', function() {
alert($(this).data('id'));
});

drop down lists in php using cookies

<?php
$i=1;
//echo '<form id="form1" name="form1" method="post" action="<?PHP $_SERVER ['PHP_SELF' ]
echo '<form>';
echo "<select name='dropdown' id=$i onchange='myFunction()'><option>Select one...</option>";
echo '<option value="horse">horse</option>';
echo '<option value="hor">hor</option>';
echo '</select>';
echo '</form>';
$i++;
echo '<form>';
echo "<select name='dropdown' id=$i onchange='myFunction()'><option>Select one...</option>";
echo '<option value="por">por</option>';
echo '<option value="voi">voi</option>';
echo '</select>';
echo '</form>';
echo '<p id="demo"></p>
<script type ="text/javascript">
function myFunction()
{
var k=2;
var x=document.getElementById(k);
var y=x.options[x.selectedIndex];
if(y){
document.cookie=\'name=\'+y.value;
alert(y.value);
}
}
</script>';
$var=$_COOKIE["name"];
echo $var;
?>

How to echo out multiple lines of HTML Code?

<?php
$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('database');
$query = "SELECT user_name FROM users";
while($row = mysql_fetch_array($result)){
echo '<div class="mosaic-block bar2" onmouseout="decolorit2()" onmouseover="colorit2()">'
'<a target="_blank" class="mosaic-overlay">'
'<div class="details">'
'<p class="font_us">' . $row['user_name'] . '</p> <br/>'
'<p class="font_us1">technische Umsetzung</p>'
'</div>'
'</a>'
'<div class="mosaic-backdrop"><img id="pic" src="../views/pictures/pic"/></div>'
'</div>';
}
mysql_close();
?>
So I wanted to output the usernames of my database with some javascript effect, but it doesn't show. How do I have to echo this out?
echo 'foo
bar
baz';
No need to close the quote on each newline. Better though, simply go out of PHP mode:
<?php while ($row = mysql_fetch_array($result)) { ?>
<div>
...
<?php echo $row['user_name']; ?>
...
</div>
<?php } ?>
Even better yet for readability (IMO):
<?php while ($row = mysql_fetch_array($result)) : ?>
...
<?php endwhile; ?>
You should use pdo or mysqli.
You did not concat your string.
<?php
$connection = mysql_connect('localhost', 'root', '1234');
mysql_select_db('database');
$query = "SELECT user_name FROM users";
while($row = mysql_fetch_array($result)){
echo '<div class="mosaic-block bar2" onmouseout="decolorit2()" onmouseover="colorit2()">'.
'<a target="_blank" class="mosaic-overlay">'.
'<div class="details">'.
'<p class="font_us">' . $row['user_name'] . '</p> <br/>'.
'<p class="font_us1">technische Umsetzung</p>'.
'</div>'.
'</a>'.
'<div class="mosaic-backdrop"><img id="pic" src="../views/pictures/pic"/></div>'.
'</div>';
}
mysql_close();
?>

Categories