How do you use Javascript within echoed PHP code?
Moderator: General Moderators
- turbolemon
- Forum Commoner
- Posts: 70
- Joined: Tue Jul 14, 2009 6:45 am
- Location: Preston, UK
Re: How do you use Javascript within echoed PHP code?
Meta refresh in the BODY element? Thats not a good idea, if it even works. Use php: header('Location: http://mysite.com/place/to/go/');. That issues a HTTP redirect header to the client, as long as you haven't sent any input to the browser already!
Are you trying to limit the input to a TinyMCE textarea? That could be your problem, I don't know whether that will actually work..
Are you trying to limit the input to a TinyMCE textarea? That could be your problem, I don't know whether that will actually work..
Re: How do you use Javascript within echoed PHP code?
Right, the example I tested was not using an js editor.turbolemon wrote:Are you trying to limit the input to a TinyMCE textarea? That could be your problem
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you use Javascript within echoed PHP code?
Doesn't work without it either:
And yes, am using a meta refresh, which works on many pages here. That isn't causing this problem though. Something bizarre is.
Code: Select all
<textarea name='description' rows='6' cols='40'
onKeyDown=\"limitText('textentry',80);\"
onKeyUp=\"limitText('textentry',80);\"></textarea>Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you use Javascript within echoed PHP code?
Internet Explorer?simonmlewis wrote:That isn't causing this problem though. Something bizarre is.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you use Javascript within echoed PHP code?
Haha... wouldn't put it past it - but no. Firefox is the same.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
RESOLVED Re: How do you use Javascript within echoed PHP cod
Hi all
It finally worked.
With a combination of the \" and the correct javascript which someone here provided, it does work. I even managed to get a secondary text box to do the same think, and countdown from that one countdown field!
Cheers.
It finally worked.
With a combination of the \" and the correct javascript which someone here provided, it does work. I even managed to get a secondary text box to do the same think, and countdown from that one countdown field!
Cheers.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you use Javascript within echoed PHP code?
Code: Select all
$result = mysql_query ("SELECT COUNT(id) AS numrows FROM dxadverts
WHERE userid = '$cookieid' GROUP BY userid") or die (mysql_error());
$numadverts = $row['numrows'];This'll be a silly problem, but I am getting a brick wall in my brain.
I am trying to see how many entries in a table for a particular ID number. And then display it.
This doesn't produce anything!
HELP!!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you use Javascript within echoed PHP code?
Where are you defining $row?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you use Javascript within echoed PHP code?
It's defined in "AS numrows".... ie. it should use numrows for $row['numrows'];.
It now has the fetch:
[can't believe I forgot that]
Still doesn't show anything, and errors on
It now has the fetch:
Code: Select all
$result = mysql_query ("SELECT userid, COUNT(*) AS numrows FROM dxadverts
WHERE userid = '$cookieid' GROUP BY userid") or die (mysql_error());
while ($row = mysql_fetch_object($result)){
$numadverts = $row['numrows'];
if ($numadverts == '3') { echo "You have reached your limit of adverts. Either edit one of your existing adverts, or delete one and create a new one.";}Still doesn't show anything, and errors on
Code: Select all
$numadverts = $row['numrows'];Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you use Javascript within echoed PHP code?
If you're using mysql_fetch_object(), shouldn't it be $row->numrows?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Count NumRows, how do you echo the answer?
Yes it should..... so it's now saying this:
And the error I get is:
Code: Select all
$result = mysql_query ("SELECT userid, COUNT(*) AS numrows FROM dxadverts
WHERE userid = '$cookieid' GROUP BY userid") or die (mysql_error());
while ($row = mysql_fetch_object($result))
{
$numadverts = $row->numrows;
if ($numadverts == '3') { echo "You have reached your limit of adverts at $numadverts adverts. Either edit one of your existing adverts, or delete one and create a new one.";}
elseif ($numadverts <= '2')
{
echo "$numadverts
<form method='post' name='myform' action='index.php?page=vehicleadded&menu=a_products' enctype='multipart/form-data'>...........Line 20 is "while ($row....".You have reached your limit of adverts at 3 adverts. Either edit one of your existing adverts, or delete one and create a new one.
Warning: mysql_fetch_object(): 9 is not a valid MySQL result resource in /usr/local/psa/home/vhosts/domain.co.uk/httpdocs/includes/advertadd.inc on line 20
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do you use Javascript within echoed PHP code?
What does
output?
Code: Select all
var_dump($result);-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do you use Javascript within echoed PHP code?
Well, when I remove the free_result code, there is no error, so I don't think I will bother changing anything else.
I know it's "bad code", but it works and there is no error.
I know it's "bad code", but it works and there is no error.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.