Page 2 of 2

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 6:31 am
by turbolemon
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..

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 6:35 am
by Benjamin
turbolemon wrote:Are you trying to limit the input to a TinyMCE textarea? That could be your problem
Right, the example I tested was not using an js editor.

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 6:39 am
by simonmlewis
Doesn't work without it either:

Code: Select all

<textarea name='description' rows='6' cols='40'
             onKeyDown=\"limitText('textentry',80);\"
onKeyUp=\"limitText('textentry',80);\"></textarea>
And yes, am using a meta refresh, which works on many pages here. That isn't causing this problem though. Something bizarre is.

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 6:43 am
by Benjamin
simonmlewis wrote:That isn't causing this problem though. Something bizarre is.
Internet Explorer?

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 6:45 am
by simonmlewis
Haha... wouldn't put it past it - but no. Firefox is the same.

RESOLVED Re: How do you use Javascript within echoed PHP cod

Posted: Thu Aug 06, 2009 9:47 am
by simonmlewis
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.

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 12:45 pm
by simonmlewis

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'];
Hi all

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!!

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 1:02 pm
by jackpf
Where are you defining $row?

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 1:08 pm
by simonmlewis
It's defined in "AS numrows".... ie. it should use numrows for $row['numrows'];.

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.";}
[can't believe I forgot that]

Still doesn't show anything, and errors on

Code: Select all

$numadverts = $row['numrows'];

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 1:09 pm
by jackpf
If you're using mysql_fetch_object(), shouldn't it be $row->numrows?

Re: Count NumRows, how do you echo the answer?

Posted: Thu Aug 06, 2009 1:20 pm
by simonmlewis
Yes it should..... so it's now saying this:

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'>...........
And the error I get is:
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
Line 20 is "while ($row....".

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 2:56 pm
by jackpf
What does

Code: Select all

var_dump($result);
output?

Re: How do you use Javascript within echoed PHP code?

Posted: Thu Aug 06, 2009 3:37 pm
by simonmlewis
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.