你是要 判断滚动高度大于50的时候设置黑色背景应该是添加scroll事件,事件里面判断滚动高度,而且是$(window).scrollTop

支付宝加好友偷能量挖 回复weixin_38527106: DEMO http://www.w3dev.cn/article/20131101/article-catalog-jquery-plugin.aspx
大约 3 年之前 回复
weixin_38527106 谢谢兄弟
大约 3 年之前 回复
weixin_38527106 我会了
大约 3 年之前 回复
weixin_38527106 兄弟,能不能写个简单的代码给我看看,就是滚动到一定高度换背景的
大约 3 年之前 回复
Csdn user default icon

<div class="post-text" itemprop="text"> <p>Okay, so I've inherited a mess of code I need to upgrade from a very old version of prototype to jquery 3.2.1 embedded in a very old website that uses php and smarty templates (ugh). </p> <p>A user who is logged in can generate up to five case numbers; they are stored in the session variables and in the database. these are throwaway numbers -- if they aren't used, they are eventually recycled. While a user is logged in, they can only generate a maximum of 5 numbers.</p> <p>I've translated the old prototype code to the jquery equivalent, and it is only firing intermittently. The function call to retrieve a new case number is bound to a button that is loaded in the document.ready part of the script.</p> <p>edit: including the whole shebang</p> <pre><code> function GetNewCaseNumber() { if (CurrentNumber &lt;= 5) { if (CurrentNumber == 1) { NewNumber = true; $('#getnumber').val("Get Additional Case Number"); } else { NewNumber = confirm("Are you sure you want another Case Number?"); } console.log("CurrentNumber: %s, NewNumber: ", CurrentNumber, NewNumber); // Show Confirm Dialog if (NewNumber == true) { // Get another case number // this fires sometimes, sometimes doesn't. why? console.log("Div tag to update= %s", "CaseNumber" + CurrentNumber); console.log("Current html content value= %s",$('#CaseNumber' + CurrentNumber).html()); if (($.trim($('#CaseNumber' + CurrentNumber).html()) == '') || ($('#CaseNumber' + CurrentNumber).val() == null)) { $.ajax({ url: ("../ajax.php?event=ObtainCaseNumber&amp;number=" + CurrentNumber), async: true, type: "GET", dataType: "json", success: function (server_response) { console.log("Current Case Number %s", server_response); $('#CaseNumber' + CurrentNumber).text(server_response); $('#CaseNumber' + CurrentNumber).fadeIn("slow"); CurrentNumber++; }, error: function (server_response) { alert("There has been an ajax error: " + server_response); } }); $('#CaseNumber' + CurrentNumber).fadeIn("slow"); /* there are at least 2 casenumbers, show "these numbers" */ $('#thisnumber').html("these numbers"); } } // Hide Additional Buttons if this is the last one if (CurrentNumber &gt;= 6) { $("#getnumber").fadeOut("slow"); } } else { alert("You cannot generate anymore Case Number's at this time."); $("#getnumber").fadeOut("slow"); } } </code></pre> <p>I've edited that function to move where the CurrentNumber was incrementing. It now appears to work perfectly. Thank you everyone for your swift help and replies!</p> <pre><code> function CheckCurrentCaseNumbers() { // Check what case numbers we already have $(".caseList").each(function() { if ($('#CaseNumber' + CurrentNumber).html() != "") { console.log("CCCN CurrentCaseNumber: %s", 'CaseNumber' + CurrentNumber); $('#CaseNumber' + CurrentNumber).fadeIn("slow"); CurrentNumber++; console.log("CCCN CurrentNumber: %s", CurrentNumber); } }); /* If there's at least 2 casenumbers, show "these numbers" */ if ($("#CaseNumber2").html != "") { $("#thisnumber").html("these numbers"); } if ($("#CaseNumber1").html()) { $("#getnumber").val("Get Additional Case Number"); } $("#Loading").fadeOut("3000"); } </code></pre> <p>this is fired by an on click event on a button binded in the document.ready tag, and NewNumber==true is an alert confirm. It's supposed to be updating these divs:</p> <pre><code> &lt;div id="CaseNumber1" class="caseList" style="display:none;"&gt;{$casenumbers.1}&lt;/div&gt; &lt;div id="CaseNumber2" class="caseList" style="display:none;"&gt;{$casenumbers.2}&lt;/div&gt; &lt;div id="CaseNumber3" class="caseList" style="display:none;"&gt;{$casenumbers.3}&lt;/div&gt; &lt;div id="CaseNumber4" class="caseList" style="display:none;"&gt;{$casenumbers.4}&lt;/div&gt; &lt;div id="CaseNumber5" class="caseList" style="display:none;"&gt;{$casenumbers.5}&lt;/div&gt; </code></pre> <p>New console log:</p> <p>Init...</p> <pre><code>CurrentNumber: 1 (index):23 generating case number (index):24 Current Number: 1 (index):132 CurrentNumber: 1, NewNumber: true (index):137 Div tag to update= CaseNumber1 (index):138 Current html content value= (index):146 Current Case Number 11481593 (index):23 generating case number (index):24 Current Number: 2 (index):132 CurrentNumber: 2, NewNumber: true (index):137 Div tag to update= CaseNumber2 (index):138 Current html content value= (index):146 Current Case Number 11481594 (index):23 generating case number (index):24 Current Number: 3 (index):132 CurrentNumber: 3, NewNumber: true (index):137 Div tag to update= CaseNumber3 (index):138 Current html content value= (index):146 Current Case Number 11481595 (index):23 generating case number (index):24 Current Number: 4 (index):132 CurrentNumber: 4, NewNumber: true (index):137 Div tag to update= CaseNumber4 (index):138 Current html content value= (index):146 Current Case Number 11481596 (index):23 generating case number (index):24 Current Number: 5 (index):132 CurrentNumber: 5, NewNumber: true (index):137 Div tag to update= CaseNumber5 (index):138 Current html content value= (index):146 Current Case Number 11481597 (index):23 generating case number (index):24 Current Number: 6 </code></pre> <p>Thank you for your help!</p> <p>Julie</p> <p>Here's my document ready:</p> <pre><code> var CurrentNumber = 1; $(document).ready(function() { $('#getnumber').val("Obtain Case Number"); $("#Loading").fadeIn("slow"); /* console logging for debugging -- will be removed */ console.log("Init..."); console.log("CurrentNumber: %s", CurrentNumber); CheckCurrentCaseNumbers(); $('#getnumber').on( "click", function() { console.log( "generating case number" ); console.log( "Current Number: %s", CurrentNumber ); GetNewCaseNumber(); }); }); </code></pre> <p>The button that fires this:</p> <pre><code> &lt;form&gt; &lt;input type="button" value="Obtain Case Number" id="getnumber" /&gt; &lt;/form&gt; </code></pre> <p>CurrentNumber needs to be global (I know jQuery doesn't really have globals) so I'm initializing it first thing</p> </div>


<div class="post-text" itemprop="text"> <p>I am trying to load my sidebars in my while loop by using if statements that call them after a certain number of posts. It's important to note that I am using AJAX code (provided below) to load in posts on scroll and I believe it may be causing the issue. </p> <p>Though they are sidebars, they are not physically a sidebar but rather content loaded between posts.</p> <p>I've tried for a week to locate the problem but I cannot seem to get the sidebars to load with AJAX as a if statement in the while loop.</p> <p><em>Important to note:</em> The sidebar will load after the number of posts if it's not loaded through AJAX. So if it's in the initial load, the sidebars load. But when you continue to scroll to say the third or fourth bar it will not load and the AJAX will only load the <code>(parts/content)</code>.</p> <p>I need to either be able to resolve the if statement so it works within the while loop that loads through AJAX or I'm open to an alternate solution as long as it doesn't remove the AJAX.</p> <p>A lot of work has been put into making this loop work and help is greatly appreciated!</p> <p><strong>front-page.php</strong></p> <pre><code> &lt;?php $current_page = max( 1, get_query_var( 'paged' ) ); $the_query = new WP_Query( array( 'cat' =&gt; '-21', 'post_type' =&gt; 'post', 'posts_per_page' =&gt; 5, 'paged' =&gt; $current_page, 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'topics', 'operator' =&gt; 'NOT EXISTS', 'field' =&gt; 'term_id', 'terms' =&gt; $term_id ) ) ) ); wp_localize_script( 'my_loadmore', 'misha_loadmore_params', array( 'ajaxurl' =&gt; admin_url( 'admin-ajax.php', 'relative' ), 'posts' =&gt; json_encode( $the_query-&gt;query_vars ), 'current_page' =&gt; $current_page, 'max_page' =&gt; $the_query-&gt;max_num_pages ) ); ?&gt; &lt;div id="main" class="container-fluid"&gt; &lt;?php if ($the_query-&gt;have_posts()) : ?&gt; &lt;?php $count = 0; ?&gt; &lt;?php while ($the_query-&gt;have_posts()) : $the_query-&gt;the_post(); get_template_part( 'parts/content', get_post_format() ); ?&gt; &lt;!-- This parts/content loads --&gt; &lt;?php $count++; ?&gt; &lt;!-- the dynamic_sidebar does not load --&gt; &lt;?php if ($count == 2 &amp;&amp; is_active_sidebar('sidebar1') ) : ?&gt; &lt;div class="side-container first-side"&gt; &lt;?php dynamic_sidebar('sidebar1'); ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;?php if ($count == 10 &amp;&amp; is_active_sidebar('sidebar2') ) : ?&gt; &lt;div class="side-container first-side"&gt; &lt;?php dynamic_sidebar('sidebar2'); ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;?php if ($count == 20 &amp;&amp; is_active_sidebar('sidebar3') ) : ?&gt; &lt;div class="side-container third-side"&gt; &lt;?php dynamic_sidebar('sidebar3'); ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt; &lt;?php wp_reset_postdata(); ?&gt; &lt;?php get_footer(); ?&gt; &lt;/div&gt;&lt;!-- END CONTAINER --&gt; </code></pre> <p><strong>parts/content -- this loads as expected including code if it's helpful</strong></p> <pre><code>&lt;div class="row post"&gt; &lt;!-- Post is mentioned in the below JS to load --&gt; &lt;div class="col-sm-5"&gt; &lt;h2&gt;Text&lt;/h2&gt; &lt;/div&gt; &lt;div class="col-sm-7"&gt; &lt;h3&gt;text&lt;/h3&gt; &lt;/div&gt; &lt;/div&gt;&lt;!-- END ROW--&gt; </code></pre> <p><strong>sidebar code - works when initially loaded but doesn't when AJAX calls on this code such as the last two sidebars in front-page.php</strong></p> <pre><code>&lt;?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?&gt; &lt;?php while( $flexible_posts-&gt;have_posts() ) : $flexible_posts-&gt;the_post(); global $post; ?&gt; &lt;div class="sidebar-area"&gt; //sidebar code here } endwhile; ?&gt; </code></pre> <p><strong>myloadmore.js - AJAX Call</strong></p> <pre><code>jQuery(function($){ var canBeLoaded = true, bottomOffset = 2000; $(window).scroll(function(){ if ( misha_loadmore_params.current_page &gt;= misha_loadmore_params.max_page ) { return; } var data = { 'action': 'loadmore', 'query': misha_loadmore_params.posts, 'page' : misha_loadmore_params.current_page }; if( $(document).scrollTop() &gt; ( $(document).height() - bottomOffset ) &amp;&amp; canBeLoaded == true ){ $.ajax({ url : misha_loadmore_params.ajaxurl, data: data, type: 'POST', beforeSend: function( xhr ){ // AJAX call is in process, we shouldn't run it again until complete canBeLoaded = false; }, success:function(data){ if( data ) { $('#main').find('div.post:last-of-type').after( data ); // where to insert posts canBeLoaded = true; // the ajax is completed, now we can run it again misha_loadmore_params.current_page++; bottomOffset = ( $( '#main &gt; div.post:last' ).offset() || {} ).top } } }); } }); }); </code></pre> <p><strong>functions.php - Added for further context</strong></p> <pre><code>function misha_my_load_more_scripts() { wp_register_script( 'my_loadmore', get_stylesheet_directory_uri() . '/js/myloadmore.js', array( 'jquery' ), '', true ); wp_enqueue_script( 'my_loadmore' ); } add_action( 'wp_enqueue_scripts', 'misha_my_load_more_scripts' ); function misha_loadmore_ajax_handler() { $args = json_decode( wp_unslash( $_POST['query'] ), true ); $args['paged'] = $_POST['page'] + 1; // load the next page $the_query = new WP_Query( $args ); if ( $the_query-&gt;have_posts() ) : while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); get_template_part( 'parts/content', get_post_format() ); endwhile; endif; wp_die(); } add_action( 'wp_ajax_loadmore', 'misha_loadmore_ajax_handler' ); // Authenticated users add_action( 'wp_ajax_nopriv_loadmore', 'misha_loadmore_ajax_handler' ); // Non-authenticated users </code></pre> </div>


