I have two slight problems I simply cant find an answer to anywhere, the first, only small.
I have my database printing out items from a database into a select box, this is giving me blank options even though there are none in the database, I remember having this problem before but cant remember how to get around it?
Secondly on the same form I would like another drop down field to change according to what is selected e.g. customer selects product, amount availible is stored in the database so I would like a qty drop down that will display from 1 upto the amount availible. The Webpage -
// connect to the server
-
@mysql_connect($host, $username, $password) or die ("Server is Down");
-
@mysql_select_db($database) or die ("Database Error");
-
$query="SELECT * FROM itemtbl";
-
$result=mysql_query($query);
-
-
$num =mysql_numrows($result);
-
-
mysql_close();
-
-
?>
-
<table>
-
<tr><td>ID</td><td>Session</td><td>Item</td><td>Date</td><td>Qty</td></tr>
-
<tr><td><form id="orderform" name="orderform" method="post" action=" "><input name="id" type="text" id="id" size="10"></td><td><input name="name" type="text" id="name" size="20"></td><td><select name="product" size="1">
-
<?php
-
$i=0;
-
while ($i < $num){
-
$id=mysql_result($result,$i,"itemid");
-
$info=mysql_result($result,$i,"info");
-
$price=mysql_result($result,$i,"price");
-
$qty=mysql_result($result,$i,"itemqty");
-
-
echo "<option value=$id> $info<option>";
-
-
$i++;
-
}
-
?>
-
</select>
-
-
</td><td><input name="date" type="text" id="date" size="20"></td><td><select name="qty" size="1">
-
<option value="1">1</option>
-
<option value="2">2</option>
-
<option value="3">3</option>
-
<option value="4">4</option>
-
<option value="5">5</option>
-
</select>
-
-
</td></tr>
-
<tr><td></td><td></td><td><input type="submit" name="submit" value="Submit"></td><td></td><td><input type="reset" name="submit2" value="Reset"></form></td></tr>
-
-
</table>
-
17 3474
I have two slight problems I simply cant find an answer to anywhere, the first, only small.
I have my database printing out items from a database into a select box, this is giving me blank options even though there are none in the database, I remember having this problem before but cant remember how to get around it?
Secondly on the same form I would like another drop down field to change according to what is selected e.g. customer selects product, amount availible is stored in the database so I would like a qty drop down that will display from 1 upto the amount availible. The Webpage -
// connect to the server
-
@mysql_connect($host, $username, $password) or die ("Server is Down");
-
@mysql_select_db($database) or die ("Database Error");
-
$query="SELECT * FROM itemtbl";
-
$result=mysql_query($query);
-
-
$num =mysql_numrows($result);
-
-
mysql_close();
-
-
?>
-
<table>
-
<tr><td>ID</td><td>Session</td><td>Item</td><td>Date</td><td>Qty</td></tr>
-
<tr><td><form id="orderform" name="orderform" method="post" action=" "><input name="id" type="text" id="id" size="10"></td><td><input name="name" type="text" id="name" size="20"></td><td><select name="product" size="1">
-
<?php
-
$i=0;
-
while ($i < $num){
-
$id=mysql_result($result,$i,"itemid");
-
$info=mysql_result($result,$i,"info");
-
$price=mysql_result($result,$i,"price");
-
$qty=mysql_result($result,$i,"itemqty");
-
-
echo "<option value=$id> $info<option>";
-
-
$i++;
-
}
-
?>
-
</select>
-
-
</td><td><input name="date" type="text" id="date" size="20"></td><td><select name="qty" size="1">
-
<option value="1">1</option>
-
<option value="2">2</option>
-
<option value="3">3</option>
-
<option value="4">4</option>
-
<option value="5">5</option>
-
</select>
-
-
</td></tr>
-
<tr><td></td><td></td><td><input type="submit" name="submit" value="Submit"></td><td></td><td><input type="reset" name="submit2" value="Reset"></form></td></tr>
-
-
</table>
-
[PHP]
$num =mysql_numrows($result);
[/PHP]
Are you sure that you are using this line... cause according to my knowledge this function is like this...
[PHP]
$num =mysql_num_rows($result);
[/PHP]
Regards,
RP
Thats exactly what I'm using and seems to work fine, well apart from the things listed above..
Hi all,
mysql_numrows() is a deprecated alias of mysql_num_rows().
You should ideally move towards using mysql_num_rows().
Now I am going to take a look at your problem..
Regards Purple
Hi,
not sure if it is a typo but:
[PHP]while ($i < $num) {
$id=mysql_result($result,$i,"itemid");
$info=mysql_result($result,$i,"info");
$price=mysql_result($result,$i,"price");
$qty=mysql_result($result,$i,"itemqty");
echo "<option value=$id> $info<option>";
$i++;
}[/PHP]
should be more like:
[PHP]while ($i < $num) {
$id=mysql_result($result,$i,"itemid");
$info=mysql_result($result,$i,"info");
$price=mysql_result($result,$i,"price");
$qty=mysql_result($result,$i,"itemqty");
echo "<option value=".$id."> ".$info."</option>";
$i++;
}[/PHP]
note the "/" terminator for the option element
Not sure what impact that will have on the code, do the change or confirm typo and post back..
also - as a matter of style, note the changes to the variables on the echo statement - doing it this way allows your IDE to identify them as variables and not just stuff to be echoed to the screen..
Regards Purple
Regarding your second question, you have some choices.
You could do it by building the page using the onchange event to refresh the page and load the second dropdown - this approach will make the page judder on a slow internet connection but can be implemented using 99% PHP.
You could use Ajax which is probably the right way to do it but assumes all of the people using the website have java enabled on their client browsers.
Have you javascript knowledge ?
Regards Purple
note the "/" terminator for the option element
Not sure what impact that will have on the code, do the change or confirm typo and post back..
also - as a matter of style, note the changes to the variables on the echo statement - doing it this way allows your IDE to identify them as variables and not just stuff to be echoed to the screen..
Regards Purple
I knew it would be something stupid like that, yes thats fixed my first problem, well noticed, cheers for that
Regarding your second question, you have some choices.
You could do it by building the page using the onchange event to refresh the page and load the second dropdown - this approach will make the page judder on a slow internet connection but can be implemented using 99% PHP.
You could use Ajax which is probably the right way to do it but assumes all of the people using the website have java enabled on their client browsers.
Have you javascript knowledge ?
Regards Purple
Not really, done bits an bobs of Java, thats about it, never really got into it
Hi,
well I suggest you go the first route,
setup an onchange event on the select to process the form when a selection has been made - within the script test the post values of the first select and if it has been set, make your second select from the DB and build the second dropdown..
Hope that makes sense..
Regards Purple
Cheers for your help, I'll look it up now and give it in a bash, let you know how it turns out, cheers guys
having little look with locating a sufficent example on the internet, just wondering about the syntax, something like - <select name="product" size="1" onChange="$product=$_POST['product'];">
-
echo "<option value=$id> $info</option>";
how would I need to modify that to get it working
having little look with locating a sufficent example on the internet, just wondering about the syntax, something like
[PHP]<select name="product" size="1" onChange="$product=$_POST['product'];">
echo "<option value=$id> $info</option>";[/PHP]
how would I need to modify that to get it working
Hi ezb,
the onChange event is client side, you need to be in JavaScript
[PHP]<select name="product" size="1" onChange="javascript :refresh_win();">
<?php
echo "<option value=$id> $info</option>";
?>[/PHP]
with a javascript function called refresh_win() which presses a submit button on the screen - you will need the form to post to itself to make this work..
Regards Purple
oh and, please use code tags when posting code, no matter how small..
MODERATOR
I can't change your post cause I don't moderate this forum, I am sure one of the php mods will get on this...
Hi, - function refresh_win()
-
{
-
document.formname.submit.click();
-
}
formname needs to be changed to the name of your form
assumes you have a button called submit - change to name of button if not.
Regards Purple
Hi ezb,
the onChange event is client side, you need to be in JavaScript
[PHP]<select name="product" size="1" onChange="javascript:refresh_win();">
<?php
echo "<option value=$id> $info</option>";
?>[/PHP]
with a javascript function called refresh_win() which presses a submit button on the screen - you will need the form to post to itself to make this work..
Regards Purple
Sorry about that, was not intending on adding proper code so simply didnt bother with code tags, edited it accordingly.
The touble with this being I would like to submit the form into a database once I have the selected information, how can I do this if I'm porting the form to its self in order to this variable?
Hi ezb,
you do this by building code block which run based on which post values are set
so :
[PHP]<?php
if (isset($_POST['first_select']) and $_POST['first_select'] <> "default value" and !isset($_POST['second_select']) ) {
//
do the code to build the second select
//
}
elseif(isset($_POST['first_select']) and $_POST['first_select'] <> "default value" and isset($_POST['second_select']) and $_POST['second_select'] <> "default value" ) {
//
do the code to save the data to the database
//
}
?>[/PHP]
does that help ?
Purple
sorry about this but the above doesnt make much snece to me.
I've got the java script working but as I though, when I select an option it basicly refreshes the form, taking all the items back to the default, was wondering if theres a way to get the same result but keeping what the user has selected in the form, purhaps taking the selected into a variable and using them as default when the form submits somehow?
Hi,
as with all of these things, there are a number of ways to achieve this..
simplest is prob using sessions so :
[PHP]<?php
session_start(); // this needs to be executed before anything is sent to the browser - including any white space
if (!isset$_SESSION['form_vars']) session_register('form_vars');
if(!empty($_POST['variable']) $_SESSION['form_vars']['variable'] = $_POST['variable']; // this needs to be done for all vars on the form
else $_SESSION['form_vars']['variable'] = null;
// now in the form we can set the field values to $_SESSION['form_vars']
['variable'] and this will be maintained across submissions of the form.
//*
//* build the form here
//*
// when its processed you need to do the following to clear the variables:
unset($_SESSION['form_vars'][);
// its also good practise to tidy the session record too using:
session_destroy(); // but only after you have saved your values...
?>[/PHP]
Does that help ?
Questions ?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pat Patterson |
last post by:
I'm having serious issues with a page I'm developing. I just need some
simple help, and was hoping someone might be able to help me out in
here.
I have a form, that consists of 3 pages of...
|
by: Nathan Bloomfield |
last post by:
Does anyone know if there is any documentation which relates to Access2k + ?
or can anyone help adjust the code?
I am having trouble converting the DAO references.
TITLE :INF: How to...
|
by: starace |
last post by:
I have designed a form that has 5 different list boxes where the
selections within each are used as criteria in building a dynamic
query. Some boxes are set for multiple selections but these list...
|
by: CAD Fiend |
last post by:
Hello,
Well, after an initial review of my database by my client, they have
completely changed their minds about how they want their form. As a
result, I'm having to re-think the whole process....
|
by: Will |
last post by:
Hi all.
I'm learning VB.Net and am developing a WinForms app.
I'm trying to make an app that I will use to scan in one or more than
on image. I want to use a tabbed interface to hold each image....
|
by: MikeY |
last post by:
Hi Everyone,
Does anyone know where I can get my hands on a sample with source code of a
simple dynamic button control in C# Windows form. I am looking for a sample
that uses a class library...
|
by: Tyler Carver |
last post by:
I am trying to use some dynamic controls that are built and then added
to tables. The problem that I am having is the timing of when I can
populate the controls and have the state remain after a...
|
by: Abraham Luna |
last post by:
how do i stop the dynamic validators from breaking explorer
if i use a dynamic validator and move to a different control it breaks
explorer and i can type in the page when i'm not supposed to....
|
by: George Meng |
last post by:
I got a tough question:
The backgroud for this question is:
I want to design an application works like a engine.
After release, we can still customize a form by adding a button, and source
code...
|
by: deejayquai |
last post by:
Hi
I'm trying to produce a report based on a dynamic crosstab. Ultimately
i'd like the report to actually become a sub report within a student
end of year record of achievement. The dynamic...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |