#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2001
    Location
    England
    Posts
    673
    Rep Power
    14

    Odd PHP/JavaScript/Netscape problem


    The following code displays records pulled from the database in a drop down menu.

    The Javascript simply displays different colour form buttons depending on whether it's Internet Explorer or Netscape you are viewing the page in.

    It works fine in I.E but nothing appears in the drop down box in Netscape. It is simply empty.

    Any ideas?

    Many thanks

    James

    The code is:

    <?PHP

    $db = mysql_connect("localhost", "root");

    mysql_select_db("pyramid",$db);

    $result = mysql_query("SELECT DISTINCT county FROM table where location='OP' or location='VOP' order by county",$db);

    ?>

    <SCRIPT LANGUAGE="JavaScript">

    if (navigator.appName == "Microsoft Internet Explorer") {
    document.write('<?php

    echo "<select name=\"county\" id=\"county\">";

    while ($myrow = mysql_fetch_row($result)) {

    echo "<option class=\"opt2\">", $myrow[0], "</option>";

    }
    ?>');

    } else document.write('<?php

    echo "<select name=\"county\" id=\"county\">";

    while ($myrow = mysql_fetch_row($result)) {

    echo "<option>", $myrow[0], "</option>";

    }
    ?>');

    </script>
    </select>
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    This is a javascript question not a PHP issue, you need to show the output of your generated javascript in the relevant forum (+ mentioning which version of Netscape may help)
    resistance is no longer futile :: 423
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2001
    Location
    England
    Posts
    673
    Rep Power
    14
    I'm not sure that it is necessarily a JavaScript issue. I'm using Netscape 4.x.

    The 'output of my generated javascript ' is as follows:

    <SELECT name="county" id="county">
    </SELECT>

    I hope you find it useful.

    Regards,

    James
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    on the second pass through result use this to reset the $result pointer back to the start, (its like reset() for an array but for the resourse identifier)

    PHP Code:
    mysql_data_seek($result,0);
    while (
    $myrow mysql_fetch_row($result)) {//etc 

    so yep it was a PHP issue , what I meant was that its impossible for javascript or the browser to affect the output of PHP, its the PHP thats wrong not the JS or the browser
    resistance is no longer futile :: 423

IMN logo majestic logo threadwatch logo seochat tools logo