Viewed   135 times

Hi I have this code that will pull the client name and address from the database. It echo's out the client name for each entry into a dropdown (<option value="<?php echo "$client" ?>"><?php echo "$client" ?></option>) which is done in a while loop. Then i have a Javascript that will change the innerHTML of a DIV named 'content' when you select a option in the dropdown - this is unique based on what is pulled from the database. - This is where I can't get it to work.. below is my code any help is much appreciated.

<div id="selectBox">
<div class="ui-widget">
    <label>Select a Client:</label>
    <select id="combobox" >
    <option value="">Select...</option>

include "db_conn.php";


function callDB(){      
$sql = 'SELECT * FROM clientlist';
   $query = mysql_query($sql) or die(mysql_error());
   while ($row = mysql_fetch_array($query))
       $ID= $row['id'];
       $client= $row["client"];
       $postal_add= $row["postal_add"];

<option value="<?php echo "$client" ?>"><?php echo "$client" ?></option>
}} ?>
<div id="content">

<script type="text/javascript">

// Script for changing Div
function change()
switch (document.getElementById("combobox").value)
  case "<?php echo $client ?>":
  document.getElementById("content").innerHTML = "<h2><?php echo $client ?></h2><b>Postal Address:</b> <?php echo $postal_add ?>"





By the time the Javascript is executed (Client), PHP already finished (Server). You will need to build the Javascript from PHP inside the While-Loop and send it to the browser later in the page:

// in while
$javascript .= "case $client:
document.getElementById('content').innerHTML = '<h2>$client</h2>
    <b>Postal Address:</b>$postal_add'

// later in page
switch (document.getElementById("combobox").value)
<?php echo $javascript; ?>
Sunday, October 23, 2022

Top tip for developing your own calendar: don't. Calendars are such a time sink, and non-trivial to write. If you need to ask for tips you'd be better off with an existing library component like you'll find in jQuery, dojo, etc..

This question has been asked many times here, links abound on other questions.

  • Best JavaScript Calendar control

  • What is the best calendar pop-up for populating a web form?

  • Creating A Javascript Calendar (Full, not pop up)

etc, etc...

Friday, September 2, 2022

I would request a video feed and make use of the author parameter. This should give you all the videos of a specific user.

In your example:

Tuesday, December 6, 2022

Here is the algorithm:

You add the new file input fields to your form. Each of this field MUST have a unique name. Then, on the server side, you loop through the $_FILES array looking how many files have been uploaded and handling them.

Saturday, September 17, 2022

You definitely want to redesign the database. Putting multiple values into a single column like that is a huge violation of the rules of normalization and will cause lots of headaches down the road. A single column should always hold a single piece of information.

You should also be using proper data types. Don't put times in a string, because you could end up with "foo" as a time and then what do you do?

Instead, what you probably want is:

CREATE TABLE Restaurants
    restaurant_id    INT            NOT NULL,
    restaurant_name  VARCHAR(40)    NOT NULL,
    CONSTRAINT PK_Restaurants PRIMARY KEY CLUSTERED (restaurant_id)
CREATE TABLE Restaurant_Hours
    restaurant_id    INT         NOT NULL,
    hours_id         INT         NOT NULL,
    day_of_week      SMALLINT    NOT NULL,
    start_time       TIME        NOT NULL,  -- Depends on your RDBMS and which date/time datatypes it supports
    end_time         TIME        NOT NULL,
    CONSTRAINT PK_Restaurant_Hours PRIMARY KEY CLUSTERED (restaurant_id, hours_id)

You can then easily check for restaurants open at a given time:

    Restaurants R
        SELECT *
            Restaurant_Hours RH
            RH.restaurant_id = R.restaurant_id AND
            RH.start_time <= @time AND
            RH.end_time >= @time AND
            RH.day_of_week = @day_of_week

If you have a time slot that spans midnight you would need to have two rows - one for the first day, and one for midnight - "x" for the next day. Also, remember to keep time zones in mind when using from a GUI.

Friday, September 16, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :