Jump to content

help populating combo box


ichversuchte

Recommended Posts

I am trying to populate a combo box, but i keep getting this error - "Query failed. " in my browser.

This is what the code looks like

[code]
<?php
include_once('Scripts/conn/cid.php');
  
$sql = "SELECT ra_name FROM staff_elkin";

$result = mysql_query($sql)
          or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) == 1)
{
    while ($row = mysql_fetch_array($result))
    {        
    $title = $row['title'];
    ?>
    <select name="raname" id="raname">
    <?php echo("<option value='$title'>$title</option>"); ?>
    </select>
    <?php
    }
}
    include_once('Scripts/close/end.php');
?>[/code]


This is what the connection to the databse looks like

[code]


<?php
$usr = "xxxxxx";
$pwd = "xxxxxxx";
$db = "xxxxx";
$host = "localhost";

# connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }

?>


anyone have any idea
Link to comment
https://forums.phpfreaks.com/topic/8913-help-populating-combo-box/
Share on other sites

This is what i have now in the code and the error is gone but a combo box doesn't appear and there is def. people in this table.

THIS IS THE CODE OR UPLOAD.PHP

[code]


<?php
include_once('Scripts/conn/cid.php');
  
$sel=mysql_select_db($db);

$sql = "SELECT ra_name FROM staff_elkin";

$result = mysql_query($sql)
          or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) == 1)
{
    while ($row = mysql_fetch_array($result))
    {        
    $title = $row['title'];
    ?>
    <select name="raname" id="raname">
    <?php echo("<option value='$title'>$title</option>"); ?>
    </select>
    <?php
    }
}

    include_once('Scripts/close/end.php');
?>
[/code]

THIS IS THE CODE FOR THIS FILE - include_once('Scripts/conn/cid.php');


[code]
<?php
    $usr = "";
    $pwd = "";
    $db = "forthest_intranet";
    $host = "localhost";

    # connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    mysql_select_db($db);
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

?>

and now i don't get anything[/code]
This fixed the problem with showing output, I can now see combo box but its printing out two of them with nothing in them.
I have the page here - [a href=\"http://ohrl.forthestudentsbookstore.com/Elkin/upload.php\" target=\"_blank\"]http://ohrl.forthestudentsbookstore.com/Elkin/upload.php[/a]

I wrote this sql state to make sure there is something there...which you can there is something there

here the code revised....half of it is the test query



[code]
<?php
include_once('Scripts/conn/cid.php');

$sql = "SELECT ra_name FROM staff_elkin";

$result = mysql_query($sql)
          or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) > 0)
{
    while ($row = mysql_fetch_array($result))
    {        
    $title = $row['title'];
    ?>
    <select name="raname" id="raname">
    <?php echo("<option value='$title'>$title</option>"); ?>
    </select>
    <?php
    }
}

    include_once('Scripts/close/end.php');
?>



//THIS IS THE QUERY CODE TO TEST THE DATABASE


<?php
include_once('Scripts/conn/conn.php');


$rowsPerPage = 300;

$pageNum = 1;

if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}

$offset = ($pageNum - 1) * $rowsPerPage;

$query = "SELECT ra_name FROM staff_elkin";


$result = mysql_query($query) or die('Error, query failed');


echo '<table border="0">';
while(list($raname) = mysql_fetch_array($result))
{
echo "<tr><td>$raname <em>made the request:</em></td></tr>";
}

echo '</table>';
echo '<br>';
include_once('Scripts/close/end.php');
?>

[/code]
[!--quoteo(post=370708:date=May 2 2006, 11:39 PM:name=ichversuchte)--][div class=\'quotetop\']QUOTE(ichversuchte @ May 2 2006, 11:39 PM) [snapback]370708[/snapback][/div][div class=\'quotemain\'][!--quotec--]
This fixed the problem with showing output, I can now see combo box but its printing out two of them with nothing in them.
I have the page here - [a href=\"http://ohrl.forthestudentsbookstore.com/Elkin/upload.php\" target=\"_blank\"]http://ohrl.forthestudentsbookstore.com/Elkin/upload.php[/a]

I wrote this sql state to make sure there is something there...which you can there is something there

here the code revised....half of it is the test query
[code]
<?php
include_once('Scripts/conn/cid.php');

$sql = "SELECT ra_name FROM staff_elkin";

$result = mysql_query($sql)
          or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) > 0)
{
    while ($row = mysql_fetch_array($result))
    {        
    $title = $row['title'];
    ?>
    <select name="raname" id="raname">
    <?php echo("<option value='$title'>$title</option>"); ?>
    </select>
    <?php
    }
}

    include_once('Scripts/close/end.php');
?>
//THIS IS THE QUERY CODE TO TEST THE DATABASE
<?php
include_once('Scripts/conn/conn.php');


$rowsPerPage = 300;

$pageNum = 1;

if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}

$offset = ($pageNum - 1) * $rowsPerPage;

$query = "SELECT ra_name FROM staff_elkin";
$result = mysql_query($query) or die('Error, query failed');
echo '<table border="0">';
while(list($raname) = mysql_fetch_array($result))
{
echo "<tr><td>$raname <em>made the request:</em></td></tr>";
}

echo '</table>';
echo '<br>';
include_once('Scripts/close/end.php');
?>

[/code]
[/quote]
in your sql you select column 'ra_name' and in line [code]$title = $row['title'];[/code]you look in column 'title'. Take look at this.
[!--quoteo(post=370721:date=May 3 2006, 12:49 AM:name=ichversuchte)--][div class=\'quotetop\']QUOTE(ichversuchte @ May 3 2006, 12:49 AM) [snapback]370721[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Ok...i changed that and it filled the combo box, but it create a combobox for everyname. It didn't put them all in one and that is what i wanted?

i appreciate your help...
[/quote]
move line [code]<select name="raname" id="raname">[/code]before and line[code]</select>[/code]after while loop
Ok i did that and the code looks like this revised...

That fixed the double combobox problem, but now its only filling one name into the box.



[code]

<?php
include_once('Scripts/conn/cid.php');

$sql = "SELECT ra_name FROM staff_elkin";

$result = mysql_query($sql)
          or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) > 0)
{
    while ($row = mysql_fetch_array($result))
    {        
    $title = $row['ra_name'];
    
    }
    ?>
    <select name="raname" id="raname">
    <?php echo("<option value='$title'>$title</option>"); ?>
    </select>
    <?php
    
}

    include_once('Scripts/close/end.php');
?>
[/code]
try[code]<?php
include_once('Scripts/conn/cid.php');

$sql = "SELECT ra_name FROM staff_elkin";

$result = mysql_query($sql)
          or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) > 0)
{
    echo '<select name="raname" id="raname">';
while ($row = mysql_fetch_array($result))
    {    
    $title = $row['ra_name'];
    echo("<option value='$title'>$title</option>");
    }

    echo '</select>';

    
}

    include_once('Scripts/close/end.php');
?>[/code]
[!--quoteo(post=370741:date=May 3 2006, 01:11 AM:name=ichversuchte)--][div class=\'quotetop\']QUOTE(ichversuchte @ May 3 2006, 01:11 AM) [snapback]370741[/snapback][/div][div class=\'quotemain\'][!--quotec--]
When i used that code, it did the same thing. only filled one combobox....
[/quote]
I edit previous post

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.