473,699 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP, dropdown and aquiring the information

2 New Member
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(co de will follow)

What i want:
When an item in the dropdownmenu(dp m) 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($sq l) or die(mysql_error ());
while ($rec = mysql_fetch_ass oc($res)) $clowns[] = $rec;
//die('<pre>'.pri nt_r($clowns,tr ue));


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 1232
rpnew
188 New Member
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(co de will follow)

What i want:
When an item in the dropdownmenu(dp m) 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($sq l) or die(mysql_error ());
while ($rec = mysql_fetch_ass oc($res)) $clowns[] = $rec;
//die('<pre>'.pri nt_r($clowns,tr ue));


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
Trailer
2 New Member
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
8520
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 of doing it. I have a table with products, tblProducts, some of them are Active while others are Inactive. The form shows all the products purchased by a customer, both Active and Inactive in a ComboBox, cbProducts. My client wants to view all...
8
278
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 the data adapter ad selecting generate dataset.
7
2290
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 this is possiible. Any help would be greatly appreciated. Here's my code <h4>SEARCH</h4> <form action="<?php echo $_SERVER ?>" method = "post" target = "right">
0
8620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2351
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2012
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.