I'm currently busy with a ticketsystem. A headline will be displayed. When the headline has over 40 characters, the headline will be cut and the '...' will be added. Now, when I try to link the headlines to its messages, it won't create a link. I'm using Ajax to do this without a page refresh, but no links are being created, which means that the full ticket wont be openend. I've tried several things but I cant get it to work. I'm also not that familiar with it :')
This is my piece of JS:
//Show ticket
function showTicket(id) {
$.ajax({url:"readTicket.php?ticket_id=" + id});
}
This is the piece of code supposed to link the headlines:
<?php echo '<a id="showTicketNow" onclick="showTicket('.$stt["ticket_id"].')">' ?>
<?php if(strlen($stt['subject']) > 40) $stt['subject'] = substr($stt['subject'], 0, 40).'...';
echo $stt['subject'] ?>
<?php echo '</a>' ?>
This is my readTicket.php
$user_id = $_SESSION['user_id'];
$ticket_id = mysqli_real_escape_string($mysqli, $_GET['ticket_id']);
$getTicketInfo = mysqli_query($mysqli,"SELECT * FROM tickets WHERE ticket_id = '$ticket_id' AND user_id = '$user_id'");
while ($row=mysqli_fetch_array($getTicketInfo)) {
$subject = $row['subject'];
$message = $row['message'];
}
echo '<div class="showTicket display subject">'.stripslashes($subject).'</div>
<div class="showTicket display message">'.stripslashes($message).'</div>';
Thanks in advance..
Try this, you were missing all of the syntax goodness.
echo'<a id="showTicketNow" onclick="showTicket('.$stt["ticket_id"].')">';
if(strlen($stt['subject']) > 40){
$stt['subject'] = substr($stt['subject'], 0, 40).'...';
}
echo $stt['subject'];
echo '</a>';
You need to specify href attribute of <a> tag, something like this:
<?php echo '<a href="javascript:void(0);" id="showTicketNow" onclick="showTicket('.$stt["ticket_id"].')">' ?>
Related
This div act as a button. Whenever I click one, the page goes to the page name "teacherinfo.php". The "Sample" text is used as the name of the teacher. The problem is when I click the "Sample2" the Sample text appear on the "teacherinfo.php" page.
Here is the script for going to "teacherinfo.php":
<?php
while ($row = mysqli_fetch_array($query)) {
echo '<div class="announcementSlider" id="click">
<img src="pictures/blank photo.png" class="teacherpic"><br>
<span name="LastName">'.$row['LastName'].'</span><br>
<span>'.$row['Grade'].' - </span>
<span>'.$row['Section'].'</span>
</div>';
}
?>
<script type="text/javascript">
var a = document.getElementsByClassName("announcementSlider");
for (i=0; i<a.length; i++) {
a[i].onclick = function () {
location.href = "teacherinfo.php";
};
}
</script>
Code for displaying the text in "teacherinfo.php":
<div class="leftForm hide-on-med-and-down">
<img src="pictures/default-avatar-250x250.png">
<p class="name"><?php echo $name3; ?></p>
<p class="section"><?php echo $grade3; ?>-<?php echo $section; ?></p>
</div>
Code for retrieving data in database:
$sql3 = mysqli_query($db,"select * from teacherinfo");
$row3 = mysqli_fetch_array($sql3,MYSQLI_ASSOC);
$name3 = $row3['LastName'];
$grade3 = $row3['Grade'];
$section3 = $row3['Section'];
I want to use the "'.$row['LastName'].'" as a where clause in mysqli_query($db,"select * from teacherinfo"). How can I do that? or is there another solution to this issue?
First of all, I don't understand why you use javascript when you can use simple a tag with correct href:
<?php
while ($row = mysqli_fetch_array($query)) {
echo '<a class="announcementSlider" href="teacherinfo.php?id=' . $row['id'] . '">
<img src="pictures/blank photo.png" class="teacherpic"><br>
<span name="LastName">'.$row['LastName'].'</span><br>
<span>'.$row['Grade'].' - </span>
<span>'.$row['Section'].'</span>
</a>';
}
?>
Here, I suppose that every teacher in your mysql-table has some unique id field.
On teacherinfo.php you access id as $_GET['id'] and create a query like (here I skip security part, but $_GET['id'] can be forged and therefore contain some insecure data, you have to check it):
sql3 = mysqli_query($db,"select * from teacherinfo where id = " . $_GET['id']);
$row3 = mysqli_fetch_array($sql3,MYSQLI_ASSOC);
$name3 = $row3['LastName'];
$grade3 = $row3['Grade'];
$section3 = $row3['Section'];
I am having problems implementing my $myimage into my echos for session.My goal is to put the $myimage into the echo but idk how to do it so i am hoping someone who comes across my post does.I have a gallery of photos and at the moment when i click on something it doesnt send the photo i clicked on rather on the last photo i added.
<?php
while ($row = mysqli_fetch_assoc($result)) {
$myimage="".$row['image']."";
$_SESSION['myimage'] = $myimage;
echo "<div class='img-single'>
<a href='images/fpage.php'><img class='i' src='images/".$row['image']."'>
</a><figcaption class='figcaption'>".$row['image_text']."</figcaption>
</div>";
}
?>
trying to make something look like this
<?php
while ($row = mysqli_fetch_assoc($result)) {
//$myimage="".$row['image']."";
$_SESSION['myimage'] = $myimage;
echo "<div class='img-single'>
<a href='images/fpage.php'><img class='i'
src='images/$myimage="".$row['image']."";'>
</a><figcaption class='figcaption'>".$row['image_text']."</figcaption>
</div>";
}
?>
In one of my pages, I have an <a> tag. When I click it, I am passing the variable as a GET parameter and retrieving it in the same page and displaying the details.
The code to get the parameters:
if(isset($_GET['CatId']))
{
$CatId= $_GET['CatId'];
}
else $CatId=0;
if(isset($_GET['MainProductId']))
{
$MainProductId= $_GET['MainProductId'];
$FilterAllProductQuery ="WHERE Product.MainProductId = '$MainProductId'";
$FilterProductQuery = "AND Product.MainProductId = '$MainProductId'";
}
else
{
$MainProductId=0;
$FilterAllProductQuery="";
$FilterProductQuery="";
}
The <a> tag:
<a href='Products.php?CatId=<?php echo $CatId;?>&MainProductId=<?php echo $id;?>' ><?php echo $row["MainProdName"] ?></a>
The details to be displayed:
if($CatId == 0)
{$sql = "SELECT *,Product.Id AS ProdId, Product.Name as ProdName FROM Product $FilterAllProductQuery ";}
else
{$sql = "SELECT * ,Product.Id AS ProdId, Product.Name as ProdName FROM Product INNER JOIN MainProduct ON MainProduct.Id = Product.MainProductId
INNER JOIN Category ON Category.Id = MainProduct.CategoryId WHERE Category.Id = '$CatId' $FilterProductQuery ";}
$result1 = $dbcon->query($sql);
if ($result1->num_rows > 0) {
while ($row = $result1->fetch_assoc()) {
$id = $row["ProdId"];
// $image=$row["ImagePath1"];
$qty = $row["Quantity"];
?>
<li class="col-lg-4">
<div class="product-box">
<span class="sale_tag"></span>
<div class="row">
<img src='themes/images/<?php echo $row["ImagePath1"]; ?>' height='200' width='250'> </a></div></div></li>
Now the code is working fine, but what's happening is that when I click the <a> tag, as I am passing the get parameters, the page is refreshing. As all the code are on the same page, I don't want the page to be refreshed. For that, I need to use Ajax request. How can I do that?
I would make an onclick() event on the a tag like so:
<?php echo '<a c_id="'.$CatId.'" MainProductId="'.$id.'" onclick="sendProduct()">'.$row["MainProdName"].'</a>';
Afterwards i would in a .js file write a simple function called sendProduct() and inside i would do an ajax request to a page named ex: insertproduct.php, get the information back and Insertproduct.php would process the data and you could use .html() or .append() to assign the data to the div showing the data with a normal id.
The c_id, MainProductId are custom attributes you could recieve in the .js file as $("#youraTag").attr("c_id");
There's a really good guide here on basic ajax: https://www.youtube.com/watch?v=_XBeGcczFJo&list=PLQj6bHfDUS-b5EXUbHVQ21N_2Vli39w0k&index=3&t=1023s
First you have to remove the href of the link and give it an id.
<a id='link'>
<?php echo $row["MainProdName"] ?>
</a>
Then you put this jQuery into your page. Note, you need to have a div in which you are going to put in all your obtained results. I reffered to this div in the code as #mydiv.
$("#link").click(function(){
$("#mydiv").load("Products.php?CatId=<?php echo $CatId;?>&MainProductId=<?php echo $id;?>");
});
I'm working on code that truncates an database entry and puts that onto a webpage, but because of the truncation it will often cut off in the middle of link anchor tag. Usually i can deal with this by adjusting the amount of characters being pulled, but because 5 entries are pulled at a time to be displayed i end up going back and forth at lot finding the percent balance as i can adjust the characters up which fixes one entry, but causes another problem with another entry.
I need to come up with a way to have a php function automatically close these so they don't cause problems and make the page a giant link.
$SQL = "SELECT * FROM Words WHERE Date_Created = DATE('2016-10-06') AND category = 'Article' ORDER BY ID DESC LIMIT 5";
$result = mysql_query($SQL);
while($row = mysql_fetch_array($result))
{
echo '<div class="storylist2">';
echo "<br/>";
echo '<h2>' .stripslashes($row['Title']). '</h2>';
$s = stripslashes($row['Word']);
$s = substr($s, 0,800); //adjust as necessary
$s = substr($s, 0, strrpos($s, "."));
$s .= "...";
echo '<h6>'. $row['Display_Date'].'</h6>';
echo '<h6>'. $row['Author']. '</h6>';
echo closetags("$s");
echo "<br/>";
if($row['url'] != "")
{
echo "<br/>";
echo '<span class="articlelink">(more)';
echo "<br/>";
}
else {
echo "<br/>";
echo '(more)</span>';
echo "<br/>";
}
echo "<br/>";
echo "<br/>";
echo "</div><hr style=\"color: #006699; margin: 10px 20px; \"/>";
I have listed above the code that i currently have for the pulling the entries onto the webpage, I've heard that there is way to make sure the truncation doesn't cut off in the middle of a tag but in all honesty i don't know how to do this. Also in the past few days i have found some PHP that closes tags which is referenced by this echo closetags("$s"); but unfortunately i haven't been able to get to work for the anchor tags. Please help thank you!
You can remove the <a> tags and leave just the anchor text for any string by running it through preg_replace before truncating it:
$no_a_tags = preg_replace('/<a.*?>([^>]*)</a>/i', '$1', $with_a_tags);
I have here my href link being echoed:
echo "<td><a href='../php/borrowersname.php?acc_number=".$row['acc_number']."'>".$row['title']."</a></td>";
And I have here a sample on how to create a Pop-Up:
Test
How to combine this to my href link above being echoed with the "javascript ... ..." enclosed by ("" && '')?
Thanks for another new learning.
You can escape the ""
<?php
echo "Test";
?>
In the 'borrowersname.php' page, you can get the value of 'acc_number' like this:
<?php
$value = $_GET['acc_number'];
//do something with $value;
?>