``` package com.ibm.ajax.app1.entity; public class WebUser { private String uname; public WebUser(String uname){ this.uname=uname; } public String getUname() { return uname; } public void setUname(String uname) { this.uname = uname; } } ``` ``` package com.ibm.ajax.app1.dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.List; import java.util.Vector; import com.ibm.ajax.app1.entity.WebUser; public class WebUserDao { public List<WebUser> queryList() throws Exception{ String username="gdx"; String password="wazzh"; String url="jdbc:oracle:thin:@//localhost:1521/orcl"; String driver="oracle.jdbc.driver.OracleDriver"; List<WebUser> lists=new Vector<WebUser>(); Class.forName(driver); Connection conn=DriverManager.getConnection(url, username, password); Statement stmt =conn.createStatement(); ResultSet rs=stmt.executeQuery("select UNAME from webUser"); while(rs.next()){ WebUser webuser=new WebUser(rs.getString("UNAME")); lists.add(webuser); } return lists; } } ``` ``` package com.ibm.ajax.app1.service.impl; import java.util.List; import com.ibm.ajax.app1.dao.WebUserDao; import com.ibm.ajax.app1.entity.WebUser; import com.ibm.ajax.app1.service.IWebUserService; public class WebUserServiceImpl implements IWebUserService { private WebUserDao webuserdao= new WebUserDao(); @Override public List<WebUser> getWebUserList() throws Exception { List<WebUser> lists= webuserdao.queryList(); return lists; } } ``` ``` package com.ibm.ajax.app1.service; import java.util.List; import com.ibm.ajax.app1.entity.WebUser; public interface IWebUserService { //获取我建立的实体对象WebUser的list表 public List<WebUser> getWebUserList() throws Exception; } ``` ``` package com.ibm.ajax.app1.servlet; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.ibm.ajax.app1.entity.WebUser; import com.ibm.ajax.app1.service.IWebUserService; import com.ibm.ajax.app1.service.impl.WebUserServiceImpl; /** * Servlet implementation class ValiateUserNameServlet */ public class ValiateUserNameServlet extends HttpServlet { private static final long serialVersionUID = 1L; private IWebUserService webuserservice; @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { webuserservice = new WebUserServiceImpl(); try{ List<WebUser> userNames=webuserservice.getWebUserList(); System.out.println(userNames); //这之上的是写的从数据库调取的语句 String userName=request.getParameter("userName"); String result=null; if(userNames.contains(userName) ){ result="<font color='red'>该用户已存在</font>"; } else{ result="<font color='green'>该用户不存在</font>"; } System.out.println("sdf"); response.setContentType("text/html ; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().print(result); } catch(Exception ex){ System.out.println(ex); } } } ``` ``` <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript" src="${pageContext.request.contextPath }/scripts/jquery-1.7.2.js "></script> <script type="text/javascript"> $(function(){ $(":input[name='username']").change(function(){ var val=$(this).val(); val=$.trim(val); if(val!=" "){ var url="${pageContext.request.contextPath }/valiateUserName"; var args={"userName":val,"time":new Date()}; $.post(url,args,function(data){ $("#message").html(data); }); } }); }) </script> </head> <body> <form action="" method="post"> UserName:<input type="text" name="username" /> <div id="message"></div> <input type="submit" value="Submit" /> </form> </body> </html> ```


<div class="post-text" itemprop="text"> <p>I have two input fields. One is to search auto suggest product names using <a href="http://jqueryui.com/autocomplete/" rel="nofollow">jquery.autocomplete</a>, and in my database I have column name <code>product left</code>, and I want to display it in the second input, is that possible?</p> <p>For example: I have a product called <code>apple</code> with <code>product left</code> of <code>30</code>. <code>apple</code> will display in the first input field after typing, and at same time <code>30</code> must appear in the <code>second field</code>. </p> <pre><code>&lt;form action="sales.php" method="post"&gt; &lt;input name="productlist" type="text" id="productlist" size="20"/&gt; &lt;input name="productleft" type="text" value=""/&gt; &lt;/form&gt; </code></pre> <p><strong>call jquery ui</strong></p> <pre><code>&lt;script type="text/javascript" src="js/jquery.autocomplete.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $("#productlist").autocomplete("psuggest.php", { selectFirst: true }); }); &lt;/script&gt; </code></pre> <p><strong>inside psuggest.php</strong></p> <pre><code>&lt;?php $q=$_GET['q']; $my_data=mysql_real_escape_string($q); $mysqli=mysqli_connect('localhost','root','','saganatracker') or die("Database Error"); $sql="SELECT pdesc FROM products WHERE pdesc LIKE '%$my_data%' ORDER BY pdesc"; $result = mysqli_query($mysqli,$sql) or die(mysqli_error()); if($result) { while($row=mysqli_fetch_array($result)) { echo $row['pdesc']." "; } } ?&gt; </code></pre> </div>

jquery / ajax使用用户输入作为条件运行php查询,然后显示没有页面刷新的查询结果

<div class="post-text" itemprop="text"> <p>I've spent the last 24 hours trying to find an answer, and while there are similar questions, the answers seem to be either more complicated than my use-case (so I don't understand it), or I find low-quality questions/answers.</p> <p>My title really says it all, except for my code, but to reiterate in full sentences: I know how to update mysql database fields with user input and php using jquery. Separately, I know how to retrieve php query results using ajax. What I can't figure out is how to do both these things at the same time: <em>Use ajax to set user input as a parameter of a php query, then also pull the results of that query.</em></p> <p>I thought it was going to be simple once I figured these things out separately, but I just don't understand .ajax() well enough at all, and that's why I'm here.</p> <p>Here is my code:</p> <p><strong>User Input Page</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt; &lt;title&gt;Pull from query&lt;/title&gt; &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"&gt; &lt;style&gt; #topRow { margin-top:40px; text-align:center; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="container contentContainer" id="topContainer"&gt; &lt;div class="row"&gt; &lt;div class="col-md-6 col-md-offset-3" id="topRow"&gt; &lt;textarea class="form-control"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="col-md-6 col-md-offset-3" id="output" style="border:1px solid #000000;height:40px;margin-top:40px;text-align:center;"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; // "keyup" RUNS FUNCTION EVERY TIME USER USES KEYBOARD $("textarea").keyup(function() { $('#output').html("loading..."); var email = $('textarea').val(); $.post("5Query.php", {email:$('textarea').val()} ); // ACCESS QUERY RESULTS (HOPEFULLY!) $.ajax({ url: '5Query.php', dataType: 'json', success: function(data) { var result = data $('#output').html(result); } }); }) &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>PHP Query in separate file</strong></p> <pre><code>&lt;?php // SET DATABASE LINK AS A VARIABLE THAT CAN BE USED WHEN RUNNING QUERIES $link = mysqli_connect(...connection stuff...); if (mysqli_connect_error()) { die("Could not connect"); } // SELECT all fields FROM databasename $query = "SELECT * FROM users WHERE email='".mysqli_real_escape_string($link, $_POST['email'])."'"; // CREATE ARRAY CONTAINING ALL VALUES FOR ROW MATCHING QUERY CRITERIA $row = mysqli_fetch_array(mysqli_query($link, $query)); $name = $row['name']; $error = 'I could not find that user name'; //echo json_encode($row); if($row){ echo json_encode($name); } else { echo json_encode($error); } ?&gt; </code></pre> <p>As you can see, I tried using $.post() to set the query parameter, since that is the only way I know how, but it does return any results. When I hard-code a value into the php query that I know is in the mysql db table, rather than trying to post user input to the query, it correctly returns and displays the query result.</p> <p>I'm hoping that some of you smart people can spot something obvious that a novice like me wouldn't see... I definitely feel like everything should take place within .ajax(), but I just don't know how to do it, and it's weirdly difficult to find the answer anywhere.</p> <p>Please let me know how to improve my question, or where I might find an answer (although keep in mind that I'm a super-novice with ajax, so it's entirely possible that I may have seen an answer and just did not know what I was looking at).</p> </div>


