Reply
Help selecting from list, then showing results
Old 04-09-2008, 06:03 PM Help selecting from list, then showing results
Average Talker

Posts: 17
Name: Craig Shaw
Hi there.
Sorry to make a seperate post, but it is a seperate issue.

I have a page which starts off with a drop down list. This lists all customers that are stored in the Customers table and shows the cust_id. (Also, is it easy to show the cust_id as well as the name next to it?)

How do I code it so that when the user chooses a customer from the list, it will then display any records in the linked table (Timesheets) where the cust id is present.

So it will just show any timekeeping tasks that have been added against the chosen customer.

My code is as follows:

Code:
<h1>View Report</h1>
<p>Please choose a Customer ID from the drop down selection below, then press Submit to view a list of the tasks recorded against the select Customer.</p>
<?php
include 'config.php';
include 'opendb.php';
$res=mysql_query("SELECT * FROM customers order by cust_id") or die(mysql_error()); 
echo "<select name=myselect>"; 
while($row=mysql_fetch_assoc($res)) { 
 
echo "<option value=$row[ID]>$row[cust_id]</a></option>"; 
} 
echo "</select>"; 
include 'library/closedb.php';
?>
craigshaw is offline
Reply With Quote
View Public Profile Visit craigshaw's homepage!
 
When You Register, These Ads Go Away!
     
Old 04-09-2008, 06:41 PM Re: Help selecting from list, then showing results
Junior Talker

Posts: 4
You may want to try the following. It will submit the information to the same page, and query the Timesheets table for the related data.

PHP Code:
<h1>View Report</h1>
<p>Please choose a Customer ID from the drop down selection below, then press Submit to view a list of the tasks recorded against the select Customer.</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'?>">
<?php
include 'config.php';
include 
'opendb.php';
$res=mysql_query("SELECT * FROM customers order by cust_id") or die(mysql_error()); 
echo 
"<select name=myselect>"
while(
$row=mysql_fetch_assoc($res)) { 
 
echo 
"<option value=$row[ID]>$row[cust_id]</a></option>"

echo 
"</select>"
include 
'library/closedb.php';
?>
<input type="submit" />
</form>
<?php
// check if form was submitted
if (isset($_POST['myselect']))
{
    
$id $_POST['myselect'];
    
// query the records in Timesheets where the customer_id = $id
    
$res mysql_query("SELECT * FROM Timesheets WHERE customer_id=$id") or die(mysql_error());
    
    while(
$row mysql_fetch_assoc($res)) 
    {
        
// print here info about the current row
    
}
}
?>

Last edited by doug_matt : 04-09-2008 at 06:44 PM.
doug_matt is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 08:15 AM Re: Help selecting from list, then showing results
Average Talker

Posts: 17
Name: Craig Shaw
Hi there.
Thanks for the reply. I had added that code to my page, and when I run it I get the following error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.

This is a copy of the code that I use, I had to change it due to table and row names being incorrect. To actually see it on the page i'm working on, go to http://www.lindendesign.co.uk/project/report1.php.

Code:
<h1>View Report</h1>
<p>Please choose a Customer ID from the drop down selection below, then press Submit to view a list of the tasks recorded against the select Customer.</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<?php
include 'config.php';
include 'opendb.php';
$res=mysql_query("SELECT * FROM customers order by cust_id") or die(mysql_error()); 
echo "<select name=myselect>"; 
while($row=mysql_fetch_assoc($res)) { 
 
echo "<option value=$row[ID]>$row[cust_id]</a></option>"; 
} 
echo "</select>"; 
include 'library/closedb.php';
?>
<input type="submit" />
</form>
<?php
// check if form was submitted
if (isset($_POST['myselect']))
{
    $id = $_POST['myselect'];
    // query the records in Timesheets where the customer_id = $id
    $res = mysql_query("SELECT * FROM timekeeping WHERE cust_id=$id") or die(mysql_error());
 
    while($row = mysql_fetch_assoc($res)) 
    {
        // print here info about the current row
    }
}
?>

Last edited by craigshaw : 04-10-2008 at 08:25 AM.
craigshaw is offline
Reply With Quote
View Public Profile Visit craigshaw's homepage!
 
Old 04-14-2008, 06:35 PM Re: Help selecting from list, then showing results
Junior Talker

Posts: 4
There's a lost tag in the form. Change the line
PHP Code:
echo "<option value=$row[ID]>$row[cust_id]</a></option>"
to
PHP Code:
echo "<option value=$row[ID]>$row[cust_id]</option>"
I should work now.
doug_matt is offline
Reply With Quote
View Public Profile
 
Old 04-15-2008, 03:27 PM Re: Help selecting from list, then showing results
Average Talker

Posts: 17
Name: Craig Shaw
hi,

thanks for the reply again,

i still have the same problem, even after removing the [/a].

Any ideas?

Thanks again,

Craig
craigshaw is offline
Reply With Quote
View Public Profile Visit craigshaw's homepage!
 
Old 04-15-2008, 11:58 PM Re: Help selecting from list, then showing results
Junior Talker

Posts: 4
Well, I saw your code and there's nothing in the value of the option tag.
PHP Code:
<option value=$row[ID]>$row[cust_id]</option
Looks like theres no ID in your database. Try changing to that:
PHP Code:
<option value=$row[cust_id]>$row[cust_id]</option

Last edited by doug_matt : 04-15-2008 at 11:59 PM.
doug_matt is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help selecting from list, then showing results
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13107 seconds with 13 queries