Current location: Hot Scripts Forums » Programming Languages » PHP » retrieve information from MYSQL through drop down list


retrieve information from MYSQL through drop down list

Reply
  #1 (permalink)  
Old 09-01-04, 05:17 PM
minglou minglou is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
retrieve information from MYSQL through drop down list

Hi guys,

I need help.

I want to build a phone card table rates in PHP,

basicly, customer choose coutry name from drop down list, and it will retrieve
information from mysql database, it will show like this

Coutry Name Coutry Code Area/City_Code Us Dollars Toll Free
Albania 355 0.2150 0.2450
Algeria 213 0.1704 0.2004
Algeria-mobile 213 61,98-99 0.2300 0.2600

only one coutry name each time, at the same page.


this is what i did:

Code:
<?
$localhost="localhost";
$username="xxx";
$password="yyy";
$database="zzz";

$linkid=mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

mysql_select_db("rates",$linkid);
$resultid=mysql_query("SELECT * From rates",$linkid);

echo"<table border=1><tr><th>Coutry Name</th>";
echo"<th>Coutry Code</th><th>Area/City_Code</th><th>Us Dollars</th><th>Toll Free</th></tr>";
while ($row = mysql_fetch_row($resultid))
{
echo"<tr>";
foreach ($row as $field)
{
echo"<td>$field</td>";
}
echo"</tr>";
}
echo"</table>";
mysql_close($linkid);
?>
but this code retrieve all the information at the same time.

what i want is drop down list, choose coutry name, and retrieve information from database.

this is database i created:

Code:
CREATE TABLE `rates` (
  `country_name` varchar(20) NOT NULL default '',
  `country_code` varchar(20) default NULL,
  `area/city_code` varchar(20) default NULL,
  `us_dollars` decimal(15,4) default NULL,
  `toll_free` decimal(15,4) default NULL,
  PRIMARY KEY  (`country_name`)
) TYPE=MyISAM;

#
# Dumping data for table `rates`
#

INSERT INTO `rates` VALUES ('Albania', '355', '', '0.2150', '0.2450');
INSERT INTO `rates` VALUES ('Algeria', '213', NULL, '0.1704', '0.2004');
INSERT INTO `rates` VALUES ('Algeria-mobile', '213', '61,98-99', '0.2300', '0.2600');


Thank you guys, anybody kindly help me please?

sean
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-01-04, 05:42 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Create a form something like this. Change "name of your script" to the name of the script you posted above..

<form action="name of your script" method="post">
<select name=country_name size=1>
<option value=Albania>Albania
<option value=Algeria>Algeria
</select>
<p>
<input type=submit name=submit value="Get Rate">
</form>

In your script, right after the opening <? tag, add this...
$country_name=$_POST['country_name'];

Change your query to this...

$resultid=mysql_query("SELECT * FROM rates WHERE country_name='$country_name", $linkid);

See if that works.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-01-04, 05:59 PM
minglou minglou is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Hi mdhall,

Thank you so much helping me!

This the code( i put in the same page ):


Code:
<form action="rates2.php" method="post">
<select name=country_name size=1>
<option value=Albania>Albania
<option value=Algeria>Algeria
</select>
<p>
<input type=submit name=submit value="Get Rate">
</form>



<?php

$country_name=$_POST['country_name'];

$localhost="localhost";
$username="xxx";
$password="yyy";
$database="zzz";

$linkid=mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

mysql_select_db("rates",$linkid);
$resultid=mysql_query("SELECT * FROM rates WHERE country_name='$country_name", $linkid);

echo"<table border=1><tr><th>Coutry Name</th>";
echo"<th>Coutry Code</th><th>Area/City_Code</th><th>Us Dollars</th><th>Toll Free</th></tr>";
while ($row = mysql_fetch_row($resultid))
{
echo"<tr>";
foreach ($row as $field)
{
echo"<td>$field</td>";
}
echo"</tr>";
}
echo"</table>";
mysql_close($linkid);
?>

However, i got this error:

Code:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/ddd/public_html/rates2.php on line 31
line 31 is while ($row = mysql_fetch_row($resultid)), i think the problem is $resultid, $resultid=mysql_query("SELECT * FROM rates WHERE country_name='$country_name", $linkid);

How can i correct this?

Thank you!

sean
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-03-09, 10:43 PM
cj158 cj158 is offline
New Member
 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
re

$resultid=mysql_query("SELECT * FROM rates WHERE country_name='$country_name' ", $linkid);


now you try this n c........
there was a small mistake. i corrected it
good luck
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help the drop down list! minglou PHP 4 08-23-04 10:47 PM
multi selection drop down list studenteye PHP 1 07-10-04 08:20 AM
Looking for robust mailing list manager with MySQL DawnMcTeo PHP 2 06-27-04 01:50 AM
display selected value in drop down list angela JavaScript 1 04-02-04 09:43 AM
month drop down list angela JavaScript 2 03-31-04 03:33 AM


All times are GMT -5. The time now is 01:45 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.