473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP, dropdown and aquiring the information

Hello guys, this is my first post here. I tried searching for the answer, but I found out pretty quickly that I wouldnt find the perfect answer. I am pretty new to programming, but Im taking a class in c-programming and I am also trying to learn php and mysql on the side.

What I have done successfully is:
Get a server with mysql and php.
Getting mysql working, adding the database and the table.
Retrieving the information from the table and inserting it into a dropdownmenu(code will follow)

What i want:
When an item in the dropdownmenu(dpm) is selected, the user gets forwarded to a new page, where the result is displayed. If the user wishes to make more choices from the dpm , he can click on a button forwarding him back to the dpm. When he returns to the dpm the choices he has made previously has disappeared. When he makes a new choice, the new choice is listed on the resultpage with his previous choices, sorted by date.

My thoughts:
I have been thinking of a solution, and fact of the mather is I copied a working code from a guide, because I am pretty fresh to php. I think that the results from his choices in the dpm needs to be added to a new table in the database, and if i could get that to work, there wouldnt be any problems. :)

The code:

<?php
<form SRC="result.php">
/* this is something i have been trying, and it didnt work. It would solve my problem with retrieving the choice in the menu, but I still wouldnt know how to make the users previous choices disappear when he returns. */

print ("Please select your favorite clowns:");?><br><br><?
mysql_connect('xXxXx','xXxXxXx','veryxXxXxXx');
mysql_select_db('clowndatabase');


$sql = 'SELECT * FROM clowntable';
$res = mysql_query($sql) or die(mysql_error());
while ($rec = mysql_fetch_assoc($res)) $clowns[] = $rec;
//die('<pre>'.print_r($clowns,true));


echo '<SELECT name="dropdown">';
foreach ($clowns as $c)
{
if ($c['id'] == $_GET['id'])
echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['clowns']}</OPTION>\n";
else
echo "<OPTION value=\"{$c['id']}\">{$c['clowns']}</OPTION>\n";
}
echo '</SELECT>';
// </form>
?>


I hope I have made my post clean. And that my problem is easily understandable. Also, if anyone can tell me how to make a linechange in php, that would be great. Up to this point, I jump out of the php-tags and make a <br>. Its pretty ugly and not very good coding.
Feb 6 '08 #1
2 1219
rpnew
188 100+
Hello guys, this is my first post here. I tried searching for the answer, but I found out pretty quickly that I wouldnt find the perfect answer. I am pretty new to programming, but Im taking a class in c-programming and I am also trying to learn php and mysql on the side.

What I have done successfully is:
Get a server with mysql and php.
Getting mysql working, adding the database and the table.
Retrieving the information from the table and inserting it into a dropdownmenu(code will follow)

What i want:
When an item in the dropdownmenu(dpm) is selected, the user gets forwarded to a new page, where the result is displayed. If the user wishes to make more choices from the dpm , he can click on a button forwarding him back to the dpm. When he returns to the dpm the choices he has made previously has disappeared. When he makes a new choice, the new choice is listed on the resultpage with his previous choices, sorted by date.

My thoughts:
I have been thinking of a solution, and fact of the mather is I copied a working code from a guide, because I am pretty fresh to php. I think that the results from his choices in the dpm needs to be added to a new table in the database, and if i could get that to work, there wouldnt be any problems. :)

The code:

<?php
<form SRC="result.php">
/* this is something i have been trying, and it didnt work. It would solve my problem with retrieving the choice in the menu, but I still wouldnt know how to make the users previous choices disappear when he returns. */

print ("Please select your favorite clowns:");?><br><br><?
mysql_connect('xXxXx','xXxXxXx','veryxXxXxXx');
mysql_select_db('clowndatabase');


$sql = 'SELECT * FROM clowntable';
$res = mysql_query($sql) or die(mysql_error());
while ($rec = mysql_fetch_assoc($res)) $clowns[] = $rec;
//die('<pre>'.print_r($clowns,true));


echo '<SELECT name="dropdown">';
foreach ($clowns as $c)
{
if ($c['id'] == $_GET['id'])
echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['clowns']}</OPTION>\n";
else
echo "<OPTION value=\"{$c['id']}\">{$c['clowns']}</OPTION>\n";
}
echo '</SELECT>';
// </form>
?>


I hope I have made my post clean. And that my problem is easily understandable. Also, if anyone can tell me how to make a linechange in php, that would be great. Up to this point, I jump out of the php-tags and make a <br>. Its pretty ugly and not very good coding.

Hi,
If you want that when user returns to the previous page his/her last choice should be disappear then change the following code snap..
[PHP]
foreach ($clowns as $c)
{
if ($c['id'] == $_GET['id'])
echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['clowns']}</OPTION>\n";
else
echo "<OPTION value=\"{$c['id']}\">{$c['clowns']}</OPTION>\n";
}
[/PHP]
to below given
[PHP]
foreach ($clowns as $c)
{
echo "<OPTION value=\"{$c['id']}\">{$c['clowns']}</OPTION>\n";
}
[/PHP]
And may also have to make a little bit change on the page where you are showing users choices... so post part of that page's code as well. (from where you are coming back to this page... that link or button whatever you've provided)
That should solve your problem.

Now regarding the second thing where you want that the next page should show all users choices.. then well according to me it will be easy if you store them in a table so that you can keep track of the all previous choices of that user....

Regards,
RP
Feb 7 '08 #2
Thank you for answering :)

But this is actually the only page i have up until now. The code on this page doesnt send any values, so I didnt start making a new page to catch the values.
Feb 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
8
by: Kris Rockwell | last post by:
Hello, I have done the following to bind data to a DropDown box: 1. Drag SQLServer table onto web form to create data connection and data adapter. 2. Generate dataset by right-clicking on...
7
by: microsoftboy | last post by:
Hi, Using the following selection criteria, I am able to list the data from mysql db, but I would like to provide the following options for users: Select All Data, Select None. I am not sure if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.