websponge Posted November 3, 2011 Share Posted November 3, 2011 Hi, Im starting to write a simple (so I thought! ) project at work, I have no problems with the HTML, CSS or even the php mysql setup, but I am struggling with a simple piece of code! I have a list box, that populates from a table column using the following code: <?php function select(){ $query="SELECT appname FROM kpe_apps"; $result = mysql_query($query); echo '<select name="item" onchange="this.form.submit()">'; while($nt=mysql_fetch_array($result)){ echo '<option value="' . $nt['id'] . '">' . $nt['appname'] . '</option>'; } echo '</select>'; } ?> I then called the function on the page I needed. which works fine, now all I need is whatever is selected in the listbox other columns in the same table relating to the selected item are seen. I just cant seem to do it, loads of people are using jquery and other code, surely this can be done in php? any help would really be appreciated.. Many Thanks MOD EDIT: code tags fixed, linefeeds and indenting added. Quote Link to comment Share on other sites More sharing options...
freelance84 Posted November 3, 2011 Share Posted November 3, 2011 <?php function select(){ $query="SELECT appname FROM kpe_apps"; $result = mysql_query($query); echo '<select name="item" onchange="this.form.submit()">'; while($nt=mysql_fetch_array($result)) { echo "<option value=\"$nt['id']\">$nt['appname']</option>"; } echo '</select>'; }?> So what happens when you call that function? Quote Link to comment Share on other sites More sharing options...
websponge Posted November 3, 2011 Author Share Posted November 3, 2011 well its supposed to display all the fields, but it doesnt. I select an app from the dropdown list, for example "payroll" and I want the query to execute so it displays all the fileds for that record. the php for listing all the fields looks like this: $query="select * from ofcom where appname='Payroll'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo "<div id='recordholder'>"; echo "<div id='database-heading'>". $row['appname'] . "</div>"."<div id='description'>" . $row['description'] . "</div>"; echo "<div id='opcatholder'><div id='opcatheader'>Operational Cataogories</div><div id='opcat'><span class='op'>OP CAT 1 - </span>".$row['opcat1'] ."</div><div id='opcat'> <span class='op'>OP CAT 2 - </span>".$row['opcat2'] ."</div><div id='opcat'><span class='op'>OP CAT 3 - </span>".$row['opcat3'] ."</div></div>"; /*echo "<div id='routingheader'>Routing Information</div>";*/ echo"<div id='info'>".$row['info']."</div>"; echo "<div id='opcatholder'><div id='opcatheader'>Routing</div>".$row['routing']."</div>"; echo "</div>"; echo "<br clear='all' />"; } as you can see, ive manually set it too Payroll so that it works.. I want the listbox to execute the query when I select the app.. really hard to explain and ive been on this all day thanks for replying Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 3, 2011 Share Posted November 3, 2011 Please post your code within . . . tags, not PHP manual [m] . . . [/m] tags, and format it so it's readable with proper indenting if you want people to take the time to read it and try to help you. Quote Link to comment Share on other sites More sharing options...
websponge Posted November 3, 2011 Author Share Posted November 3, 2011 I tried to edit it! sorry.. stupid IE9! well its supposed to display all the fields, but it doesnt. I select an app from the dropdown list, for example "payroll" and I want the query to execute so it displays all the fileds for that record. the php for listing all the fields looks like this: $query="select * from ofcom where appname='Payroll'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo "<div id='recordholder'>"; echo "<div id='database-heading'>". $row['appname'] . "</div>"."<div id='description'>" . $row['description'] . "</div>"; echo "<div id='opcatholder'><div id='opcatheader'>Operational Cataogories</div><div id='opcat'><span class='op'>OP CAT 1 - </span>".$row['opcat1'] ."</div><div id='opcat'> <span class='op'>OP CAT 2 - </span>".$row['opcat2'] ."</div><div id='opcat'><span class='op'>OP CAT 3 - </span>".$row['opcat3'] ."</div></div>"; /*echo "<div id='routingheader'>Routing Information</div>";*/ echo"<div id='info'>".$row['info']."</div>"; echo "<div id='opcatholder'><div id='opcatheader'>Routing</div>".$row['routing']."</div>"; echo "</div>"; echo "<br clear='all' />"; } as you can see, ive manually set it too Payroll so that it works.. I want the listbox to execute the query when I select the app.. really hard to explain and ive been on this all day thanks for replying Quote Link to comment Share on other sites More sharing options...
freelance84 Posted November 3, 2011 Share Posted November 3, 2011 It is even easier to read when using the [ php][/ php] tags (minus the extra spaces). It is also better to put commands like select in caps too: SELECT * FROM ofcom WHERE appname='Payroll' ...... easier to bug find later as it is easier to read. $query="select * from ofcom where appname='Payroll'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo "<div id='recordholder'>"; echo "<div id='database-heading'>". $row['appname'] . "</div>"."<div id='description'>" . $row['description'] . "</div>"; echo "<div id='opcatholder'><div id='opcatheader'>Operational Cataogories</div><div id='opcat'><span class='op'>OP CAT 1 - </span>".$row['opcat1'] ."</div><div id='opcat'> <span class='op'>OP CAT 2 - </span>".$row['opcat2'] ."</div><div id='opcat'><span class='op'>OP CAT 3 - </span>".$row['opcat3'] ."</div></div>"; /*echo "<div id='routingheader'>Routing Information</div>";*/ echo"<div id='info'>".$row['info']."</div>"; echo "<div id='opcatholder'><div id='opcatheader'>Routing</div>".$row['routing']."</div>"; echo "</div>"; echo "<br clear='all' />"; } So what gets outputted with just this? $query="select * from ofcom where appname='Payroll'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { print_r($row); } Quote Link to comment Share on other sites More sharing options...
websponge Posted November 3, 2011 Author Share Posted November 3, 2011 ok, noted, will make sure I do this, but can anyone help please? Quote Link to comment Share on other sites More sharing options...
freelance84 Posted November 3, 2011 Share Posted November 3, 2011 now all I need is whatever is selected in the listbox other columns in the same table relating to the selected item are seen. So if your query works fine, then this sounds like an AJAX question. client action > info to server > info back to client from server displaying something new on clients screen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.