mysql Select with php and js

Codes here !

Moderators: egami, macek, gesf

Post Reply
oliver33
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Feb 18, 2018 5:17 am

Sun Feb 18, 2018 5:23 am

Hi,

I have this code:

<script>var pages=5;</script>

$sql = "SELECT * FROM ".$datatable." ORDER BY id ASC LIMIT 2, <script>document.write(pages);</script>";

var pages is javascript but does not return any database value.

If I put the value 5 instead of the script already works:

$sql = "SELECT * FROM ".$datatable." ORDER BY id ASC LIMIT 2, 5";

Another strange thing is if I do an echo, it prints the same thing:

echo "SELECT * FROM ".$datatable." ORDER BY id ASC LIMIT 2, <script>document.write(pages);</script>";

the result is:

SELECT * FROM binar ORDER BY id ASC LIMIT 2, 5

It's all correct! I do not see why it does not work !!

someone can help me?

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 753
Joined: Mon Feb 22, 2016 5:52 pm

Sun Feb 18, 2018 11:09 am

It's not correct, it doesn't work.

You can't mix and match JavaScript with PHP in the same script and expect them both to execute.

oliver33
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Feb 18, 2018 5:17 am

Sun Feb 18, 2018 2:00 pm

I tried this code to send a var to php but dont work. What I do wrong?

<script type = "text/javascript" language = "javascript">
$.post("ajax.php", {"cust_id": custid});
</script>

In php I have :

<?php
$_POST['cust_id'];
?>

chorn
php-forum Fan User
php-forum Fan User
Posts: 563
Joined: Fri Apr 01, 2016 2:18 am

Sun Feb 18, 2018 11:11 pm

that example is very incomplete. and what would "dont work" mean for anybody who can't read your mind? a simple post to any file would not generate any output, so how did you check the improper functioning? at least your PHP code is doing exactly nothing.

oliver33
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Feb 18, 2018 5:17 am

Mon Feb 19, 2018 1:41 am

chorn wrote:
Sun Feb 18, 2018 11:11 pm
that example is very incomplete. and what would "dont work" mean for anybody who can't read your mind? a simple post to any file would not generate any output, so how did you check the improper functioning? at least your PHP code is doing exactly nothing.
But that's exactly what I need to know.
What is missing for this code to work?
I am looking for a code that converts a var from js to php.
Nothing works and I do not know what's wrong.
That's why I came here.
Thank you if you can help me.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 753
Joined: Mon Feb 22, 2016 5:52 pm

Fri Feb 23, 2018 11:15 am

You need to process the data with PHP, from your post, I would suggest that you learn PHP from the ground up since whatever you want to do with that data is no where in your post.

sparxbpo12
New php-forum User
New php-forum User
Posts: 3
Joined: Mon Mar 05, 2018 12:47 am
Location: Ahmedabad
Contact:

Mon Mar 05, 2018 12:51 am

Try with different script.
An Experienced PHP Developer

Post Reply