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
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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

[!--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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[!--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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.