1

I don't know what is happening, but if I haven't any row in my php while to show jquery click will not work.

If I have one or more rows in WHILE jquery works. If I remove the while part of php, it works.

php:

$stmt = $mysqli_link->prepare("select id, user from posts limit 10");
$stmt->execute();
$stmt->bind_result($id, $user);

$i=0;
while($stmt->fetch()) { //if nothing to show JQUERY will not work
 $i=$i+1;
 show_p($id, $user);
}

$stmt->close();

jquery

$(document).ready(function(){
$(".changesize").click(function(e){
 alert("ok");
});
});

what is the problem with while and jquery? any ideas?

EDIT----------------------- my temporary solution:

$stmt->store_result();
$num = $stmt->num_rows; //NUM ROWS

if($num>0){ //if more than 0 rows. call while

    $i=0;
    while($stmt->fetch()) {
...
RGS
  • 4,062
  • 4
  • 31
  • 67
  • 4
    What does `show_p()` do? - But PHP and JS / jQuery are two different languages and php will be parsed first before the js/jQuery, so if something isn't working it isn't because of the loop, but because of the output. – Epodax Feb 17 '16 at 13:39
  • strange because if I remove `show_p()` the click still not working... but if I remove the while it is ok... @Epodax – RGS Feb 17 '16 at 13:52
  • @RickJoe : Please provide the code of show_p(id, user) function – AsgarAli Feb 17 '16 at 13:57
  • @AliKhanusiya it is a simple function just to echo the id and user: `function show_p($id,$user){ echo"$id $user"; }` – RGS Feb 17 '16 at 14:01
  • 2
    Where does the element with the class attribute of `changesize` appear within your html? – Cedric Ipkiss Feb 17 '16 at 14:09
  • @che-azeh it is before `

    `

    – RGS Feb 17 '16 at 14:12
  • 1
    What I'm trying to understand is why the event doesn't execute on `.changesize` and how that's related to your PHP while loop. Do those two elements have any relationship? – Cedric Ipkiss Feb 17 '16 at 14:17
  • @che-azeh nothing ;/ it is all here – RGS Feb 17 '16 at 14:20

1 Answers1

0

Maybe not the main cause of your problem, but here's a problem: you cannot use bind_results() with PHP Data Objects. There is no point in using it in the first place as PDO's functions handle all that hassle.

I'm concerned about the method because you pass the same variables to it which you pass to the show_p() function in the while loop; and your problem apparently comes from the show_p() function.

Undo that line with bind_results() and run your query again.

Cedric Ipkiss
  • 5,662
  • 2
  • 43
  • 72
  • oh, it is mysqli not PDO... what should I use instead of `bind_result`? – RGS Feb 17 '16 at 14:41
  • Just take off the line containing `bind_result`. Take a look at this thread: http://stackoverflow.com/questions/16908589/is-it-possible-to-use-store-result-and-bind-result-with-php-pdo – Cedric Ipkiss Feb 17 '16 at 14:44
  • I will try to take the line off and tell you what happens! thank you – RGS Feb 17 '16 at 14:47