I am trying to make a copy button. It only gives an error in Chrome:
Uncaught SyntaxError: Unexpected token }
I tried lots of different scripts, but none worked. Everything works except the copy button. I even went to the ICT part of our school. They did not have a solution.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
This is the copy script
<script>
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
This is the end of the copy script
<?php
$str1 = "'";
$str2 = '#';
?>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
<?php
$link = mysqli_connect("localhost", "username", "password", "database");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sqlget = "SELECT FROM redeem";
$result = $link->query($sqlget);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo"<table>";
echo "<tr><th>Code: </th>
<th id=" . $row['code']. ">" . $row['code']. "</th>
<th>Expires: </th><th>". $row['expires']."</th>
<th><button onclick='copyToClipboard($str2".$row['code'].")'><p id=" . $row['code']. ">...</button></th></tr></table>";
}
} else {
echo "0 results";
}
?>
This code is the working version of the copy button.
<center>
<p id="p1">Hello, I'm TEXT 1</p>
<p id="p2">Hi, I'm the 2nd TEXT</p><br/>
<button onclick="copyToClipboard('#p1')">Copy TEXT 1</button>
<button onclick="copyToClipboard('#p2')">Copy TEXT 2</button>
<br/><br/><input class="textBox" type="text" id="" placeholder="Dont belive me?..TEST it here..;)" />
</center>
Hope you guys/girls can help me out.
copyToClipboard($str2".$row['code'].")
produce : copyToClipboard(#code)
It should be :
"[...]copyToClipboard(\"$str2".$row['code']."\")[...]"
or even better :
"onclick='copyToClipboard(" . '"' .$str2 . $row['code']. '"' . ")'"
With the output copyToClipboard("#code")
FIXED!!!
IT finally woooorrrrkkssss!!!
It took me a while. But thanks to Blag his part of the code. I found it.
<?php $str1 = "'"; ?>
This was the sollution.
<th><button onclick='copyToClipboard(".$str1. $str2 . $row["code"] .$str1. ")'>
Related
I've tried different codes, but the codes always not working. I want to reload just the specific section every 5 seconds, not reloading the whole page. It's important not to refresh the whole page, because it includes an chat function. If I would reload the whole page, people can't enter text without loosing it every 5 seccond. Like I said, I've tried some codes from stackOverflow but somehow they don't work for me.
Here's my code
<script type="text/javascript">
$(document).ready(function(){
setInterval(function(){
$("#context").load(window.location.href + " #context" );
}, 5000);
});
</script>
<--variables explained --->
$fid = $_GET['fid']
$username = $_SESSION['username']
$db :
$servername = "localhost";
$dbname = "psychopath";
$username = "root";
$password = "";
try{
$dsn = "mysql:host=" . $servername . ";dbname=" . $dbname;
$db = new PDO($dsn, $username, $password);
echo "";
}catch(PDOException $e){
echo $e.getMessage();
}
<--- variables END ----->
$display_messages = $db->prepare("SELECT * FROM mychat_from WHERE (user_to_name = ? OR userfrom_name = ?) AND (user_to_id = ? OR userfrom_id = ?)");
$display_messages->execute([$username , $username, $fid, $fid]);
while($row=$display_messages->fetch(PDO::FETCH_ASSOC)){
$userfrom = $row['userfrom'];
if($userfrom != $username){
$messagefrom2 = $row['message_from'];
$messagefrombreak2 = wordwrap($messagefrom2, 27, "\n", true);
?>
<?php
?><section id="context" name="context"><?php echo '<b> '.$userfrom.'</b>said:<br>';
echo "<section style='background: black; float: left; margin-left: 5px; border-radius: 7px; color: white;'> <font style='float: left;'> ".$messagefrombreak2."</font></section>";?>
</section>
<?php echo "<br><br>";
?>
And here is full code:
<!-- end snippet -->if(isset($_GET['fid'])){
$fid = $_GET['fid'];
?>
<section>
<section>
<?php
$get_friend = $db->prepare("do stuff");
$get_friend->execute([$fid]);
while($row=$get_friend->fetch(PDO::ROW STUFF)){
}
?>
</section>
<section>
<?php
$username = $_SESSION['username'];
$get_id = $db->prepare("do stuff");
$get_id->execute([$fid]);
while($row=$get_id->fetch(ROW STUFF)){
$get_your_id = $db->prepare("do stugg");
$get_your_id->execute([$username]);
while($row=$get_your_id->fetch(ROW STUFF)){
$display_messages = $db->prepare("DO STUFF");
$display_messages->execute([$your_id, $your_id, $fid, $fid]);
while($row=$display_messages->fetch(DO STUFF)){
$userfrom = $row['userfrom'];
if($userfrom != $username){
$messagefrom2 = $row['message_from'];
$messagefrombreak2 = wordwrap($messagefrom2, 27, "\n", true);
?>
<?php
?><div id="container" name="container"><div id="context" name="context"><?php echo '<b> '.$userfrom.'</b>said:<br>';
echo "<section style='background: black; float: left; margin-left: 5px; border-radius: 7px; color: white;'> <font style='float: left;'> ".$messagefrombreak2."</font></section>";?>
</div></div>
<?php echo "<br><br>";
?>
<script type="text/javascript">
$(document).ready(function(){
setInterval(function(){
$("#context").load(window.location.href + " #container" );
}, 5000);
});
</script>
<?php
}else{
$messagefrom = $row['message_from'];
$messagefrombreak = wordwrap($messagefrom, 27, "\n ", true);
echo "<font style='float: right;'><b>You </b>said: </font><br>";
echo "<section style='background: #960505; float: right; margin-right: 5px; border-radius: 7px; color:
white;'><font style='float: right;'> ".$messagefrombreak." </font></section><br><br>";
}}}}
?>
</section>
use ajax and json
ajax to make a call to server within the page
json little simple format
use setInterval
like
var myVar = setInterval(my_func, 5000);
my_func is a function that will hold ajax action. and do what do you need
I am newbie in PHP and AJAX, and I am in trouble and don't know how to solve it.
I am creating this page that shows a recordset that resulted from a query.
There are 2 pages: getdata.php and phpajax.php. phpajax.php calls getdata.php via Javascript.
What I have done:
I manage to make it work by using button "Try it" (using static value)
What I want:
How to display the data properly using "Submit" button on a single click (ATM the data appears for a couple of seconds after I click Submit twice, then disappears because the page suddenly refreshes) ?
How to pass the value of SELECT and TEXT into fshowdata() using the Submit Button ?
How to pass the value of SELECT and TEXT into fshowdata() using the "Try It" Button ?
Here is the for the phpajax.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script>
function fshowdata(str1,date1) {
//alert("The form was submitted");
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
//document.getElementById("demo").innerHTML = str1 + " " + date1;
xmlhttp.open("GET","getdata.php?q="+str1+"&"+"t="+date1,true);
xmlhttp.send();
}
}
</script>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<p id="demo">Click the button to change the text in this paragraph.</p>
<?php
$con = mysql_connect('localhost','root','123');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb')or die('Could not select database');
$sql="SELECT DISTINCT(rides) FROM t_trx ORDER BY rides ";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
echo "<form onsubmit='"."fshowdata(`some rides`,`a date`)"."' action='".""."'>";
echo "Choose Rides : "." "."<select id='"."rides"."' name='"."rides"."'>";
echo "<option value='"."ALL"."'>ALL</option>";
while($row = mysql_fetch_array($result)) {
echo "<option value='".$row["rides"]."'>".$row["rides"]."</option>";
}
mysql_free_result($result);
echo "</select>";
mysql_close($con);
echo "<input id='"."date2"."' type='"."TEXT"."' name = '"."date2"."'>";
echo "<input id='"."button1"."' type='"."SUBMIT"."' value = '"."SUBMIT"."'>";
echo "</form>";
echo "<button onclick='"."fshowdata(`ROLLER COASTER`,`18/07/2015`)"."'>";
echo "Try it";
echo "</button>";
?>
<br>
<div id="txtHint"><b>Data will be shown here...</b></div>
</body>
</html>
And for the getdata.php:
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = $_GET['q'];
echo $q;
$date_ = $_GET['t'];
echo $date_;
$con = mysql_connect('localhost','root','123');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb')or die('Could not select database');
$sql="SELECT * FROM t_trx WHERE rides = '".$q."' AND date1 = '".$date_."' LIMIT 10";
echo $sql;
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
echo "<table>
<tr>
<th>Rides</th>
<th>Number</th>
<th>Date</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['Rides'] . "</td>";
echo "<td>" . $row['Number'] . "</td>";
echo "<td>" . $row['Date'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>
Thanks guys. I appreciate your help...
use below code to skip refresh page
onsubmit="return fshowdata(`some rides`,`a date`)"
in the fshowdata function, you should return false.
Dear Experts of php and sql . I'm working on a project where there is a table in which two column for "name and having passport".
That table data comes from database. Now what I want that I want to create link on the name of user and when I click on that I get results of those user.
I don't want to write every time a different code.
I want when I click on that link it will get the username and show data acc. to that username. Because there is lots of user . So I want to create a dynamic code that will get username or some unique id and show data acc. to that `
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.green {
background: #4DDB4D;
color: black;
}
.red {
background: red;
}
</style>
</head>
</html>
<?php
$conn = new mysqli("localhost","root","","db_dat");
$havepassport='';
$sql = "SELECT * from upload WHERE having_passport='yes' OR having_passport='no'";
$result = $conn -> query($sql);
$havepassport='';
$havepassport .='<table>';
$havepassport .='<tr>'.'<th>'."Name".'</th>'.'<th>'."Having Passport".'</th>'.'</tr>';
while ($row = $result -> fetch_assoc()) {
$passportClass = $row['having_passport'] == 'yes' ? 'green' : 'red';
$havepassport .='<tr class='.$passportClass.'>'.'<td>';
$havepassport .= '<a href=>'. $row['emp_name'].'</a>';
$havepassport .= '</td>'.'<td>'. $row['having_passport'].'</td>'.'</tr>';
}
$havepassport.='</table>';
echo $havepassport;
?>
`The output of above code is
You can have something like this:
index.php
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.green {
background: #4DDB4D;
color: black;
}
.red {
background: red;
}
</style>
</head>
</html>
<?php
$conn = new mysqli("localhost","root","","db_dat");
$havepassport='';
$sql = "SELECT * from upload WHERE having_passport='yes' OR having_passport='no'";
$result = $conn -> query($sql);
$havepassport='';
$havepassport .='<table>';
$havepassport .='<tr>'.'<th>'."Name".'</th>'.'<th>'."Having Passport".'</th>'.'</tr>';
while ($row = $result -> fetch_assoc()) {
$passportClass = $row['having_passport'] == 'yes' ? 'green' : 'red';
$havepassport .='<tr class='.$passportClass.'>'.'<td>';
$havepassport .= ''. $row['emp_name'].'';
$havepassport .= '</td>'.'<td>'. $row['having_passport'].'</td>'.'</tr>';
}
$havepassport.='</table>';
echo $havepassport;
?>
in info.php:
<?php
if(isset($_GET['user'])){
echo "get infos of user : ".$_GET['user'];
} else {
// not specified user
header("Location: index.php");
}
Atention! Instead of username put user_id or something uniq of the user.
$havepassport .= ''. $row['emp_name'].'';
info.php?user=[something uniq]
First Variant
I think you must wrap name with tag a, for example:
<td> <?php echo $name?> </td>
As you see, when you click to the name your php code will get $_GET['link']. And
you having id of user reload the page with corresponding data.
Second Variant
Set a javascript function to a tag`s onclick event. Let this function do XMLHttpRequest. that is all.
I am trying to create a Button so the user can copy the $filename the code works for the first one but not for the rest I understand that this is because I would probably need to array the js-copyfilename and js-copyfilenamebtn classes so each one is different but then I know very little about JavaScript so wouldn't know where to start
Thanks in advance
<p>Current Images Inside Gallery
<br />
<?php foreach($rows as $row): ?>
<div class="t">
<table class="table2">
<tr>
<td class="table2"><?php echo $row["id"]; ?></td>
</tr>
<tr>
<td><img src="images/<?php echo $row["photo"] ; ?>" alt="" width="130" height="130" /></td>
</tr>
<tr>
<td><textarea class="js-copyfilename" readonly="readonly" ><?php echo $row["photo"];?></textarea>
<button class="js-copyfilenamebtn">Copy Filname</button>
</td>
</tr>
</table>
</div>
<?php endforeach;?>
</div>
<script type="text/javascript">
var copyfilenameBtn = document.querySelector('.js-copyfilenamebtn');
copyfilenameBtn.addEventListener('click', function(event) {
var copyfilename = document.querySelector('.js-copyfilename');
copyfilename.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
});
</script>
For anybody trying to do something similar I done it like so... This code selects all rows in db, puts them into table, and then creates a copy filename button for each of them and copies the one you click into the filename field once you enter the id and click submit the delete form it will delete that image from the database and directory + a few other validation checks
function ClipBoard(obj) {
var filename = document.getElementById("filename");
filename.innerText = obj.innerText;
Copied = filename.createTextRange();
Copied.execCommand("Copy");
}
#charset "utf-8";
/* CSS Document */
#wrap
{
height:800px;
text-align:center;
}
.table1 {
text-align:center;
font-weight: bold;
width: 130px;
font-size:14px;
}
.table2 {
float:left;
text-align:center;
font-weight: bold;
width: 130px;
border: 1px solid #000;
font-size:14px;
}
.t {
width:140px;
display:inline-block;
margin:0 auto;
}
.js-copyfilename {
text-align:center;
font-weight: bold;
width: 128px;
height:16px;
border:1px solid #000;
font-size:14px;
overflow:hidden;
}
<?php
// Include Databse
include "common.php";
// validation errors
$error = array();
// Check if form has been submitted
if (isset ($_POST['delete']))
{
// get the filename & id. See php.net/basename for more info
$filename = basename($_POST['filename']);
$id =($_POST['id']);
// get file extension, see php.net/pathinfo for more info
$ext = pathinfo($_POST['filename'], PATHINFO_EXTENSION);
// allowed file extensions
$allowedExtensions = array('jpeg','jpg','gif','png','bmp');
// Check filename is not empty
if(empty($filename))
{
$error[] = "Please enter a Filename";
}
// Check valid file extension used
else if(!in_array($ext, $allowedExtensions))
{
$error[] = "Please check Filename";
}
// Check ID is not empty
if(empty($_POST['id']))
{
$error[] = "Please enter a ID";
}
else if(is_numeric($id))
{
// Check ID exists in database
$query = "SELECT id FROM `test` WHERE `id` = :id" ;
$stmt = $db->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->execute();
if(!$stmt->rowCount() == 1)
{
$error[] = "Please check ID";
}
}
else {
$error[] = "ID is not numeric";
}
// delete file from database if there are no errors
if (empty($error))
{
// path to the image
$file_to_delete = 'images/' . $filename;
// Checks the file exists and that is a valid image
if(file_exists($file_to_delete) && getimagesize($file_to_delete))
{
// Delete File From Directory
unlink($file_to_delete);
}
else
{
$error[] = "File not found please check Filename";
}
if (empty($error))
{
// Run Query To Delete File Information From Database
try
{
$query = "DELETE FROM `test` WHERE `id` = :id";
$stmt = $db->prepare($query);
$stmt->execute(array('id' => intval($_POST['id'])));
}
catch(PDOException $ex)
{
die("Failed to run query: Please report issue to admin");
}
$status = "File Deleted";
}
}
}
// Run Query To Show The Current Data In Database
try
{
$query = "SELECT id,photo FROM test ORDER BY id";
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Failed to run query: Please report issue to admin");
}
$rows = $stmt->fetchAll();
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Delete Image</title>
<link href="css/delete.css" rel="stylesheet" type="text/css" />
<script src="copy.js"></script>
</head>
<body>
<div id="wrap">
<form action="delete.php" method="post" enctype="multipart/form-data">
Please enter the Filename and ID of the image you wish to delete
<table width="284" align="center">
<tr>
<td width="144" class="table1">Filename</td>
<td width="128" class="table1">ID </td>
</tr>
<tr>
<td class="table1"><input name="filename" id="filename" type="text" value="<?php echo $filename; ?>" /></td>
<td class="table1"><input name="id" type="text" id="id" value="<?php echo $id; ?>" size="3" maxlength="4" /></td>
</tr>
</table>
<p>
<?php
// Show validation errros here
if(!empty($error)):
echo implode('<br />', $error);
echo $status;
endif;
?>
<br />
<input type="submit" value="Delete Selected Image" name="delete" />
</p>
</form>
<p>Current Images Inside Gallery
<br />
<?php
foreach($rows as $row):
$i = $row["photo"];
?>
<div class="t">
<table class="table2">
<tr>
<td class="table2"><?php echo $row["id"]; ?></td>
</tr>
<tr>
<td><img src="images/<?php echo $row["photo"] ; ?>" alt="" width="130" height="130" /></td>
</tr>
<tr>
<td><?php print '<textarea class="js-copyfilename" name="copytext'.$i.'" id="copytext'.$i.'">'.$i.'</textarea>
<input type="button" onclick="ClipBoard(document.getElementById(\'copytext'.$i.'\'));" value="Copy Filename">
'; ?>
</td>
</tr>
</table>
</div>
<?php endforeach;?>
</div>
</body>
</html>
COMMON.PHP
<?php
// These variables define the connection information for your MySQL database
$username = "";
$password = "";
$host = "";
$dbname = "";
// UTF-8 is a character encoding scheme that allows you to conveniently store
// a wide varienty of special characters, like ¢ or €, in your database.
// By passing the following $options array to the database connection code we
// are telling the MySQL server that we want to communicate with it using UTF-8
// See Wikipedia for more information on UTF-8:
// http://en.wikipedia.org/wiki/UTF-8
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
// A try/catch statement is a common method of error handling in object oriented code.
// First, PHP executes the code within the try block. If at any time it encounters an
// error while executing that code, it stops immediately and jumps down to the
// catch block. For more detailed information on exceptions and try/catch blocks:
// http://us2.php.net/manual/en/language.exceptions.php
try
{
// This statement opens a connection to your database using the PDO library
// PDO is designed to provide a flexible interface between PHP and many
// different types of database servers. For more information on PDO:
// http://us2.php.net/manual/en/class.pdo.php
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
}
catch(PDOException $ex)
{
// If an error occurs while opening a connection to your database, it will
// be trapped here. The script will output an error and stop executing.
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code
// (like your database username and password).
die("Failed to connect to the database: " . $ex->getMessage());
}
// This statement configures PDO to throw an exception when it encounters
// an error. This allows us to use try/catch blocks to trap database errors.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// This statement configures PDO to return database rows from your database using an associative
// array. This means the array will have string indexes, where the string value
// represents the name of the column in your database.
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// This block of code is used to undo magic quotes. Magic quotes are a terrible
// feature that was removed from PHP as of PHP 5.4. However, older installations
// of PHP may still have magic quotes enabled and this code is necessary to
// prevent them from causing problems. For more information on magic quotes:
// http://php.net/manual/en/security.magicquotes.php
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
function undo_magic_quotes_gpc(&$array)
{
foreach($array as &$value)
{
if(is_array($value))
{
undo_magic_quotes_gpc($value);
}
else
{
$value = stripslashes($value);
}
}
}
undo_magic_quotes_gpc($_POST);
undo_magic_quotes_gpc($_GET);
undo_magic_quotes_gpc($_COOKIE);
}
// This tells the web browser that your content is encoded using UTF-8
// and that it should submit content back to you using UTF-8
header('Content-Type: text/html; charset=utf-8');
// This initializes a session. Sessions are used to store information about
// a visitor from one web page visit to the next. Unlike a cookie, the information is
// stored on the server-side and cannot be modified by the visitor. However,
// note that in most cases sessions do still use cookies and require the visitor
// to have cookies enabled. For more information about sessions:
// http://us.php.net/manual/en/book.session.php
session_start();
// Note that it is a good practice to NOT end your PHP files with a closing PHP tag.
// This prevents trailing newlines on the file from being included in your output,
// which can cause problems with redirecting users.
I want to key down my search results and for this i am using this jquery below:
$('#ChangeAccountInput').keydown(function(e)
{
if(e.keyCode==40)
{
$('#results').css("background-color", "yellow");
}
});
But the problem is, it is applying to the full div not on a single value.
Above jquery applying to all like:
html:
<input id='ChangeAccountInput' class="InputBorder" placeholder="Search" style="display: none; margin-top: -79px; margin-left: -226px; border: 1px solid rgb(133, 133, 133); font-family: calibri; font-size: 15px; color: rgb(68, 68, 68); padding-left: 6px; padding-right: 21px; width: 182px"/>
<i class="icon-search" id="iconsearch1" style="display: none; margin-top: -37px; margin-left: -22px;"></i>
<div id="results" stlye='display: none'></div>
php:
while($row = oci_fetch_assoc($query))
{
echo "<a href='#'>";
echo '<font>'.$row['ACCOUNT_TYPE'].'</font>';
echo '<br>';
echo "<div style='border: 1px solid #AAAAAA; margin-left: -4px'></div>";
echo "</a>";
}
ajax:
$.ajax
({
type: 'GET',
url: 'Reports/Account Search.php',
data: 'GetAccountInput='+GetAccountInput,
success: function(data)
{
$('#results').html(data);
$('#results').show();
}
});
Account Search File:
<?php
error_reporting(0);
$user = "fyp";
$pass = "fyp";
$host = "localhost/CRMP";
// Connection with the Oracle.
$con = oci_connect($user, $pass, $host);
// If connection is established with the Oracle or not.
if (!$con)
{
//header('location:../../../Extra/Error_Other.php');
}
else
{
//echo "Connected to Oracle.";
}
?>
<?php
$GetAccount = $_GET['GetAccountInput'];
if($GetAccount != '')
{
$query = oci_parse($con, "SELECT DISTINCT ACCOUNT_TYPE FROM ACCOUNTS WHERE ACCOUNT_TYPE LIKE '%".$GetAccount."%'");
oci_execute($query);
$check = oci_fetch_array($query);
if(empty($check))
{
echo "<a href='#'>";
echo "No Result Found";
echo "</a>";
}
while($row = oci_fetch_assoc($query))
{
echo "<a>";
echo $row['ACCOUNT_TYPE'];
echo '<br>';
echo "</a>";
echo "<div style='border: 1px solid #777A79; margin-left: -6px'></div>";
}
}
else
{
}
?>
Help would be apprciated.
I thought about this some more and I came up with a solution that will work for you. All you should have to do is add the kind of styling that you want and other animations as needed.
http://jsfiddle.net/2wk6Q/1095/
$('#ChangeAccountInput').keydown(function (e) { //not actually the down key though :-)
if ($('a').hasClass('yellowBack')) { // do any links have this class?
var selected = $('a.yellowBack'); // if the do, they are the 'selected' link
selected.removeClass('yellowBack'); // this cleans up the one that we move from
if (40 == e.keyCode) { // going down the list
if (selected.next().length == 0) {
// if there isn't another list item, highlight the first
$('#results a:first').addClass('yellowBack');
} else {
// add the class to the next item
selected.next().addClass('yellowBack');
}
} else { // going up the list
if (selected.prev().length == 0) {
// add the class to the last item if you have gone to the top of the list
$("#results a:last").addClass("yellowBack");
} else {
// add the class to the next one up the list
selected.prev().addClass('yellowBack');
}
}
} else {
// if none were initially selected, select the first one
$("#results a:first").addClass("yellowBack");
}
});
This will allow you to move up and down the returned list, no matter what length the list is. Proper styling will prevent scrollbar issues that you mentioned above.
EDIT: modifying PHP so that output matches latest fiddle -
while($row = oci_fetch_assoc($query))
{
echo "<div style='border-bottom: 2px solid #777A79; margin-left: -4px'>";
echo "<a href='#'>";
echo '<font>'.$row['ACCOUNT_TYPE'].'</font>';
echo "</a>";
echo "</div>";
}
The reason for the modification is because the PHP is essentially outputting HTML that is hard to work with in JavaScript. The OP is learning how to format ALL of his code, from back to front, so that it plays nicely together.