pass PHP to JS - string
Hello,
How can I pass string from PHP to JavaScrtipt?
string like this :
"1 - one
2 - two
3 - three"
4 - éáúő
5 - $%*&"
Simple string, with line breaks.
in sql database I have descriptions
this descriptions I need to use in JS
43 Replies
that's impossible to answer with more context
the possibilities are varied
what EXACTLY do you want to do?
there are things what php cannot do, so I have to do with js
so I have to pass datas to js from sql
you mean, like a
fetch
request?if it is the right word. Sorry I do not know the names, I can only use those
fetch request in php?
im trying to understand absolutely exactly why you have to put data in javascript, from php
if you can show code, that helps a lot too
my code is more than 400 lines
php cannot have event listener example
so js can do that
but why do you have to pass data from php to an event listener?
onclick example
I have name li tags from sql database, when I click one of them, those name datas have to show on the page
sounds like you're trying to re-implement the
<details>
tagno
no detail tag
I do not understand what you mean
so, you want a list, that when you click it shows extra content
that sounds a lot like the
<details>
tagno, that is details tag
sql database
have lot lot tables
1 table [ name and id]
2nd [different datas]
3rd....so on
in the datas there is details, like name and id, but that one have details with string like what I type at the first one
li tag have names, all names from sql datas
if I click on of the name , that specific name datas have to show it on the page
like the user list here on discord?
is there user list?
I do not know where is user list
I am not familiar with discord
on the right side
I am writing now on the right side
I am from pc
BabyCenter
Most popular baby names of 2024
Our list of the most popular baby names of the year is different from the others. We update it in real time, using data BabyCenter parents share with us as…
you click on the name and show details.
but mine not drop you other page
next to the names show the details
html grid
but that page opens the names on other pages
is that what you want?
"but mine not drop you other page
next to the names show the details
html grid"
what kind of information?
like VS Code
left side list
right side datas
when you click left side a file name, right side you can see the file
but mine is not files
only datas
what data?
are you joking?
what is data?
Name, Id, ...so on
I wrote datas in sql
like: Name, Id, Age, Job, Country, Hair, Details
yeah, im totally joking. i have nothing better to do -.-
Please stay civil, Epic is just trying to help. He's asking reasonable questions to try to determine what the best solution is
He ask me same question again and again. I wrote many times. Pleas look back. And I am not write anything wrong.
Please write to me what wrong did I wrote
"sql database
have lot lot tables
1 table [ name and id]
2nd [different datas]
3rd....so on
in the datas there is details"
17:19
You'll want to make a rest api endpoint and then use
fetch
in Javascript to call that api.
Either that, or embed the data in data attributes on the LIs on the initial page load.
It depends on how much data you have, and how often someone that loads your page will access one or more detail views of your data
That's why Epic kept asking what data, because you just gave a vague, incomplete description, which isn't enough to make the determination
So if you're asking a question about a topic that you don't know anything about, someone keeps asking you to clarify, and you don't know why they keep asking, try asking them politely what information they need rather than just going "are you joking". It's rude and only going to escalate things and make people less likely to want to help you"You'll want to make a rest api endpoint and then use fetch in Javascript to call that api." - no
... Okay?
I am not using api
and no fetch in JS
Ok then use the other suggestion
I do not understand
This is php
how to pass php string to js
no fetch, no api
you wrote api and fetch , not me
you just confusing me
I do not understand
you're asking how to pass data between two programming languages. That's a problem that is usually solved by using an API (Application Programming Interface).
this is how I pass simple string
no api, no fetch
you shouldn't be using
var
anymorebut this way cannot pass what I would like to
var is ok if you careful
if you want to use multiple line variables, you can use backticks instead of single quotes
not multiple lines variables
1 variable
will work if there are newlines in the variable
for anyone else reading this in the future though, that is a terrible practice especially if it's more than a couple of variables
no one read this
even no one will use it
They could, which is why I added that note
oh, I see. you mean here. I thought my page
Thank you so much for help. I will solve the problem to change description format. I think this is the only way to me.