Sree Aka
Sree Aka

Reputation: 29

PHP, Javascript Help Required

I am new to this forum. I have been developing a interface and have got stuck with PHP and Javascript.

My Site has 3 Buttons

<button id="ProjectSource" class="testbutton" onClick="AddNewProject(this.id);">Project Source</button>
<button id="SelfCons" class="testbutton" onclick="AddNewProject(this.id)">Self Cons</button>
<button id="Currency" class="testbutton" onclick="AddNewProject(this.id)">Currency</button>

These buttons are sent to a Javascript function on the same page which will store the button ID in a variable, which is later used in another PHP.

Now I have an Select Box in the same page and I get the data from the database using PHP.

<select size="10" id="Database" onClick="ClearAdd()" >
    <?php
        while($row = mysql_fetch_assoc($get))
        {
    ?>
        <option value = "<?php echo($row['ProjectSource'])?>" >
            <?php echo($row['ProjectSource']) ?>
        </option>
            <?php 
        }               
    ?>
</select>

My First Problem is If you see I am currently using $row['ProjectSource']), But what I need is the ID of the buttons which corresponds to the field name in the database.

My Second Problem is The Select functions loads when the page loads, I want that to refresh when I click on any buttons.

Thanks in Advance for your help!

Upvotes: 0

Views: 73

Answers (2)

user4858416
user4858416

Reputation:

use mysql fetch query

For example:

while ($row = mysql_fetch_assoc($query)){
                    $id = $row['id'];
}

Upvotes: 1

dark knight
dark knight

Reputation: 85

For your second Problem you should implement ajax. Either using javascript or jquery.

Regarding first problem it is not clear What are the field names and how button Id is implemented? It would be better if you post some code Can you implement some kind of mapping of your fieldName to your buttonId using associative array? like array("fieldName1"=>"id1",....)

Upvotes: 0

Related Questions