Jump to content


Photo

While Loop and combo box


  • Please log in to reply
2 replies to this topic

#1 Malcolmhire2001

Malcolmhire2001
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 23 May 2006 - 11:24 AM

Hello, i am trying to make a form where you can select a member from a combo box then you would be able to edit there details, using a while loop.

all that is happening is that it there is a empty combo box and the button

heres my code:

<?php
    include("connection.inc.php");
    $connection = connect();

    $sql = "SELECT membership_no, forename, surname, address_1, address_2, post_code, telephone_no
                FROM tbl_members
                ORDER BY surname";

    $result = @mysql_query($sql) or die (mysql_error());
    $option_block = "";
    
    while ($row = mysql_fetch_array($result))
    {
                    $membership_no = $row['membership_no'];
        $forename = $row['forename'];
                    $surname = $row['surname'];
        $address_1 = $row['address_1'];
        $address_2 = $row['address_2'];
        $postcode = $row['post_code'];
        $telephone_no = $row['telephone_no'];
     
        $option_block .= "<option value=\"$membership_no\"> $membership_no, $forename, $surname, $address_1, $address_2, $post_code, $telephone_no</option>";
    }

    $display_block = "

        <FORM METHOD=\"post\" ACTION=\"index.php?page=show_existing.php\">

        <P><strong>Contact:</strong>
        <select name=\"membership_no\">
                $option_block
        </select>

        <INPUT TYPE=\"SUBMIT\" NAME=\"submit\" VALUE=\"Select this Member\"></P>
        </form>

        ";
?>
<HTML>
<HEAD>
<TITLE>User Management</TITLE>
</HEAD>
<BODY>
<h1>User Management</h1>
<h3>Modify a User</h3>
<P>Select a user from the list below, to modify the user's record.</p>

<? echo "$display_block"; ?>

</BODY>
</HTML>

Thanks to anyone that can help

Malcolm


#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 23 May 2006 - 11:51 AM

Hello

the code seems the be correct....

try removing the @ sign from mysql_query()

also try,

$result = @mysql_query($sql) or die (mysql_error());

$num = mysql_num_rows($result);
echo $num;//this will display no of records..if there are any in the db

hth
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 Malcolmhire2001

Malcolmhire2001
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 23 May 2006 - 01:03 PM

i solved the problem

i stupidly had no data in the SQL table [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

thanks anyway




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users