0

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!

2
  • 1
    Try jquery $.ajax() to make calls from js to php to solve the second problem. Commented May 16, 2015 at 11:14
  • PHP runs before JavaScript even becomes active, so this can not work in that order. Looks like you should go read up on some of the elementary basics of those techniques first. Commented May 16, 2015 at 13:22

2 Answers 2

1

use mysql fetch query

For example:

while ($row = mysql_fetch_assoc($query)){
                    $id = $row['id'];
}
Sign up to request clarification or add additional context in comments.

Comments

0

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",....)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.