<div class="post-text" itemprop="text"> <p>hi guys i ran in too small issue where i am creating like and dislike function so i created an while loop that created like and dislike for every tag but only the first button are responsive when using .onlick = function</p> <pre><code>if (mysql_num_rows($res) &gt; 0){ while ($row = mysql_fetch_assoc($res)) { //blah blah blah $categories .= "&lt;a href='view_category.php?cid=".$id."' class='cat_links'&gt;".$title." - &lt;font size='-1'&gt;".$description." &lt;/a&gt; &lt;/font&gt; &lt;div class='rating'&gt;&lt;input type='button' id='like1' value='like' /&gt;&lt;span id='temp_rating'&gt; ".$rating." &lt;/span&gt;&lt;input type='hidden' name='cid' id='cid' value='".$id."'/&gt;&lt;input type='button' value='dislike' /&gt;&lt;/div&gt;"; //blah blah blah } } </code></pre> <p>which does this <img src="https://i.stack.imgur.com/OEKC6.png" alt="enter image description here"></p> <p>and the my javascript code is </p> <pre><code>&lt;script src="ajax.js"&gt;&lt;/script&gt; &lt;script&gt; var submitEvent = document.getElementById("like1").onclick = function(){ likemsg(HTTP); }; &lt;/script&gt; </code></pre> <p>ajax.js</p> <pre><code>function likemsg(){ var temp_rating = 1; var cid = encodeURIComponent(document.getElementById('cid').value); var url = "category_like_parse.php?temp_rating="+temp_rating+"&amp;cid="+cid; alert(); HTTP.onreadystatechange=function() { if (HTTP.readyState==4 &amp;&amp; HTTP.status==200) { document.getElementById("temp_rating").innerHTML=HTTP.responseText; } } HTTP.open("POST", url ,true); HTTP.send(); } </code></pre> <p>and goes to category_like_parse.php saves +1 to database and echo it and it displays it but only for first like button the rest are unresponsive i got to this conclusion because i used alert(); which only worked for the first one and the rest dint. am i doing anything wrong.</p> </div>

PHP DOM解析多个页面使用while循环多次加载单页语句

<div class="post-text" itemprop="text"> <p>I m trying to parse a post related statement from a forum site using PHP dom parser. It works when we insert individual url's of the page, but when we try to apply a while loop logic it kinda prints only one page multiple times.. </p> <p>my code as goes::</p> <pre><code>&lt;?php set_time_limit(3600); $i = 1; $e = 839304-$i; while(true){ require_once('dom/simple_html_dom.php'); $html =file_get_html('http://www.usmleforum.com/files/forum/2017/1/'.$e.'.php'); foreach ($html-&gt;find("tr") as $row) { $element = $row-&gt;find('td.Text2',0); if ($element == null) { continue; } $textNode = array_filter($element-&gt;nodes, function ($n) { return $n-&gt;nodetype == 3; //Text node type, like in jQuery }); if (!empty($textNode)) { $text = current($textNode); echo $text."&lt;br&gt;"; } } $i++; } ?&gt; </code></pre> <p>as the result indicates, it only prints the statement from page 839303, but it prints it multiple times and still loads on.. so its clear that this code is skipping the $i++ line somehow and runs again...</p> <p>Any help is appreciated...</p> </div>

java web怎样实现商品分类显示

自己写了一个小的javaweb项目,用的jsp+servlet。 想实现商品的分类显示,但是不知道怎样从jsp页面传值给dao层,以及查询语句怎么写? 求大神帮助。 这是jsp页面: ``` <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%> <%@ page import="cn.edu.qust.bookcitys.entity.Items"%> <%@ page import="cn.edu.qust.bookcitys.dao.ItemsDao"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>展示</title> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/common.css" rel="stylesheet"> <link href="css/show.css" rel="stylesheet"> </head> <body> <header> <!-- logo --> <div class="index-header-top"> <img src="images/logo.png" class="logo"> </div> <!--导航栏--> <nav class="navbar navbar-default" role="navigation"> <div class="container-fluid"> <ul class="nav navbar-nav"> <li><a href="index.jsp">首页</a></li> <li class="active"><a href="show.jsp" target="_self">展示</a></li> <li><a href="cart.jsp" target="_self">购物车</a></li> <li><a href="login.jsp" target="_self">登录</a></li> </ul> </div> </nav> </header> <div class="details_container"> <div class="details_left"> <dl> <dt class="book"> <a href="show.jsp?sort=1">文学</a> </dt> <dd> <a href="#">作品集</a> </dd> <dd> <a href="#">名著</a> </dd> <dd> <a href="#">小说</a> </dd> </dl> <dl> <dt class="xbook"> <a href="show.jsp?sort=2">青春</a> </dt> <dd> <a href="#">青春</a> </dd> <dd> <a href="#">励志</a> </dd> <dd> <a href="#">校园</a> </dd> </dl> <dl> <dt class="book"> <a href="show.jsp?sort=3">生活</a> </dt> <dd> <a href="#">作品集</a> </dd> <dd> <a href="#">名著</a> </dd> <dd> <a href="#">小说</a> </dd> </dl> </div> <div class="details_right"> <div style="width: 1000px;"> <% ItemsDao itemsDao = new ItemsDao(); String sort = request.getParameter("sort"); ArrayList<Items> list = itemsDao.getAllItems(); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { Items item = list.get(i); request.setAttribute("item",item); %> <div style="width: 180px; height: 220px; float: left;"> <a href="details.jsp?id=${item.id }"><img style="float: left;" src="images/${item.picture }" width="170px" height="120px" border="1" /></a> <span style="float: left; margin: 5px 0px 0px 5px; color: blue">${item.name }</span> <span style="float: left; margin: 5px 0px 0px 5px; color: #000">作者:${item.author }&nbsp;&nbsp; 价格: ${item.price }¥ </span> </div> <% } } %> </div> </div> </div> <div class="details_bottom"> <footer> Copyright &copy; Made By 泥石流 </footer> </div> <!-- 如果要使用Bootstrap的js插件,必须先调入jQuery --> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script> <!-- 包括所有bootstrap的js插件或者可以根据需要使用的js插件调用 --> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> </body> </html> ``` ``` 这是dao层: package cn.edu.qust.bookcitys.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import cn.edu.qust.bookcitys.entity.Items; import cn.edu.qust.bookcitys.util.DBHelper; //商品的业务逻辑类 public class ItemsDao { //获得所有的商品信息 public ArrayList<Items> getAllItems(){ Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; ArrayList<Items> list = new ArrayList<Items>();//商品集合 try{ conn = DBHelper.getConnection(); // String sql = "select * from items where sort=?;";//sql语句 String sql = "select * from items ;";//sql语句 stmt = conn.prepareStatement(sql); // stmt.setInt(1, sort); rs = stmt.executeQuery(); while(rs.next()){ Items item = new Items(); item.setId(rs.getInt("id")); item.setName(rs.getString("name")); item.setAuthor(rs.getString("author")); item.setNumber(rs.getInt("number")); item.setPrice(rs.getInt("price")); item.setPicture(rs.getString("picture")); item.setSort(rs.getInt("sort")); list.add(item);//每次遍历把一个商品加入集合 } return list; } catch(Exception e){ e.printStackTrace(); return null; } finally{ //释放数据集对象 if(rs!=null){ try{ rs.close(); rs = null; } catch(Exception e){ e.printStackTrace(); } } //释放语句对象 if(stmt!=null){ try{ stmt.close(); stmt = null; } catch(Exception e){ e.printStackTrace(); } } } } //根据商品编号获得商品资料 public Items getItemsById(int id){ Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try{ conn = DBHelper.getConnection(); String sql = "select * from items where id=?;";//sql语句 stmt = conn.prepareStatement(sql); stmt.setInt(1, id); rs = stmt.executeQuery(); if(rs.next()){ Items item = new Items(); item.setId(rs.getInt("id")); item.setName(rs.getString("name")); item.setAuthor(rs.getString("author")); item.setNumber(rs.getInt("number")); item.setPrice(rs.getInt("price"));; item.setPicture(rs.getString("picture")); item.setSort(rs.getInt("sort")); return item; } else{ return null; } } catch(Exception e){ e.printStackTrace(); return null; } finally{ //释放数据集对象 if(rs!=null){ try{ rs.close(); rs = null; } catch(Exception e){ e.printStackTrace(); } } //释放语句对象 if(stmt!=null){ try{ stmt.close(); stmt = null; } catch(Exception e){ e.printStackTrace(); } } } } //获取最近浏览的前3条信息 public ArrayList<Items> getViewList(String list){ System.out.println("list:"+list); ArrayList<Items> itemlist = new ArrayList<Items>(); int iCount = 3; if(list!=null&&list.length()>0){ String[] arr = list.split("#"); System.out.println("arr.length="+arr.length); //如果商品记录大于等于3条 if(arr.length>=3){ for(int i=arr.length-1;i>=arr.length-iCount;i--){ itemlist.add(getItemsById(Integer.parseInt(arr[i]))); } } else{ for(int i = arr.length-1;i>=0;i--){ itemlist.add(getItemsById(Integer.parseInt(arr[i]))); } } return itemlist; } else{ return null; } } } ``` ``` 想把sort的值传到dao层并实现分类显示。


<div class="post-text" itemprop="text"> <p>That's my first post, hope there're no mistakes!</p> <p>I have an index.html page with divs and stuff and inside a div named "central" my code load different pages selected by button click functions. One of those "page into page" have a jQuery.post call to a php script that passes values to a JS function. Everything works fine but that's where my problem starts: how can I reload into "central" page the same page to reinitialize the php script? I tried another jQUery.load() call and a location.reload() function but both seems to not work (well actually they reload the whole page, not only the central div). </p> <p>I really appreciate any kind of suggestions, thanks =)</p> <p>that's my code, at the end of random.js there's an else statement, i think there should go the reload function</p> <p><strong>random.html</strong></p> <pre><code>&lt;body&gt; &lt;div class="row"&gt; &lt;div id="random" class="col-lg-12"&gt; &lt;div class="row"&gt; &lt;div&gt; &lt;h3 style="text-align:center;"&gt; Domanda n° &lt;span id="divNumero"&gt; &lt;/span&gt; &lt;/h3&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div&gt; &lt;span id="divDomanda" style="margin: 15px 0 15px 0;"&gt; &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div style="text-align:center;"&gt; &lt;h2&gt; &lt;span id="divRispostaCifrata"&gt; &lt;/span&gt; &lt;/h2&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="input-group"&gt; &lt;input type="text" class="form-control" id="rispostaInsert"&gt; &lt;span class="input-group-btn"&gt; &lt;button class="btn btn-primary" id="check" type="button"&gt; Check! &lt;/button&gt; &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="alert alert-default" id="helpRisposta" role="alert"&gt; La risposta è lunga &lt;span id="divLung"&gt;&lt;/span&gt; lettere &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div id="alertDiv" class="col-lg-12"&gt; &lt;div id="alert" class="col-lg-12"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;script&gt; jQuery(document).ready(initRandom()); &lt;/script&gt; </code></pre> <p></p> <p><strong>random.php</strong></p> <pre><code>&lt;?php include_once "function.php"; $array_DB=retrieveDB(); $controllo=true; do{ $i=mt_rand(0,(count($array_DB)-1)); if($array_DB[$i]['visibile']!=0) $controllo=false; } while($controllo); $indice=$array_DB[$i]['indice']; $domanda=$array_DB[$i]['domanda']; $risposta=$array_DB[$i]['risposta']; $rispostaCrypt=convert(); $lung=strlen($risposta); echo json_encode(array( 'indice'=&gt;$indice, 'domanda'=&gt;$domanda, 'risposta'=&gt;$risposta, 'rispostaCrypt'=&gt;$rispostaCrypt, 'lung'=&gt;$lung ) ); function convert(){ global $risposta; $temp=''; for($i=0;$i&lt;strlen($risposta);$i++) { if($risposta[$i]==(' ')) $temp.=' '; else if($risposta[$i]==('-')) $temp.='-'; else $temp.='#'; } return $temp; } ?&gt; </code></pre> <p><strong>random.js</strong></p> <pre><code>function initRandom(){ jQuery.post("pages/random.php",(function(sendback){ var indice=0; var domanda; var risposta; var lung; var rispostaCrypy; response=jQuery.parseJSON(sendback); indice=response.indice; domanda=response.domanda; risposta=response.risposta; lung=response.lung; rispostaCrypt=response.rispostaCrypt; jQuery("#divNumero").text(indice); jQuery("#divDomanda").text(domanda); jQuery("#divRispostaCifrata").text(rispostaCrypt); jQuery("#divLung").text(lung); controlla(indice,domanda,risposta) })) } function controlla(indice,domanda,risposta){ var temp=''; jQuery("#check").click(function(){ temp=''; if(!(jQuery("#rispostaInsert").val())){ alertDiv("Forse dovresti inserire una risposta"); } else{ var rispostaI=jQuery("#rispostaInsert").val() var lungRspInsert=rispostaI.length; var lungRsp=risposta.length; if((lungRspInsert)&lt;(lungRsp)){ var diff=lungRsp - lungRspInsert; alertDiv("Mancano "+diff+" lettere") } else if((lungRspInsert)&gt;(lungRsp)){ var diff=lungRspInsert - lungRsp; alertDiv("Ci sono "+diff+" lettere in più"); } else if((lungRspInsert)==(lungRsp)){ var contatore=0; for(var i=0;i&lt;lungRsp;i++) { if(rispostaI.charAt(i).toLowerCase()==risposta.charAt(i).toLowerCase()){ temp+=risposta.charAt(i) contatore++; } else{ temp+='#'; } } jQuery("#divRispostaCifrata").text("").text(temp); if(contatore!=lungRsp){ jQuery("#helpRisposta").text("").text("Indovinate "+contatore+" lettere su "+lungRsp) } else{ alertDiv("COMPLIMENTI! La risposta è corretta"); } } } }); } </code></pre> </div>


我在做jsp+servlet数据分页的时候,无法实现前后翻页, 下面是我的分层结构 jsp [code="java"] <%@page contentType="text/html;charset=gbk" %> <%@page language="java" import="java.util.*" %> <%@ include file="inc/cmnAuthenticate.jsp" %> <%@page language="java" import="ch05.*" %> <% Vector vMails = null; int totalPage=0; int curPage=0; int countPerPage=10; int pageNumber=1; Hashtable myValues = (Hashtable)session.getAttribute(CommonConst.VIEWID_INBOXLIST); if ( myValues != null ) { vMails = (Vector)myValues.get("mails"); if ( vMails == null ) { vMails = new Vector(); } if(myValues.get("totalPage")!=null){ totalPage=((Integer)myValues.get("totalPage")).intValue(); } if(myValues.get("curPage")!=null){ curPage=((Integer)myValues.get("curPage")).intValue(); } } %> <html> <head> <title>收件箱</title> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <script language="JAVASCRIPT" src="common\cmnScript.js"></script> <script language="JAVASCRIPT" src="inbox.js"></script> <link rel="stylesheet" type="text/css" href="common\cmnStyle.css" TITLE="common"></link> <script language="JAVASCRIPT"> <% if ( session.getAttribute("errMsg") != null ) { %> var sErrMsg = "<%=session.getAttribute("errMsg")%>"; <% } else { %> var sErrMsg = ""; <% } %> </script> </head> <%@ include file="inc/cmnPagePart1.jsp" %> <table border=0 cellpadding=0 cellspacing=0 width=650 align=center> <tr> <td height=15>&nbsp;</td> </tr> <tr> <td height=30>你当前共有 <font color=blue><%=vMails.size()%></font> 封邮件。</td> </tr> <tr> <td> <table border=1 bordercolor="#13A7FD" cellpadding=2 cellspacing=0 width=650 align=center> <tr> <td width=130> <b>发件人</b> </td> <td width=400> <b>主题</b> </td> <td width=120> <b>发信时间</b> </td> </tr> <% if ( vMails.size() > 0 ) { for ( int i=0; i<vMails.size(); i++ ) { if(i<countPerPage){ MailContent mailContent = (MailContent)vMails.get(i); String sFrom = mailContent.getSender(); String sSubject = mailContent.getSubject(); String sSendTime = mailContent.getSendTime(); String sReadFlg = mailContent.getReadFlg(); if ( sReadFlg.equals("0") ) { %> <tr> <td> <b><%=sFrom%></b> </td> <td> <b><a href="javascript:gotoMail('<%=i%>')"><%=sSubject%></a></b> </td> <td> <%=sSendTime%> </td> </tr> <% } else { %> <tr> <td> <%=sFrom%> </td> <td> <a href="javascript:gotoMail('<%=i%>')"><%=sSubject%></a> </td> <td> <%=sSendTime%> </td> </tr> <% } } } } else { %> <tr> <td colspan=3> 没有任何邮件! </td> </tr> <% } %> </table> </td> </tr> <tr> <td height=20>&nbsp;</td> </tr> </table> <form name="form_main" action="servlet/Inbox" method="post" > <input type="hidden" name="mailIndex" value=""> <div align="right"> 共 <font color=blue><%=totalPage%></font> 页,当前是第 <font color=blue><%=(totalPage==0?0:curPage+1)%></font> 页 &nbsp; <% if ( curPage > 0 ) { %> <a href="javascript: gotoPagePosition('0')">首页</a> &nbsp; <a href="javascript: gotoPagePosition('<%=curPage-1%>')">前一页</a> &nbsp; <% } else { %> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <% } if ( curPage < totalPage-1 ) { %> <a href="javascript: gotoPagePosition('<%=curPage+1%>')">后一页</a> &nbsp; <a href="javascript: gotoPagePosition('<%=totalPage-1%>')">末页</a> &nbsp; <% } else { %> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; <% } %> <input type="hidden" name="pageId" value="S0101"> <input type="hidden" name="gotoPageNo" value=""> </div> </form> <%@ include file="inc/cmnPagePart2.jsp" %> [/code] servlet [code="java"]/* * This product includes software developed by the * Apache Software Foundation (http://www.apache.org/). */ package ch05.controller; import java.io.*; import java.util.Hashtable; import javax.servlet.*; import javax.servlet.http.*; import ch05.*; import ch05.module.*; /** * 针对收件箱页面的Servlet * @author Administrator * @version 1.0 */ public class Inbox extends HttpServlet implements java.io.Serializable { /** * */ private static final long serialVersionUID = 1L; public void doGet ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { //设置提交表单的中文编码 request.setCharacterEncoding("GBK"); HttpSession mySession = request.getSession(true); //清空错误消息 mySession.setAttribute("errMsg",""); //是否非法进入本页面 if ( mySession.getAttribute("username") == null ) { response.sendRedirect("/ch05/login.jsp"); return; } //是否进入默认页面 if ( !request.getParameterNames().hasMoreElements() ) { //设置session中的页面值域 mySession.setAttribute(CommonConst.VIEWID_INBOXLIST, new Hashtable() ); //取得最新邮件 MInbox mInbox = new MInbox(); boolean bGetResult = mInbox.getNewestMail( mySession ); String sGotoPage = request.getParameter("gotoPageNo"); Hashtable myValues = (Hashtable)mySession.getAttribute(ch05.CommonConst.VIEWID_INBOXLIST); myValues.put( "curPage", new Integer(sGotoPage) ); mySession.setAttribute("curPage","inbox"); response.sendRedirect("/ch05/inbox.jsp"); return; } //得到用户输入信息 String sMailIndex = request.getParameter("mailIndex"); String sMailOption = request.getParameter("mailOption"); //如果用户是提交表单 if ( sMailIndex != null && sMailIndex.length() > 0 ) { //设置session中的详细页面值域 mySession.setAttribute(CommonConst.VIEWID_INBOXDETAIL, new Hashtable() ); //获得对应的邮件信息 MInbox mInbox = new MInbox(); boolean bGetResult = mInbox.getDetailMail( mySession, sMailIndex ); if ( bGetResult ) { response.sendRedirect("/ch05/inboxDetail.jsp"); } else { response.sendRedirect("/ch05/inbox.jsp"); } } //如果用户是从详细页面迁移过来的 else if ( sMailOption != null && sMailOption.length() > 0 ) { String sSender = request.getParameter("sender"); String sSendTime = request.getParameter("sendTime"); String sSubject = request.getParameter("subject"); String sContent = request.getParameter("content"); //删除邮件 if ( sMailOption.equals("delete") ) { MInbox mInbox = new MInbox(); boolean bDeleteResult = mInbox.deleteMail( mySession, sSender, sSendTime ); mInbox.getNewestMail( mySession ); response.sendRedirect("/ch05/inbox.jsp"); return; } //回复邮件 else if ( sMailOption.equals("reply") ) { //设置session中的写邮件页面值域 mySession.setAttribute(CommonConst.VIEWID_SENDBOXDETAIL, new Hashtable() ); MInbox mInbox = new MInbox(); boolean bReplyResult = mInbox.replyMail( mySession, sSender, sSubject, sContent ); mySession.setAttribute("curPage","composite"); response.sendRedirect("/ch05/composite.jsp"); return; } try { MInbox mInbox=new MInbox(); mInbox.gotoPage(request, response); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } //如果用户非法进入这个页面 else { response.sendRedirect("/ch05/login.jsp"); } } public void doPost ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { doGet( request, response ); } }[/code] 数据库处理 [code="java"]/* * This product includes software developed by the * Apache Software Foundation (http://www.apache.org/). */ package ch05.module; import java.sql.*; import java.util.*; import java.text.*; import javax.mail.*; import javax.mail.internet.*; import javax.servlet.http.*; import ch05.*; /** * 针对收件箱页面的后台处理类 * @author Administrator * @version 1.0 */ public class MInbox { public boolean getNewestMail ( HttpSession mySession ) { //设置用户信息用 Hashtable myValues = (Hashtable)mySession.getAttribute(CommonConst.VIEWID_INBOXLIST); String sHost = ""; String sUser = ""; String sPass = ""; //尝试查找用户邮箱设置 try { //载入SQLServer的JDBC驱动类 Class.forName(CommonConst.DB_DRIVER_CLASSNAME); //获得数据库连接 Connection conn = DriverManager.getConnection( CommonConst.DB_CONN_STRING ); Statement stmt = null; ResultSet rs = null; String sUsername = (String)mySession.getAttribute("username"); try { //设置数据库的rollback点 conn.setAutoCommit(false); //检查数据库中是否已经有该用户的邮箱设置 stmt = conn.createStatement(); //执行SQL语句 String sQuery = "select * from mail_setting where username='" + sUsername + "'"; rs = stmt.executeQuery( sQuery ); if (rs.next() ) { sHost = rs.getString(2); sUser = rs.getString(3); sPass = rs.getString(4); } else { mySession.setAttribute("errMsg","请首先进行邮箱设置!"); return false; } //尝试连接Pop3服务器 Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props, null); //获得收件箱 Store store = session.getStore("pop3"); store.connect( sHost, sUser, sPass); //获得Folder,并按照只读打开 Folder folder = store.getFolder( "INBOX" ); folder.open( Folder.READ_WRITE ); //获得所有邮件,并依次获取内容 Message messages[] = folder.getMessages(); //往数据库中登录 for ( int i=0; i<messages.length; i++ ) { //只要不是html格式,大概没有乱码问题。。。 String sFrom = MailContent.getFrom( messages[i].getFrom()[0].toString() ); String sTo = MailContent.getFrom( messages[i].getRecipients( Message.RecipientType.TO )[0].toString() ); String sDate = (new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")).format(messages[i].getSentDate()); String sSubject = messages[i].getSubject(); String sContent = ""; //如果纯文本邮件内容 if ( messages[i].getContent() instanceof String ) { sContent = (String) messages[i].getContent(); } //如果HTML格式邮件内容 else { sContent = ((MimeMultipart)messages[i].getContent()).getBodyPart(0).getContent().toString(); } //插入数据库 String sUpdateQuery = "insert into inbox values('" + sUsername + "', '" + sFrom + "', '" + sTo + "', '" + sDate + "', '" + sSubject + "', '" + sContent + "', '0') "; stmt.executeUpdate( sUpdateQuery ); } conn.commit(); conn.setAutoCommit(true); //删除服务器上的邮件 for ( int i=0; i<messages.length; i++ ) { messages[i].setFlag( Flags.Flag.DELETED, true ); } folder.close(true); store.close(); //重新获取数据库中的所有邮件,并表示在页面上 Vector vMails = new Vector(); sQuery = "select * from inbox where username='" + sUsername + "' order by send_time desc"; rs = stmt.executeQuery( sQuery ); while ( rs.next() ) { String sFrom = rs.getString(2); String sTo = rs.getString(3); String sDate = rs.getString(4); String sSubject = rs.getString(5); String sContent = rs.getString(6); String sReadFlg = rs.getString(7); MailContent mc = new MailContent(); mc.setSender(sFrom); mc.setReceiver(sTo); mc.setSendTime(sDate); mc.setSubject(sSubject); mc.setContent(sContent); mc.setReadFlg(sReadFlg); vMails.add( mc ); } myValues.put( "mails", vMails ); //计算总页数 int countPerPage=10; int totalMail=vMails.size(); int totalPage=0; if(totalMail%countPerPage==0){ totalPage=totalMail/countPerPage; } else{ totalPage=totalMail/countPerPage+1; } int curPage=0; myValues.put("curPage", new Integer(curPage)); myValues.put("totalPage", new Integer(totalPage)); } catch(Exception e) { e.printStackTrace(); mySession.setAttribute("errMsg","查找邮件时出现错误!"); return false; } finally { try { rs.close(); stmt.close(); }catch(Exception ex) { } } }catch(Exception ex) { ex.printStackTrace(); mySession.setAttribute("errMsg","查找邮件时出现错误!"); return false; } return true; } } }[/code] js [code="java"]window.onload = windowLoad; //--------------------------------- //页面载入时调用 function windowLoad() { cmnWindowLoad(); } //查看具体邮件 function gotoMail( index ) { form_main.mailIndex.value = index; form_main.submit(); } //前后翻页 function gotoPagePosition( gotoCount ) { form_main.pageId.value = "goto"; form_main.gotoPageNo.value = gotoCount; form_main.submit(); }[/code]


<div class="post-text" itemprop="text"> <p>In My code i am using a prepare statement using bind_result. In the following code i access all values on the carmake table. In that when I am going to access the admin name it gives me the error "Call to a member function bind_param() on a non-object". I have used this code previously. i used get_result at that time and it worked fine, but when I used bind_result it gives an error</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; &lt;/script&gt; &lt;?php session_start(); if(isset($_SESSION['username1'])) { include("../config/database.php"); if(isset($_GET["page"])) { $page = $_GET["page"]; $rows_per_page = 10; } else { $page=1; } $start_from = ($page * 10) -10; $limit = ($page * 10); $query=$conn-&gt;prepare("SELECT makeid,name,status,creation_date_and_time,created_by FROM carmake ORDER BY makeid desc LIMIT $start_from,10"); $query-&gt;execute(); $query-&gt;bind_result($makeid,$name,$status,$creation_date_and_time,$created_by); //$result=$query-&gt;get_result(); ?&gt; &lt;?php ?&gt; &lt;table width="100%" border="0" cellspacing="0" cellpadding="0" class="table"&gt; &lt;tr&gt; &lt;th width="6%" align="center" class="tbl_back"&gt; Id&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Name&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Created by&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Status&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Edit&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Delete&lt;/th&gt; &lt;/tr&gt; &lt;?php //$i = 0; while($query-&gt;fetch()) { /* Construct Data */ ?&gt; &lt;?php /*$serviceid=$data['servicetype']; $query2="select * FROM tblservicemaster where serviceid='$serviceid'"; $result2 = mysql_query($query2,$conn) or die(mysql_error()); $leadservice=mysql_fetch_array($result2);*/ ?&gt; &lt;tr&gt; &lt;td class="tbl_back1"&gt;&lt;?php echo $makeid ?&gt;&lt;/td&gt; &lt;td class="tbl_back1"&gt;&lt;?php echo $name ?&gt;&lt;/td&gt; &lt;td class="tbl_back1"&gt; &lt;?php $idd=$created_by; $query1=$conn-&gt;prepare("select name,adminid from admintable where adminid=?"); $query1-&gt;bind_param("i",$idd); $query1-&gt;execute(); $query1-&gt;bind_result($name,$adminid); //$query1-&gt;store_result(); $query1-&gt;fetch(); /* $query1="select name from admintable where id=".$data[4]; $result1=mysql_query($query1) or die(mysql_error()); $data1=mysql_fetch_array($result1);*/ echo $name; ?&gt; &lt;/td&gt; &lt;td class="tbl_back1"&gt;&lt;?php if($status==1){echo "Enabled";}if($status==0){echo "Disabled";} ?&gt;&lt;/td&gt; &lt;td class="celledit"&gt;&lt;a href="edit_carmakepages.php?id=&lt;?php echo $makeid; ?&gt;"&gt;&lt;center&gt;&lt;img src="images/editsign.jpg"/&gt;&lt;/center&gt; &lt;/a&gt;&lt;/td&gt; &lt;td class="celldelete"&gt;&lt;a href="javascript:del_topic(&lt;?php echo makeid; ?&gt;)"&gt;&lt;center&gt;&lt;img src="images/deletesign.jpg"/&gt;&lt;/center&gt; &lt;/a&gt;&lt;/td&gt; &lt;?php //$i++; ?&gt; &lt;/tr&gt; &lt;/tr&gt; &lt;?php } // end while /*else { ?&gt; &lt;table width="100%" border="0" cellspacing="0" cellpadding="0" class="table"&gt; &lt;tr&gt; &lt;th width="6%" align="center" class="tbl_back"&gt; Id&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Name&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Created by&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Status&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Edit&lt;/th&gt; &lt;th width="12%" align="center" class="tbl_back"&gt;Delete&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="15" align="center" style=" color:red" class="tbl_back12"&gt; No Record Found &lt;!--&lt;h4 class="aligncenter"&gt;No Record Found&lt;/h4&gt;--&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php }*/ ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;?php } ?&gt; &lt;/html&gt; </code></pre> </div>


<div class="post-text" itemprop="text"> <p>Due to one agent wanting his website url on the functionality that I worked on a month ago I ended up having to make some minor changes. I have two function PHP pages that run a very similar script but I had to make two based of two value sets. What they echo onto the page with AJAX is exactly the same and this is where it gets a little weird...</p> <p>The first script I did was successful but I needed to make a <code>if elseif else</code> statement so everyone agent didn't have a link that went no where. After fiddling around with this statement I was able to get just the one agent to have his website URL on there. Once I had that done I was under the impression that it would be smoothing sailing from there..it was not... </p> <p>I used the exact same statement for both of their scripts and only one works. The only thing that differs from them is what value it is receiving and that I use JavaScript + AJAX for the first one (Which works) and then decided to learn jQuery + AJAX to do the next one. Before this they all worked and it is the exact code for both besides the use of JavaScript/jQuery (which is the same language) and one uses <code>GET</code> while the other uses <code>POST</code></p> <p>I also get no errors or anything while the function is running. The agent's name is Sam Fiorentino that is the only one with a website url. <strong>I went into the console for the second search, the radio buttons, and it shows the company name outside of the anchor tag which is the root of the problem.</strong> Why would one display it correctly while the other doesn't?</p> <p><strong>First PHP</strong> (Works)</p> <pre><code>while ($stmt-&gt;fetch()) { // Gets results from the database echo "&lt;div class='agentcon'&gt;" . "&lt;span class='agentn'&gt;" . "&lt;strong&gt;". $First_Name . "&amp;nbsp;" . $Last_Name . "&amp;nbsp;" . $Suffix . "&lt;/strong&gt;" . "&lt;/span&gt;" . "&lt;a href=mailto:".$Email . "&gt;" . "&lt;span class='email'&gt;" . "Send an e-mail to" . "&amp;nbsp;" . $First_Name . "&lt;/span&gt;" . "&lt;/a&gt;" ."&lt;div class='floathr'&gt;&lt;/div&gt;"; if ($Company == NULL) { echo "&lt;p&gt;"; } elseif ($Website == NULL) { echo "&lt;p&gt;" . "&lt;strong&gt;" .$Company . "&lt;/strong&gt;" . "&lt;br&gt;"; } else { echo "&lt;p&gt;" . "&lt;strong&gt;" . "&lt;a target='blank' href=" .$Website . "&gt;" .$Company . "&lt;/a&gt;" . "&lt;/strong&gt;" . "&lt;br&gt;"; } </code></pre> <p><strong>Second PHP</strong> (Doesn't Work)</p> <pre><code>while ($stmt-&gt;fetch()) { // Gets results from the database echo "&lt;div class='agentcon'&gt;" . "&lt;span class='agentn'&gt;" . "&lt;strong&gt;".$First_Name . "&amp;nbsp;" .$Last_Name . "&amp;nbsp;" . $Suffix . "&lt;/strong&gt;" . "&lt;/span&gt;" . "&lt;a href=mailto:".$Email . "&gt;" . "&lt;span class='email'&gt;" . "Send an e-mail to" . "&amp;nbsp;" .$First_Name . "&lt;/span&gt;" . "&lt;/a&gt;" ."&lt;div class='floathr'&gt;&lt;/div&gt;"; if ($Company == NULL) { echo "&lt;p&gt;"; } elseif ($Website == NULL) { echo "&lt;p&gt;" . "&lt;strong&gt;" .$Company . "&lt;/strong&gt;" . "&lt;br&gt;"; } else { echo "&lt;p&gt;" . "&lt;strong&gt;" . "&lt;a target='blank' href=" .$Website . "&gt;" .$Company . "&lt;/a&gt;" . "&lt;/strong&gt;" . "&lt;br&gt;"; } </code></pre> <p><strong>SQL + Binded code</strong> (First/Working one)</p> <pre><code>$sql="SELECT First_Name, Last_Name, Suffix, Email, Company, WorkAddress1, WorkCity, WorkStateProvince, WorkZipCode, Work_Phone, Fax, Ancillary, SmallGroup, IndividualPlans, LongTermCare, Medicare, LargeGroup, TPASelfInsured, CertifiedForPPACA, Website FROM `roster` WHERE Last_Name = '".$q."' OR Company = '".$q."' OR WorkCity = '".$q."' OR WorkZipCode = '".$q."' ORDER BY Last_Name ASC"; if(!$stmt = $con-&gt;Prepare($sql)) { die; }else{ $stmt-&gt;execute(); $stmt-&gt;store_result(); $stmt-&gt;bind_result($First_Name, $Last_Name, $Suffix, $Email, $Company, $WorkAddress1, $WorkCity, $WorkStateProvince, $WorkZipCode, $Work_Phone, $Fax, $Ancillary, $SmallGroup, $IndividualPlans, $LongTermCare, $Medicare, $LargeGroup, $TPASelfInsured, $CertifiedForPPACA, $Website); $rows = $stmt-&gt;num_rows; </code></pre> <p><strong>SQL + Binded code</strong> (Not working one)</p> <pre><code>$poststr = $_POST['expertise']; //get our post data if(count($poststr) &gt; 1){ //count to make sure we have an array $expertise = implode(" AND ",$_POST['expertise']); //implode the array using AND as glue } else{ //otherwise if it is only one no need for implode $expertise = implode("",array($poststr)); } //here is our string for prepared statement $sql = "SELECT First_Name, Last_Name, Suffix, Email, Company, WorkAddress1, WorkCity, WorkStateProvince, WorkZipCode, Work_Phone, Fax, Ancillary, SmallGroup, IndividualPlans, LongTermCare, Medicare, LargeGroup, TPASelfInsured, CertifiedForPPACA, Website FROM roster WHERE ".$expertise." = 1 ORDER BY Last_Name ASC"; if(!$stmt = $con-&gt;Prepare($sql)) { die; }else{ $stmt-&gt;execute(); $stmt-&gt;store_result(); $stmt-&gt;bind_result($First_Name, $Last_Name, $Suffix, $Email, $Company, $WorkAddress1, $WorkCity, $WorkStateProvince, $WorkZipCode, $Work_Phone, $Fax, $Ancillary, $SmallGroup, $IndividualPlans, $LongTermCare, $Medicare, $LargeGroup, $TPASelfInsured, $CertifiedForPPACA, $Website); $rows = $stmt-&gt;num_rows; </code></pre> <p><strong>Javascript + AJAX</strong> (First one/Working one)</p> <pre><code>&lt;script&gt; function showUser(str) { if (str=="") { document.getElementById("bodyA").innerHTML=""; return; } 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 &amp;&amp; xmlhttp.status==200) { document.getElementById("bodyA").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","process.php?q="+str,true); xmlhttp.send(); } &lt;/script&gt; </code></pre> <p><strong>jQuery + AJAX</strong> (Second one/Not working)</p> <pre><code>$('input').on('click', function() { //Pulls data based on radial input var value = $(this).val(); $.ajax({ type: 'POST', datatype: "html", data: { expertise: value }, url: "expertise.php", success: function (data) { $('#bodyA').html(data); } }); }); </code></pre> <p>Any idea?</p> <p><a href="http://healthbenefitsohio.com/advance.php" rel="nofollow noreferrer">Live Site</a></p> </div>


<div class="post-text" itemprop="text"> <p>I'm creating a login and I've encountered an issue. I want an error message to appear if the user enters an incorrect username and/or password, specifically if both don't match what's in the DB the user will be prompted that they have entered an incorrect username/password.</p> <p>It seems as if my else statement is ignored whenever I run the code. My if statement works, I've tested it. But no matter what I echo in the else clause, it's not being accessed. I've tried restructuring the js the php is tied to, I've tried Stack Overflow solutions to similar issues to no avail. I've tested the code by stepping through it and when the if statement is true "sas" is echoed, when if is not true (else) "" is echoed. No error messages on the console. Perhaps there's something wrong with the logic of what I'm trying here.</p> <p>I'm using Malsup's jQuery form plugin to submit login form asynchronously. I've reduced some of non essential (there may be more I know) html and js but included the files for good measure.</p> <h1>PHP</h1> <pre><code> &lt;?php $host = "meh"; // Host name $username = "blah"; // Mysql username $password = "pft"; // Mysql password $db_name = "doh"; // Database name $tbl_name = "leh"; // Table name // Connect to server and select databse. $mysqli = new mysqli("$host", "$username", "$password", "$db_name"); if ($mysqli-&gt;connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli-&gt;connect_errno . ") " . $mysqli-&gt;connect_error; } // username and password sent from form $myusername = $_POST['myusername']; $mypassword = $_POST['mypassword']; // To protect MySQL injection $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysqli_real_escape_string($mysqli, $myusername); $mypassword = mysqli_real_escape_string($mysqli, $mypassword); $sql = "SELECT FirstName, Password FROM $tbl_name WHERE FirstName= ? AND Password= ? "; //prepare and bind paramters if ($stmt = $mysqli-&gt;prepare($sql)) { $stmt-&gt;bind_param("ss", $myusername, $mypassword); $stmt-&gt;execute(); $stmt-&gt;bind_result($returnedusername, $returnedpassword); //fetch $stmt results while ($stmt-&gt;fetch()) { if (isset($returnedusername) &amp;&amp; isset($returnedpassword) &amp;&amp; $returnedusername === $myusername &amp;&amp; $returnedpassword === $mypassword) { session_register("myusername"); session_register("mypassword"); //header("location:login_success.php"); echo "sas"; } else {//I DONT THIS PART IS BEING RUN...NOT SURE THOUGH IF LOOKING AT WRONG PART OF CODE echo $_POST['loginError'];//loginError found in html, will be error message } } //end while } //end if $stmt-&gt;close(); $mysqli-&gt;close(); ?&gt; </code></pre> <h2>JS</h2> <pre><code>$('document').ready(function() { var loginForm = $("#form1"); //Will load user's name into page heading (from local storage) function storeUsername() { window.alert("You made it in the function");//testing to see if code is run if (typeof(Storage) != "undefined") { // Store the user's first name as localStorage Object var inputUsername = document.getElementById("myusername"); localStorage.username = inputUsername.value; window.alert(localStorage.username); } } var options = { target: '#loginError', beforeSubmit: beforeSubmit, // pre-submit callback success: afterSuccess }; //Submit form via ajax // bind to the form's submit event $('#form1').submit(function() { // inside event callbacks 'this' is the DOM element so we first // wrap it in a jQuery object and then invoke ajaxSubmit $(this).ajaxSubmit(options); return false; }); //after succesful upload function afterSuccess() { var flag = $("#loginError"); var flagContents = flag.html(); if (flagContents == "sas") { window.location.href = "login_success.php"; //remove the imgPlaceHolder element } else { flag.fadeIn('slow');//error message will fade In } } function beforeSubmit() { //check whether browser fully supports all File API if (window.File &amp;&amp; window.FileReader &amp;&amp; window.FileList &amp;&amp; window.Blob) { storeUsername(); } else { //Output error to older unsupported browsers that doesn't support HTML5 File API alert("Please upgrade your browser, because your current browser lacks some new features we need!"); return false; } } }); </code></pre> <h2>HTML</h2> <pre><code>&lt;!DOCTYPE html&gt; &lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="../js/generalJS/modernizr.custom.js"&gt;&lt;/script&gt; &lt;script src="http://malsup.github.com/jquery.form.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table width="100" border="0" cellpadding="0" cellspacing="1"&gt; &lt;tr&gt; &lt;form name="form1" id="form1" method="post" action="checklogin.php"&gt; &lt;td&gt; &lt;table width="100%" border="0" cellpadding="3" cellspacing="1"&gt; &lt;tr&gt; &lt;td colspan="3"&gt;&lt;strong&gt; Login &lt;/strong&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Username: &lt;input name="myusername" type="text" id="myusername" required&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password: &lt;input name="mypassword" type="password" id="mypassword" required&gt; &lt;/td&gt; &lt;/tr&gt; &lt;input type="submit" id="mySubmit" name="Submit" value="Login"&gt;&lt;/input&gt; &lt;div id="loginError" name="loginError" style="display:none" value="**Username or password incorrect**"&gt;&lt;/div&gt; &lt;!--Php script will provide an error is login fails. It will get the outcome from checklogin, fetch reason from "password"--&gt; &lt;/table&gt; &lt;/td&gt; &lt;/form&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;script type="text/javascript"&gt; function downloadJSOnload() { var element1 = document.createElement("script"); element1.src = "../js/login.js"; document.body.appendChild(element1); } if (window.addEventListener) window.addEventListener("load", downloadJSOnload, false); else if (window.attachEvent) window.attachEvent("onload", downloadJSOnload); else window.onload = downloadJSOnload; &lt;/script&gt; &lt;/html&gt; </code></pre> </div>


<div class="post-text" itemprop="text"> <p>I have the code below and I just want to call the variables from my dropdown list to a Javascript function so I can manipulate those values.</p> <pre><code>function generateColorList(){ $selectHeaderStr = "&lt;select class='colorlist-items colorlist' name='title' id='Colorlist' width='250px'&gt;"; $selectHeaderEnd = "&lt;/select&gt;"; $qryTitle = getQueryTitle(); $connQuery = getRowByQuery($qryTitle); echo $selectHeaderStr; while($row = mysqli_fetch_array($connQuery)){ echo "&lt;option id='" . $row['title'] ."-" . $row['nid'] ."' class='colorlist-item Colorlist' data-times='" . $row['field_paint_times_value'] ."' data-efficiency='" . $row['field_paint_efficeincy__value'] ."' value='" . $row['title'] ."'&gt;". $row['title'] . "&lt;/option&gt;"; $p = $row[2];echo $p;echo "&lt;/br&gt;"; $q = $row[3];echo $q ;echo "&lt;/br&gt;"; } echo $selectHeaderEnd;echo '&lt;/br&gt;'; } echo generateColorList(); ?&gt; &lt;script src="jquery-3.1.0.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; &lt;script&gt; $('#Colorlist').change(function () { var selectedValue = (this).val(); alert(selectedValue)}; &lt;/script&gt; &lt;p id="times"&gt;&lt;/p&gt; &lt;p id="efficiency"&gt;&lt;/p&gt; &lt;p id="times"&gt;&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> </div>


<div class="post-text" itemprop="text"> <p>I am trying use an if statement and TWO .addClass background-color variables based on whether the column value for 'shift_times'= "SAT AM/SUN PM" or = "SAT PM/SUN AM". I am finding solutions for when a value is a number, but not text. </p> <pre><code> $query = "SELECT COUNT(confirmed) as cnt, position, shift_times FROM volConfirm WHERE confirmed='yes' GROUP BY shift_times, position order by position"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" . $row['position'] ." ". $row['shift_times'] ."= " . $row['cnt'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } </code></pre> </div>


<div class="post-text" itemprop="text"> <p>I am trying to create a number of div's that are responsive to a click event via js. If I use a universal id/class instead of a variable it works but upon clicking every div by the same name responds. Here is the code, much thanks ahead of time!</p> <pre><code> &lt;?php $con=mysqli_connect("host","user","password","database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = "SELECT * FROM items"; $result = mysqli_query($con,$sql); echo ""; while ($row = mysqli_fetch_array($result)) { echo " &lt;style&gt; #" . $row['ID'] ." { margin-left: 100px; margin-top: 0px; height:0px; width:750px; background: rgba(255, 255, 255, 0.3); color: rgba(11, 11, 11, 0.8); cursor:pointer; transition: height 0.5s; border-radius: 10px; overflow: hidden; box-shadow: 0px 2px 1px white inset, 0px -2px 8px white, 0px 2px 5px rgba(0, 0, 0, 0.1), 0px 8px 10px rgba(0, 0, 0, 0.1); -webkit-transition:box-shadow 1.0s; } #" . $row['ID'] .".csseffect { margin-left: 100px; margin-top: 5px; width: 750px; height: 125px; } #" . $row['item'] ." { margin-left: 75px; height: 50px; width: 800px; outline: none; font-family : inherit; font-size : 100%; background: rgba(255, 255, 255, 1.0); -webkit-box-sizing: border-box; /* For legacy WebKit based browsers */ -moz-box-sizing: border-box; /* For legacy (Firefox &lt;29) Gecko based browsers */ box-sizing: border-box; border-radius: 20px; padding: 5px; border: solid 1px #dcdcdc; box-shadow: 0px 2px 1px white inset, 0px -2px 8px white, 0px 2px 5px rgba(0, 0, 0, 0.1), 0px 8px 10px rgba(0, 0, 0, 0.1); -webkit-transition:box-shadow 0.5s; } &lt;/style&gt; &lt;div id=\"".$row['ID']."\" class=\"".$row['ID']."\"&gt;" . $row['item'] ."&lt;br&gt;&lt;/div&gt; &lt;div id=\"".$row['item']."\" class=\"".$row['item']."\"&gt;&lt;br&gt; &lt;div class=\"forms\"&gt; Blah blah blah &lt;/div&gt; &lt;p class=\"pos_fixed\"&gt;Some positioned text.&lt;/p&gt; &lt;/div&gt;&lt;br&gt; &lt;script&gt; $(document).ready(function(){ // when the page has loaded in browser... $('.".$row['ID']."').click(function(){ // bind a click event to the div element... $('.".$row['item']."').toggleClass('csseffect'); // that toggles the 'csseffect' class }); }); &lt;/script&gt; "; } ?&gt; </code></pre> </div>

itextsharp 导出pdf ,动态生成的图片问题

itextsharp 支持jquery吗 我采用下面的方法,去把当前的url转换为pdf。 ``` public void CreatPdf(string htmlurl, int lange) { Document doc = new Document(PageSize.A4, 9, 18, 36, 36);//左右上下 MemoryStream ms = new MemoryStream(); try { PdfWriter writer = PdfWriter.GetInstance(doc, ms); writer.CloseStream = false; doc.Open(); //url = HttpContext.Current.Server.MapPath("h1.html"); url = htmlurl; Thread thread = new Thread(new ThreadStart(setBitmap)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); while (thread.IsAlive) Thread.Sleep(100); bitmap.Save(HttpContext.Current.Server.MapPath("t.bmp")); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitmap, System.Drawing.Imaging.ImageFormat.Bmp); //img.ScalePercent(75);//560 630 if (lange == 1) { img.ScalePercent(50); } else { img.ScalePercent(48); } //img.ScaleAbsolute(w, h); doc.Add(img); } catch (Exception err) { throw new Exception(err.Message); } finally { doc.Close(); using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("out.pdf"), FileMode.Create)) { ms.Position = 0; byte[] bit = new byte[ms.Length]; ms.Read(bit, 0, (int)ms.Length); fs.Write(bit, 0, bit.Length); } ViewPdf(ms, "out"); } } ``` 在我本机和我们的一台windows server 2003 机子发布了下,导出没有问题。但,当发布到客户的虚拟主机上后,导出的pdf里面的图片就不对了。 这个图片是我jquery动态生成的。不知道怎么回事?希望高手指点一二。。 我本机上运行,导出的pdf: ![图片说明](https://img-ask.csdn.net/upload/201506/30/1435628727_528065.jpg) 客户虚拟主机上发布后,导出的pdf: ![图片说明](https://img-ask.csdn.net/upload/201506/30/1435628717_540045.jpg)


<div class="post-text" itemprop="text"> <p>So my "type1" select statement will select an issue category, and then based on that issue I want a dropdown of employees that deal with that issue in another drop down. Also how do I make all the hidden select statements occupy the same space? </p> <p>Here is my code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;IssueReport&lt;/title&gt; &lt;script src = "../../jquery.js"&gt;&lt;/script&gt; &lt;style&gt; body{ padding:0; margin:0; } #box { padding: 5px; color:black; margin: 0 auto; border-style: solid; border-color: #0000E6; border-width: 2px; background-color: #58C6EB; width: 162px; height: 687px; float: left; border-radius: 10px; } .word{ color: #0000E6; } .buttons{ background-color: #CCFFFF; border-radius: 5px; } &lt;/style&gt; &lt;script&gt; function showForm(){ var issue = document.getElementById("type1").value; if(issue == 'Program Glitch'){ document.getElementById("IT1").style.display = "block"; } $("#type1").onchange(function{ }); } $(document).ready(function(){ $("#sub").click(function(){ var user_issue = $("#issue").val(); var user_priority = $("#priority").val(); var user_type = $("#type1").val(); var user_author = $("#author").val(); $.post("BugReport.php",{issue:user_issue,priority:user_priority,type1:user_type,author:user_author},function(data){ $("#result").html(data); }); }); $("#sub").click(function(){ document.getElementById('issue').value=''; $('#type1').prop('selectedIndex', 0); $('#priority').prop('selectedIndex', 1); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="box"&gt; &lt;h3 class = "word" style = "margin:10px 30px 30px 30px;"&gt;Issue Report&lt;/h3&gt; &lt;div class = "word" style = "width: 100px; margin-left: auto; margin-right: auto"&gt;Type Of Issue:&lt;/div&gt; &lt;div style = " max-width: 150px; margin-left: auto; margin-right: auto; padding: 2px"&gt; &lt;form action="BugReport.html" method="post"&gt; &lt;select onchange = "showForm()" class = "buttons" name = "type1" id = "type1" style = 'max-width: 150px;'&gt; &lt;?php $servername = "localhost"; $username = "user"; $password = "pass"; $database = "database"; $con = mysqli_connect($servername,$username,$password,$database); if($con-&gt;connect_error){ die("Connection failed " . $con-&gt;connect_error); } $sql1 = "select issue_name, issue_description from Issue"; $result = mysqli_query($con,$sql1); while ($row = mysqli_fetch_array($result)) { $issue = $row['issue_name']; $des = $row['issue_description']; echo "&lt;option value = '$issue' title = '$des'&gt;$issue&lt;/option&gt;"; } ?&gt; &lt;/select&gt; &lt;/form&gt;&lt;/div&gt; &lt;form action="BugReport.html" method="post"&gt; &lt;div id = "Buyers1" style = "visibility:hidden;"&gt;&lt;select class = "buttons" name = "author" id = "Buyers" style = "margin: 0px 30px 0px 30px;"&gt; &lt;?php $sql = "select first, last from Employee where department_id = '1'"; $result = mysqli_query($con,$sql); while ($row = mysqli_fetch_array($result)) { $name = $row['first'] . ' ' . $row['last']; echo "&lt;option value = '$name'&gt;$name&lt;/option&gt;"; } ?&gt; &lt;/select&gt;&lt;/div&gt;&lt;/form&gt; &lt;div id = "Operations1" style = "visibility:hidden;"&gt;&lt;form action="BugReport.html" method="post"&gt; &lt;select class = "buttons" name = "author" id = "Operations" style = "margin: 0px 30px 0px 30px;"&gt; &lt;?php $sql = "select first, last from Employee where department_id = 2"; $result = mysqli_query($con,$sql); while ($row = mysqli_fetch_array($result)) { $name = $row['first'] . ' ' . $row['last']; echo "&lt;option value = '$name'&gt;$name&lt;/option&gt;"; } ?&gt; &lt;/select&gt;&lt;/form&gt;&lt;/div&gt; &lt;div id = "IT1" style = "display:none;"&gt;&lt;form action="BugReport.html" method="post"&gt; &lt;select onchange = "showForm()" class = "buttons" name = "author" id = "IT" style = "margin: 0px 30px 0px 30px;"&gt; &lt;?php $sql = "select first, last from Employee where department_id = 3"; $result = mysqli_query($con,$sql); while ($row = mysqli_fetch_array($result)) { $name = $row['first'] . ' ' . $row['last']; echo "&lt;option value = '$name'&gt;$name&lt;/option&gt;"; } ?&gt; &lt;/select&gt;&lt;/form&gt;&lt;/div&gt; &lt;div id = "CustomerService1" style = "visibility:hidden;"&gt;&lt;form action="BugReport.html" method="post"&gt; &lt;select class = "buttons" name = "author" id = "CustomerService" style = "margin: 0px 30px 0px 30px;"&gt; &lt;?php $sql = "select first, last from Employee where department_id = 4"; $result = mysqli_query($con,$sql); while ($row = mysqli_fetch_array($result)) { $name = $row['first'] . ' ' . $row['last']; echo "&lt;option value = '$name'&gt;$name&lt;/option&gt;"; } ?&gt; &lt;/select&gt;&lt;/form&gt;&lt;/div&gt; &lt;div id = "HR1" style = "visibility:hidden;"&gt;&lt;form action="BugReport.html" method="post"&gt; &lt;select class = "buttons" name = "author" id = "HR" style = "margin: 0px 30px 0px 30px;"&gt; &lt;?php $sql = "select first, last from Employee where department_id = 5"; $result = mysqli_query($con,$sql); while ($row = mysqli_fetch_array($result)) { $name = $row['first'] . ' ' . $row['last']; echo "&lt;option value = '$name'&gt;$name&lt;/option&gt;"; } ?&gt; &lt;/select&gt;&lt;/form&gt;&lt;/div&gt; &lt;div id = "Logistics1" style = "visibility:hidden;"&gt;&lt;form action="BugReport.html" method="post"&gt; &lt;select class = "buttons" name = "author" id = "Logistics" style = "margin: 0px 30px 0px 30px;"&gt; &lt;?php $sql = "select first, last from Employee where department_id = 6"; $result = mysqli_query($con,$sql); while ($row = mysqli_fetch_array($result)) { $name = $row['first'] . ' ' . $row['last']; echo "&lt;option value = '$name'&gt;$name&lt;/option&gt;"; } ?&gt; &lt;/select&gt;&lt;/form&gt;&lt;/div&gt; &lt;form action="BugDisplayAndReply.html" method="post"&gt; &lt;label&gt;&lt;/label&gt;&lt;br&gt; &lt;textarea style = "max-width: 156px; background-color: #F3F9FF; border-color: #0000E6;" cols="20" rows="34" name="issue" id = "issue" placeholder = "Enter Your Issue Here" "&gt;&lt;/textarea&gt;&lt;/form&gt;&lt;br&gt; &lt;div class = "word" style = "width: 50px; margin-left: auto; margin-right: auto"&gt;Priority:&lt;/div&gt; &lt;div style = "width: 70px; margin-left: auto; margin-right: auto; padding: 2px"&gt; &lt;form action="BugReport.html" method="post"&gt; &lt;select class = "buttons" name = "priority" id = "priority"&gt; &lt;option value = "Low"&gt;Low&lt;/option&gt; &lt;option value = "Regular" selected&gt;Regular&lt;/option&gt; &lt;option value = "High"&gt;High&lt;/option&gt; &lt;option value = "Urgent"&gt;Urgent&lt;/option&gt; &lt;/select&gt; &lt;/form&gt;&lt;/div&gt; &lt;div style = "width: 50px; margin-left: auto; margin-right: auto; padding: 2px"&gt; &lt;input class = "buttons" type ="submit" name = "sub" value = "Submit" id = "sub"&gt;&lt;/div&gt; &lt;div id="result"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> </div>

使用“Group by”语句在Datatable(服务器端)sql查询中搜索

<div class="post-text" itemprop="text"> <p>I am using <a href="http://datatables.net" rel="nofollow">datatable</a> jQuery plugin to render multiple joined tables from MySQL database. I am able to get the table rendered as desired. But the search is not functioning.</p> <p><strong>Observations:</strong><br> When I tried to run the query in my dbms using the "WHERE" clause, I found that the "WHERE" clause will only run if it is coming before the "GROUP BY" statement. So in my code it must also come before the "GROUP BY" statement, whereas the $sql is concatenating the "WHERE" clause after the "GROUP BY" statement. I don't know how to insert the WHERE clause (with search value) before the "GROUP BY" statement at runtime.</p> <p>I am providing the code for both of my files, (1) <strong>Index.php</strong> (the file with the table and the js which sends ajax request to response.php file). (2) <strong>response.php</strong> (the file containing the sql and search code which sends json encoded data to index.php). I am using the datatable version 1.10.10. I am following this <a href="http://phpflow.com/php/datatable-pagination-sorting-and-search-server-side-phpmysql-using-ajax/" rel="nofollow">tutorial</a></p> <p>Following is my code:</p> <p><strong>index.php</strong></p> <pre><code>&lt;head&gt; ... &lt;link href="css/bootstrap.css" rel="stylesheet" type="text/css"&gt; &lt;link href="css/customize.css" rel="stylesheet" type="text/css" media="screen"&gt; &lt;link rel="stylesheet" type="text/css" href="css/font-awesome.css"&gt; &lt;link rel="stylesheet" type="text/css" href="css/dataTables.bootstrap.css"&gt; &lt;link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css"&gt; ... &lt;/head&gt; &lt;body&gt; ... &lt;div class="row"&gt; &lt;div id="" class="col-lg-12 col-md-12 col-sm-12 col-xs-12"&gt; &lt;table id="employee_grid" class="display table-bordered"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class="col-lg-2 col-md-2 col-sm-2 col-xs-2"&gt;Student Name&lt;/th&gt; &lt;th class="col-lg-1 col-md-1 col-sm-1 col-xs-1"&gt;Gender&lt;/th&gt; &lt;th class="col-lg-1 col-md-1 col-sm-1 col-xs-1"&gt;City&lt;/th&gt; &lt;th class="col-lg-3 col-md-3 col-sm-3 col-xs-3"&gt;Course Description&lt;/th&gt; &lt;th class="col-lg-2 col-md-2 col-sm-2 col-xs-2"&gt;Subject&lt;/th&gt; &lt;th class="col-lg-1 col-md-1 col-sm-1 col-xs-1 text-right"&gt;Scholarship&lt;/th&gt; &lt;th class="col-lg-2 col-md-2 col-sm-2 col-xs-2"&gt;View Details&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; ... &lt;script&gt; $( document ).ready(function() { $('#employee_grid').DataTable({ "bProcessing": true, "serverSide": true, "autoWidth": true, "stateSave": true, "lengthMenu": [ 10, 25, 50, 100 ], "ajax":{ url :"response_b.php", // json datasource type: "post", // type of method,GET/POST/DELETE error: function(){ $("#employee_grid_processing").css("display","none"); } }, "columnDefs": [ { "targets": 6, "data": "StudentID", "render": function ( data, type, full, meta ) { return '&lt;a href="beneficiary.php?StudentID="'+data+'"&gt;'+data+'&lt;/a&gt;'; } }] }); }); &lt;/script&gt; &lt;/body&gt; </code></pre> <p><strong>response.php</strong></p> <pre><code>&lt;?php //include connection file include_once("connection.php"); // initilize all variable $params = $columns = $totalRecords = $data = array(); $params = $_REQUEST; //define index of column $columns = array( 0 =&gt; '`Full Name`', 1 =&gt; 'Gender', 2 =&gt; 'CityName', 3 =&gt; 'CourseDescriptionLong', 4 =&gt; '`Subject`', 5 =&gt; 'ScholarshipAwarded', 6 =&gt; 'StudentID' ); $where = $sqlTot = $sqlRec = ""; // check search value exist if( !empty($params['search']['value']) ) { $where .=" WHERE "; $where .=" (`Full Name` LIKE '".$params['search']['value']."%' "; $where .=" OR CityName LIKE '".$params['search']['value']."%' "; $where .=" OR CourseDescriptionLong LIKE '".$params['search']['value']."%' )"; } // getting total number records without any search $sql = " SELECT fullnames.`full name`, studentdetails.gender, lt_cities.cityname, lt_coursedescription.coursedescriptionlong, lt_coursesubject.`subject`, Sum(scholarshipdetails.scholarshipawarded), studentdetails.studentid, coursedetails.coursetype, lt_coursedescription.coursedescriptionshort, scholarshipdetails.scholarshipyear FROM studentdetails INNER JOIN scholarshipdetails ON studentdetails.studentid = scholarshipdetails.studentid INNER JOIN coursedetails ON studentdetails.studentid = coursedetails.studentid AND scholarshipdetails.scholarshipyear = coursedetails.scholarshipyear LEFT JOIN lt_coursedescription ON coursedetails.courseid = lt_coursedescription.courseid INNER JOIN tuitionfeedetails ON studentdetails.studentid = tuitionfeedetails.studentid AND scholarshipdetails.scholarshipyear = tuitionfeedetails.scholarshipyear INNER JOIN fullnames ON studentdetails.studentid = fullnames.studentid INNER JOIN lt_cities ON lt_cities.cityid = studentdetails.city LEFT JOIN lt_coursesubject ON lt_coursesubject.courseid = lt_coursedescription.courseid AND lt_coursesubject.subjectid = coursedetails.coursesubject GROUP BY studentdetails.studentid"; $sqlTot .= $sql; $sqlRec .= $sql; //concatenate search sql if value exist if(isset($where) &amp;&amp; $where != '') { $sqlTot .= $where; $sqlRec .= $where; } $sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." "; $queryTot = mysqli_query($conn, $sqlTot) or die("database error:". mysqli_error($conn)); $totalRecords = mysqli_num_rows($queryTot); $queryRecords = mysqli_query($conn, $sqlRec) or die("error to fetch employees data"); //iterate on results row and create new index array of data while( $row = mysqli_fetch_row($queryRecords) ) { $data[] = $row; } $json_data = array( "draw" =&gt; intval( $params['draw'] ), "recordsTotal" =&gt; intval( $totalRecords ), "recordsFiltered" =&gt; intval($totalRecords), "data" =&gt; $data // total data array ); echo json_encode($json_data); // send data as json format ?&gt; </code></pre> <p>I have researched for this type questions on the Stack Overflow, and there are many questions with answers, but none of them seems to work for me. </p> <p>Can any one guide me?</p> </div>









立方体线框模型透视投影 (计算机图形学实验)

计算机图形学实验 立方体线框模型透视投影 的可执行文件,亲测可运行,若需报告可以联系我,期待和各位交流

2019 AI开发者大会

2019 AI开发者大会




一 专题从基础的C语言核心到c++ 和stl完成基础强化; 二 再到数据结构,设计模式完成专业计算机技能强化; 三 通过跨平台网络编程,linux编程,qt界面编程,mfc编程,windows编程,c++与lua联合编程来完成应用强化 四 最后通过基于ffmpeg的音视频播放器,直播推流,屏幕录像,










Linux常用命令大全(非常全!!!) 最近都在和Linux打交道,感觉还不错。我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较短小但却功能强大。我将我了解到的命令列举一下,仅供大家参考: 系统信息 arch 显示机器的处理器架构 uname -m 显示机器的处理器架构 uname -r 显示正在使用的内核版本 d...




深度学习系列课程从深度学习基础知识点开始讲解一步步进入神经网络的世界再到卷积和递归神经网络,详解各大经典网络架构。实战部分选择当下最火爆深度学习框架PyTorch与Tensorflow/Keras,全程实战演示框架核心使用与建模方法。项目实战部分选择计算机视觉与自然语言处理领域经典项目,从零开始详解算法原理,debug模式逐行代码解读。适合准备就业和转行的同学们加入学习! 建议按照下列课程顺序来进行学习 (1)掌握深度学习必备经典网络架构 (2)深度框架实战方法 (3)计算机视觉与自然语言处理项目实战。(按照课程排列顺序即可)


fakeLocation13.5.1 虚拟定位 ios13.5.1的最新驱动下载,iPhone/iPad免越狱虚拟定位工具Location-cleaned驱动已更新









【数据结构与算法综合实验】欢乐连连看(C++ & MFC)案例

这是武汉理工大学计算机学院数据结构与算法综合实验课程的第三次项目:欢乐连连看(C++ & MFC)迭代开发代码。运行环境:VS2017。已经实现功能:开始游戏、消子、判断胜负、提示、重排、计时、帮助。


学生成绩管理系统,分三个模块:学生,教师和管理员。 管理员模块:负责学生、老师信息的增删改;发布课程信息的增删改,以便让学生选课;审核老师提交的学生成绩并且打印成绩存档;按照课号查询每个课号的学生成绩




在中国清朝,明黄色的衣服只有皇子才有资格穿,慢慢的黄色在中国就成了高贵的颜色。在人们的色彩印象中,黄色也表现为暂停。所以当你的网页设计采用黄色的时候,会让人们在你的网页前停留。 黄色,就像橙色和红色,黄色也是一个暖色。它有大自然、阳光、春天的涵义,而且通常被认为是一个快乐和有希望的色彩。黄色是所有色相中最能发光的颜色,给人轻快,透明,辉煌,充满希望的色彩印象。 黄色是一个高可见的色...





学生成绩管理系统(PHP + MYSQL)

做的是数据库课程设计,使用的php + MySQL,本来是黄金搭配也就没啥说的,推荐使用wamp服务器,里面有详细的使用说明,带有界面的啊!呵呵 不行的话,可以给我留言!







相关热词 c# 局部 截图 页面 c#实现简单的文件管理器 c# where c# 取文件夹路径 c# 对比 当天 c# fir 滤波器 c# 和站 队列 c# txt 去空格 c#移除其他类事件 c# 自动截屏