| | |
Listbox is not displaying the correct information if at all
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
Solved Threads: 0
Hello everyone I have some code listed below, well with this code I it does not display anything in the listbox. When I have it displaying the stuff in the listbox it does not display the correct stuff...like less than 10. I have put the line of code in bold. Can someone look at it and tell what I am missing. My goal is to have two list boxes, but they are not going to be dependent on each other.
<!-- //to display a listbox from a database when something is clicked it is the item is then displayed underneath the listbox
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
//-----------------------------------
//this is the connection string to connect to the database
//do not delete or change anything on the next two lines
//-----------------------------------
$db = mysql_connect("localhost", "brian", "Golffor1") or die(mysql_error());
mysql_select_db("brian_aTitle") or die (mysql_error);
$id='10';
// $query3="Select * from 'Premiums' where id < $id";
$query3 = "SELECT `Premium` AS 'premium' FROM `Premiums` where ID < 10";
$result3 = mysql_query($query3);
$the_data = array();
$the_string = "";
while($data = mysql_fetch_row($result3))
{
$the_data[] = $data[0];
}
for ($x = 0; $x < count($the_data); $x++)
{
$the_string = $the_string . '"' . $the_data[$x] . '"';
if ($x != (count($the_data) - 1)){ $the_string = $the_string . ", "; }
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--//hide from old browsers
var Descriptions = new Array(<?PHP echo $the_string; ?>);
function ShowDesc(id)
{
document.listbox.description.value = Descriptions[id];
}
//end hide from old browsers-->
</script>
</head>
<body>
<form name="listbox">
<?
//start of the array
enhanced_list_box(array(
'table' => 'Premiums',
'id_number' => 'id',
'value_field' => 'Policy',
'highlight_id' => 1));
//this display's the listbox so the user can select a service
function enhanced_list_box($options){
// $sql = "select " . $options['id_number'];
// $sql .= ", " . $options['value_field'];
// $sql .= " from " . $options['table'];
// $sql .= "where " . $options['id_number'] < $ID;
$sql = "SELECT `policy` AS 'policy' FROM `Premiums` where ID < 10";
/* append any where criteria to the sql */
if(isset($options['where_statement'])) {
$sql .= " where " . $options['where_statement'] ;
}//CLOSE OF IF STATEMENT
$result = mysql_query($sql)
or die(mysql_error());
echo '<select name="' . $options['id_number'] . '" size="1" onChange="ShowDesc(this.selectedIndex)">';
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
if($row[0] == $options['highlight_id']) {
echo '<option value="', $row[0], '" SELECTED>',
$row[1], '</option>';
}//CLOSE OF IF STATEMENT
else {
echo '<option value="', $row[0], '">',
$row[1], '</option>';
}//CLOSE OF ELSE STATEMENT
}//CLOSE OF WHILE STATEMENT
echo '</select>';
}
?>
<br>
<textarea name="description" readonly="TRUE" cols="40">Choose an item to view it's description.</textarea>
</form>
</body>
</html>•
•
•
•
>$sql = "SELECT `policy` AS 'policy' FROM `Premiums` where ID < 10";
This statement just doesn't make any sense in terms of SQL. And you got some strange (non standard ) apostrophe's there as well.
Iamthwee, what are you talking about ? the back ticks `` denote a field name or table name within mySQL proper syntax.
PHP fills these in for you if you don't use them.
GardCMS :: Open Source CMS :: Gardcms.org
•
•
Join Date: Oct 2007
Posts: 19
Reputation:
Solved Threads: 0
Hi,
I am a newbie to PHP. what is the way to hold the selected value from the list. How does the return statement work in this context.
Brgds,
kNish
function enhanced_list_box_05($options){
$sql = "select " . $options['value_field'];
$sql .= " from " . $options['table'];
$result = mysql_query($sql)or die("error in SQL");
echo '<select name="', $options['value_field'],'" size="1">';
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
if($row[0] == $options['highlight_id']) {
echo '<option value="' . $row[0] . '"SELECTED>' . $row[0] . '</option>';
} else {
echo '<option value="' . $row[0] . '">' . $row[0] . '</option>';
echo $row[0];
}
}
echo '</select>';
return $row[0];
}
I am a newbie to PHP. what is the way to hold the selected value from the list. How does the return statement work in this context.
Brgds,
kNish
function enhanced_list_box_05($options){
$sql = "select " . $options['value_field'];
$sql .= " from " . $options['table'];
$result = mysql_query($sql)or die("error in SQL");
echo '<select name="', $options['value_field'],'" size="1">';
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
if($row[0] == $options['highlight_id']) {
echo '<option value="' . $row[0] . '"SELECTED>' . $row[0] . '</option>';
} else {
echo '<option value="' . $row[0] . '">' . $row[0] . '</option>';
echo $row[0];
}
}
echo '</select>';
return $row[0];
}
![]() |
Similar Threads
- won't go past POST (Troubleshooting Dead Machines)
- Listbox and msgbox not displaying content (VB.NET)
- C++ (C++)
- Putting a file together with an exe (C++)
- I need help using VBA for Word Macros (Windows NT / 2000 / XP)
- PLEASE, I need help with this....why can't I get it to work? (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: How to hide .php extension
- Next Thread: Cannot send mail to yahoo
Views: 2155 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date datepart directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql oop parse password paypal pdf php problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web webdesign xml youtube






