How to create a textbox that display message when mouseover? - javascript

I have a sql query that obtain a string called description from the database
Also , i have a table that contain a mail list
I would like for each mail list name, when the mouse over it, it display a text block that contain the description
Are there any plugin , or how to do that? Thank you.

I use a jQuery plug-in called TipTip, which is very simple to implement.

The PHP(for the query). You can use whatever, this is an example.
<?php
$q = 'your sql query'
$query = mysql_query($query)
while($row = mysql_fetch_array($query)){
?>
<div class="email-list-name-<?=$row['id']?>"> <?=$row['email-list-name']?> </div>
<div class='description-for-email' style='display:none;'><?=$row['description']?></div>
<?php } ?>
The jQuery:
$(function(){
$('div[id^="email-list-name"]').click(function(){
$('.description-for-email').hide(); //hide all message displays
$(this).next('.description-for-email').show(); //show the next description for our email we clicked
});
});
You didn't really provide any other information, so I just threw together a general example.

You can use the title attribute of html for that or make use of tooltip . You can easily find an example of tooltip. But if you trying to fetch the data from your db on the run time..i would say thats a bad idea

Related

Sort and separate names from a database

Could anybody point me in the right direction?
I have a database with a handful of messages. Each message has a username also..
I wish to use the names of the messages in a drop down menu so that the user can click a user and view the messages from the user.
THE PROBLEM: the drop down list shows every user of every message and i don-not know how to separate the users so that if there is 7 messages from ROB only 1 ROB will be shown in the drop down list..
I hope I am making sense here.
So if anyone could help me here, I would be grateful.
What sort of query should I be using the separate every user from the database so I can show them in the drop-down menu, as individual users...
Instead of the same user being shown for as many messages as the user wrote.
Below is the current query..
<div class='userbox'>
<header class='ubheader'>Contacts</header>
<section class='ubmain'>
";
$db = new PDO("mysql:host=localhost;dbname=messages", 'root', ''); // 1. set database with this instead of conect - or change conect to this
$query="SELECT * FROM `messagedatabase` WHERE `listID`='$listID' ORDER BY messagedate DESC";
$stat=$db->prepare($query);
$stat->execute();
$Mcount = $stat->rowCount();
$messagecount=$Mcount;
while($row = $stat->fetch()){
$messageaccountname=$row['messageaccountname'];
if ($messageaccountname != $useraccountname){
echo"<div class='ubnames' onclick='selectmessage(\"{$messageaccountname}\")'>{$messageaccountname}</div>";
}
}
echo "
</section>
</div>
";
Any help would be appreciated.
Many thanks.
The simple solution would be to add a DISTINCT clause to your query, such as:
SELECT DISTINCT messageaccountname FROM ....
Beyond that, it sounds like the database isn't normalized. Ideally, you'd have your accounts in a separate table that would be related to your messagedatabase table. But database design is a different discussion beyond the scope of this post.

How to dynamically generate a link with query

Hi fellow developers,
I want to integrate affiliate program for my website, to earn commissions from bookings made via my links.
Since, I have those properties on my site as well, I need a user to be able to click "book it" and get redirected to a page on booking.com with that particular place highlighted.
So the link has this params, which I need:
http://www.booking.com/searchresults.html?city=-2900142&aid=814610&checkin_monthday=25&checkin_month=3&checkin_year=2017&checkout_monthday=30&checkout_month=3&checkout_year=2017&no_rooms=1&group_adults=1&highlighted_hotels=2197459
City = I have custom field for it,so wordpress can pick it with
get_post_meta(CityID)
Highlighted_hotels = makes this particular object highlighted if it's available, also I have it in custom field, so I can take it with
get_post_meta(HotelID)
But how do I take date values from dropdowns? And how do I make a link afterwards? with
<?php echo '<a href="http://www.booking.com/searchresults.html?';
echo $city;
echo $highlighted;
echo $dates;
Is this a correct method to create a link on wordpress?
Btw, I'm using an official booking.com plugin right now, but it's broken and doesn't fill my needs, I want to change it with above custom code, but you can take a look at what I want to achieve on my site here for example (russian language) :
http://sochi.asp.sale/nedvizhimost/chvizhepse/posutochno/kompleks-zolotoj-kashtan/
Form is on the right side bottom.
Any help much appreciated!
Use Javascript to take the values from the dropdown like so:
var e = document.getElementById("DROPDOWN_NAME");
var strUser = e.options[e.selectedIndex].text;
Now to build a URL just use the variable created called strUser.
var url = "http://www.booking.com/searchresults.html?" + strUser;
I hope that is clear and helps.
EDIT:
If you want to use php to build the link, append the values to the url variable:
<?php echo '<a href="http://www.booking.com/searchresults.html?' . $city . '&' . $highlighted . '&' . $dates;
That will echo the completed url with all the variables added onto the end of it.

Set_value fallback in code igniter to obtain integer from URL address

