I am trying to make multiple buttons in PHP. I am new to html and PHP. I am unable to saw the problem in the code. Its not giving error but do nothing when I click on the button.
Here is the piece of my code
<html>
<head></head>
<body>
<table>
<tbody>
<tr>
</tr>
</tbody>
</table>
<table border="5" cellpadding="0" cellspacing="0" margin-bottom="1px" width="100%" style="color:navy">
<tbody>
<tr>
<td> <b> Teacher's Name </b> </td>
<td> <b> Courses </b> </td>
<td> <b> Feedback </b> </td>
</tr>
<!--?php while ($row = mysql_fetch_row($subjects)) {
$Teacher_Names = mysql_query("SELECT Name FROM teachers where Teacher_ID = $row[1]");
$Name = mysql_fetch_row($Teacher_Names)?-->
<tr>
<td>
<!--?php echo $Name[0];?--></td>
<td>
<!--?php echo $row[0]; ?--> </td>
<td>
<form method="POST" action="CourseFeedbackForm.php">
<img type="button" src="books.jpg" height="30" width="30" id="<?php $button.$count?>" name="submit" value="<?php $row[1]?>">
<!--?php $count = $count + 1; ?-->
<img src="horizontal1.jpg" height="30" style="padding-left:0px">
<img type="button" src="teachers.jpg" height="30" width="30" id="<?php $button.$count?>" name="submit" value="<?php $row[1]?>">
<!--?php $count = $count + 1; ?-->
</form></td>
</tr>
<!--?php } ?-->
</tbody>
</table>
</body>
</html>
It kind of took me a while to understand what you are doing there, but not I still did not understand everything. Why are you calling <img type="button">? In order to get a button, you know, that thing that you can click and it executes a piece of code, use <button type="submit"></button>. Almost everything you've done there is wrong. I'm not an expert, but I really can't see the reason you would try to use the <img> tag to create a button.
Offtopic: Learn to use <div></div>. It is much more flexible than a table, and table's are old and outdated.
Related
I will try to be more specific.
Search Results from an php/mysqli query are put into a table.
This is the code for the table:
<tr>
<td bgcolor="#FFFFFF" style="padding-right:7;" id="Photo1<?php echo $uid ?>">
<a href="../view_profile/view_profile.php?id=<?php echo $uid; ?>">
<img src="../../users/<?php echo $gender; ?>/<?php echo $email; ?>/Profile/<?php echo $img; ?>" style="height:70; width:70;">
</a>
</td>
<td onMouseOver="serched_name_over1(<?php echo $uid;?>)" onMouseOut="serched_name_out1(<?php echo $uid;?>)" width="500" bgcolor="#FFFFFF" id="Name_bg1<?php echo $uid; ?>">
<a href="../view_profile/view_profile.php?id=<?php echo $uid;?>" id="Name_font1<?php echo $uid;?>"><?php echo $name; ?>
</a>
</td>
</tr>
I run the query and results are shown on website.
Source Code:
<table cellspacing="0" border="0">
<tr>
<td bgcolor="#FFFFFF" style="padding-right:7;" id="Photo156">
<a href="../view_profile/view_profile.php?id=56">
<img src="../../users/Male/jonnycash#gmail.com/Profile/GABRIEL ALCANTAR ALCALA.png" style="height:70; width:70;">
</a>
<a href="../view_profile/view_profile.php">
<img src="../../users/Male/jonnycash#gmail.com/Profile/GABRIEL ALCANTAR ALCALA.png" style="height:70; width:70;">
</a>
</td>
<td onMouseOver="serched_name_over1(56)" onMouseOut="serched_name_out1(56)" width="500" bgcolor="#FFFFFF" id="Name_bg156">
<a href="../view_profile/view_profile.php?id=56" id="Name_font156">
Jonny Cash </a>
</td>
</tr>
<tr>
<td colspan="2"> <hr style="border-color:#CCCCCC;"> </td>
</tr>
</table>
Now, the info I want is shown on the website, however...
THE LINK does not work on the website (i click on the img and nothing), but on the Source Code it does (i click on the link and it takes me to page).
I have tried echoing in parts to construct the path, but no use. I tried and also, nothing. I tried using the htmlspecialchars and htmlentities. And nothing. I have even tried doing a regular html code inside the table along side the results... and nothing. It does not link.
What am I doing wrong?
If you need to see more code, please let me know to attach more.
Please help.
I send the data from the database to the screen with foreach.I do not see any results when I click the button.where do i make mistakes i ask you to help
<table class="table">
<thead class="thead-dark" align="center" >
<th >id</th>
<th >EğitimAdı</th>
<th >Adres</th>
<th >Onay </th>
</thead>
<tbody>
<form id="form1" action="" method="post">
<?php $i=1; foreach($dbb as $ac){ ; ?>
<tr align="center" >
<td > <?php echo $ac[0]; ?> </td>
<td > <?php echo $ac[1]; ?></td>
<td align="center"> <iframe width="360" height="115" src="<?php echo $ac[2]; ?>" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen ></iframe></td>
<td >
<button type="button" value="<?php echo $ac[0]; ?>" id="gonder" onclick="gonder('this.val()')">İzledim</button>
</td>
</tr>
<?php $i++; } ?>
</form> <p></p>
</tbody>
</table>
gonder.js send to the database
function gonder(deger){
$.ajax({
type:"post",
url:"isleme.php",
data:deger,
success:function(cevap) {
$("p").text(cevap);
}
})
}
isleme.php to view the screen
<?php
$b=$_POST['deger'];
echo $b;
?>
First you're missing parentheses:
onclick="gonder" has to be onclick="gonder()"
Secondly variable "deger" is empty because #id doesn't exist, try changing to:
var deger = $("#gonder").val();
I noticed you are iterating and having same id for all the elements. Ideally id should be unique in each of the document.
You can do either of the below:
prepare and have unique id for each iterative element.
Try removing id element since you are not dependent on click using id.
Please let me know, if it helps?
How do I create a jQuery hover to show a div when the mouse is over like twitter repla retweet and favorite?
Here is my HTML:
<div style="display:none;" id="blab">
<?php echo $blab_id; ?>
</div>
<a href="blab.php?id=<?php echo $blab_id; ?>">
<div class="blab_body" id="hover" value="Hide">
<table>
<tr>
<td valign="top">
<img src="<?php echo $profile_pic_info; ?>" class="blab_image" width="50" height="50" />
</td>
<td> </td>
<td>
<table>
<tr>
<td valign="top">
<a href="profile.php?id=$mem_id">
<strong><?php echo $added_fullname; ?></strong>
</a>
<?php echo $added_to_fullname; ?>
</td>
</tr>
<tr>
<td>
<?php echo $blab_body; ?>
</td>
</tr>
<tr>
<td>
<text style="color:gray;">
<?php echo $blab_date; ?>|<?php echo $device; ?>
</text>
</td>
</tr>
</table>
</td>
</tr>
</table>
<div style="background:#000; display:none;" id="id"> </div>
</div>
</a>
<hr />
and here is my JavaScript code:
$('#id').hide();
$('#hover').hover(function () {
var blab_id = $('#blab').text();
$('#id').show();
}, function () {
$('#id').hide();
});
It shows the div for the first one only.
You can only use a certain ID once on the whole page! If you insert more than one copy of this div on the page, your HTML code becomes invalid. That's why jQuery only attaches the event handler to the first element.
The solution is to use class="hover_enabled" instead of id="hover" as it is allowed to add the same class to multiple elements. Here is how you would do it in jQuery:
$('.hover_enabled').hover(function() { ...
The same thing applies to #id.
I have a simple PHP while loop which executes a list of tabular comments/posts from the SQL database. Each post has a reply hyperlink that that will open a textarea (form) below the post which will allow the user to reply to that specific post. It works fine for one post, but when there are multiple posts the jQuery opens all of the textareas for each post. I assume that this is an issue with me calling identical classes using jQuery. But I am not sure how to deal with it. What I would like to achieve is allowing the user to click on a reply hyperlink within a specific post and only that textarea will appear underneath and not all of them at the same time.
Here is the PHP code to generate the list of posts with the reply feature.
<?php>
echo "<table width=\"100%\" border=\"0\" cellspacing=\"10\">";
while ($row2 = mysql_fetch_assoc($res))
{
echo "
<tr>
<td>
<span class=\"anonname\">Anon" . $row2['uid'] . " </span>
<span class=\"smalltext\"> says:</span>
</td>
</tr>
<tr>
<td>
<span class=\"messagetext\">" . $row2['msg'] . "</span></td>
</tr>
<tr>
<td>
<div class=\"replystyle\"><span class=\"replytext\"><a href=\"#\"
class=\"replybtn\">Reply</a> ⋅ Like </span> <span
class=\"replytext\" style=\"float:right;\"><span class=\"timetext\">" .
$row2['timestamp'] . "</span>Report</span></div>
</td>
</tr>
<tr>
<td>
<div id=\"replymsgbox\">
<form id=\"messaging\" action=\"\" method=\"post\" accept-charset=\"UTF-8\">
<div class=\"tarea\">
<textarea name=\"message\" rows=\"2\" class=\"txtbx\"></textarea>
</div>
<span style=\"float:right;\"><input name=\"submit\" class=\"signupbtn\"
type=\"submit\" value=\"share\" /></span><br/><br/>
</form>
</div>
</td>
</tr>";
}
echo "</table>";
}
?>
Here is the jQuery
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$('.replymsgbox').hide();
$('.replybtn').click(function(){
$('.replymsgbox').slideToggle('fast');
});
});
</script>
Any help would be appreciated.
With $('.replymsgbox') selector, you are getting all the element having such class.
To get just the one related to the button, use:
$('.replybtn').click(function(){
$('.replymsgbox', $(this).parent().parent().next()).slideToggle('fast');
});
You are narrowing research of a .replymsgbox element inside next <tr> this way.
(This isn't an answer, just an observation; comments don't allow such formatting)
This is what I wrote about in my comment to your question:
<table width="100%" border="0" cellspacing="10">
<?php
while ($row2 = mysql_fetch_assoc($res)) {
?>
<tr>
<td>
<span class="anonname">Anon<?php echo $row2['uid'];?></span>
<span class="smalltext"> says:</span>
</td>
</tr>
<tr>
<td>
<span class="messagetext"><?php echo $row2['msg']; ?></span></td>
</tr>
<tr>
<td>
<div class="replystyle"><span class="replytext"><a href="#"
class="replybtn">Reply</a> ⋅ Like </span>
<span class="replytext" style="float:right;"><span
class="timetext"><?php echo $row2['timestamp']; ?></span>Report</span></div>
</td>
</tr>
<tr>
<td>
<div id="replymsgbox">
<form id="messaging" action="" method="post" accept-charset="UTF-8">
<div class="tarea">
<textarea name="message"rows="2" class="txtbx"></textarea>
</div>
<span style="float:right;"><input name="submit" class="signupbtn"
type="submit" value="share" /></span><br/><br/>
</form>
</div>
</td>
</tr>
<?php } ?>
</table>
See how that cleans up much better? Now if you want to make changes to your HTML, you don't have to through all the complex escaping machinations.
i have one php code for button creation
for($i=1;$i<=$n;$i++)
{
$row=mysql_fetch_array($result);
if($row['btn_color']==1)
$btbg="side-button5.png";
if($row['btn_color']==2)
$btbg="side-button6.png";
if($row['btn_color']==3)
$btbg="side-button7.png";
if($row['btn_color']==4)
?>
<br>
<table width="200" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="images/<?php echo $btbg ; ?>" style="background-repeat:no-repeat"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="66">
<div align="center" class="buttonside">
<p>
<a class="buttonside" href="vpa.php?pgid=<?php echo $row['page_id']; ?>">
<?php echo $row['btn_text']?></p>
</a>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
?>
this code is working fine but the link is on text, i want to put link on full button(background)
Thanks
To make the button 'linkable', you'll need to wrap the <a> tag around it.
However, you're going to need to change your HTML markup structure - you can't wrap an anchor around a table cell!