I'm using the codeigniter framework in order to update records from a database, where the user first selects the ID of the item from a drop down list on the form
This ID gets added onto the URL where all of the relevant information for that item is obtained from the database.
I used a small bit of javascript in order to achieve the ID being added onto the URL.
My problem is that even though I have the set_value() field on the form to the ItemID, it still doesn't retrain the ID within the drop down box after the page reloads?
I need the ID to stay inside of the drop down list, as well as being on the URL at the top of the page
here is my code for the form
<?php echo form_dropdown('ItemID', $ItemIDListFromDatabase,
set_value('ItemID', 1), 'id="ItemID"'); ?>
<script type="text/javascript">
$( '#ItemID' ).on( 'change', function( e ){
document.location.href = "<?php echo site_url('site/Myform) ?>" + "/" + $( this ).val();
});
</script>
As you can see above I've tried adding a random fallback number to this set_value call, which works but only to update the item with ID of 1, I need it to be able to update the Item corresponding to the ID on the URL
I hope this makes sense, all help appreciated thanks.
You can do this by very simply using
$this->uri->segment()
Without knowing your full URL address, I don't know the exact number to put into the segment, but going by your code supplied just change the following to this:
<?php echo form_dropdown('ItemID', $ItemIDListFromDatabase,
set_value('ItemID', $this->uri->segment(3)), 'id="ItemID"'); ?>
This will obtain the value within segment 3 of your URL.
A quick tip if you can't figure out what the correct URI segment should be, you can test it out by echoing different values until you find the correct one
E.g.
<?php echo $this->uri->segment(3); ?>
This will display what ever is displayed on your third segment of the URL

Yii2: Jquery selecting id of a table cell not working

I am using Yii2 and using this jquery code to access the value of a cell(td) column. I have set the id of the column say 'room_name'
I am using this code which works fine on a form, but in grid-view(table) I am getting a blank alert.
<?php
$script = <<<EOD
alert ($('#room_name').val());
EOD;
$this->registerJs($script);
?>
Do I need to do it differently for tables, as the id is getting repeated over multiple rows.
Thanks for a suggestion.
I got it from #anpsmn. Adding for record for help to others.
$('td.room_name').each(function(){
alert($(this).text());
})

PHP multiple records insert

I am attempting to reword my issue.
I have a datatable that can return thousands of records, each with multiple columns. There is a checkbox in the first column that, once the user checks it, they then click a button, and the CONTAINER_NUMBER that is associated with the row is sent to a modal window to be used in a form.
Here is the code for the checkbox:
echo "<tr><td><input type=\"checkbox\" id=\"{$Row[CONTAINER_NUMBER]}\" name=\"checkMr[]\" /></td>";
This is the javascript that retrieves the CONTAINER_NUMBER and sends it to the modal window:
<script type="text/javascript">
$(function()
{
$('a').click(function()
{
var selectedID = [];
$(':checkbox[name="checkMr[]"]:checked').each(function()
{
selectedID.push($(this).attr('id'))
});
$(".modal-body .containerNumber").val( selectedID );
});
});
</script>
This is the section of the modal window that displays the CONTAINER_NUMBER:
<div class="modal-body">
<form action="" method="POST" id="serviceModalForm" name="serviceModalForm">
<input type="text" name="containerNumber" id="containerNumber" class="containerNumber">
Here is the section of PHP that takes the id="containerNumber" and converts it to a PHP variable. After that, there is an INSERT statement that inserts the containerNumber into a database table:
<?php
$container = $_POST['containerNumber'];
if(isset($_POST['submit'])){
$container = mysql_real_escapse_string(stripslashes($container));
$sql = "INSERT INTO myTable (container_num) VALUES ('$container')";
if(mysql_query($sql)){
echo "Insert complete";
}
else {
echo "Insert was not completed";
}
?>
This code is fine. It works good. It does what it's supposed to do...for when the user checks ONE checkbox. It DOES NOT work when the user checks multiple checkboxes.
Basically, from what I've been researching is that I need to separate the records from the variable $container, as there can be multiple containers in that variable, which is why the query does not work when there are more than one container numbers selected.
I need to be able to separate the container numbers and store them in an array or something. The query will read each record separately and generate multiple INSERT statements for each record.
I've tried several times to create an array and get the sql statement to recognize it, but have been unsuccessful. I'm not sure if I'm placing the array in the right place. I'm not sure if this has to be done in the javascript before the container gets sent to the modal window.
I know I need to utilize a FOREACH loop to go through the array, but like I said, I'm not sure where the array needs to go in my code.
Please help. I know I need to learn PDO or MYSQLI. I will be sure to utilize PDO or MYSQLI on my next application. Until then, please help me with this issue.
Thank you, and sorry for so much wording.
Your containerNumber will be posted as a converted string from a js array. Something like id1, id2, id3[...]
In your php code, convert the $container back to an array ($containerArray = explode(",", $container)) and construct the sql dynamically to add all the rows in a single query so that the statment becomes something like
INSERT INTO myTable (container_num) VALUES ('$containerArray[0]'), ('$containerArray[1]')[...]

Categories

Resources