php global array help

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default php global array help

    I cant seem to get my $dropdown_value to display. I have tried lots of things to make the array global or even try to call functions, but it is difficult when you are calling 2 tables within an array while looping... Here is the original code... It displays ONLY ONE value of the "admins" and has the correct number of dropdown options from the database, but it does not give values or display names for the last them.


    Code:
    <?php
    include("../include/config.php");
    
    $checkout_connect = mysql_connect($dbhost,$dbUsername,$dbPassword);
    $selectdb1 = mysql_select_db($dbDatabase,$checkout_connect);
    if (!$checkout_connect || !$selectdb1){
    echo "Could <b>NOT</b> connect to database. Please check the config.php!";
    die;
    }
    /*Begin Query*/
    if(!isset($_POST['submit']))
    {
    ?>
    <form name="form" action="<?php echo $PHP_SELF;?>" method="post">
      <table width="700" border="0">
        <tr>
          <td width="200"><div align="right">Item Name:&nbsp;</div></td>
          <td width="100"><input type="text" name="name"><font size=1> Example: Colorjet Ink</font></td>
          <td width="400" align="left"></td>
        <tr>
          <td><width="200"><div align="right">&nbsp;</div></td>
          <td><input type="submit" value="submit" name="submit" /></td>
          <td width="400" align="left"></td>
        </tr>
    
      </table>
    </form>
    <?php
    }
    $count=0;
    
    //Do this once you click submit
    if(isset($_POST['submit']))
    {
    
    //Begin Dropdown Option Grab
    $sql_dropdown = "SELECT * FROM checkout_user WHERE admin='1'";
    $sql_dropdown_result = mysql_query($sql_dropdown) or die('Query failed: ' . mysql_error());
    $numrows = mysql_num_rows($sql_dropdown_result);
    if($numrows == 0)
    {
            echo "None Found";
    }
    else
    {
            for($i=0; $i<$numrows; $i++)
            {
                    while ($dropdown_search = mysql_fetch_array($sql_dropdown_result))
                    {
                            $dropdown_value = array($i => array(dropdown_name => $dropdown_search['name'],
                                                             dropdown_barcode => $dropdown_search['barcode']));
                    }
            }
    }
    
    
    //Begin Second Query and Display values
    $sql = "SELECT * FROM checkout_item WHERE itemname like \"%$_POST[name]%\" OR barcode like \"%$_POST[name]%\"";
    $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
    
    while ($search = mysql_fetch_array($result)){
    $value = array($count => array(itemname => $search['itemname'],
                                 barcode    => $search['barcode'],
                                 returncond => $search['return_condition'],
                                 added      => $search['date_checked'],
                                 notes      => $search['notes'],
                                 status     => $search['is_it_checked_out'],
                                 checkedout => $search['checked_out_by'],
                                 checkedin  => $search['checked_in_by'],
                                 userchk    => $search['checked_out_to'],
                                 used       => $search['times_used'])
                  );
    echo $value[$count]["itemname"];
    
    
    //Display Dropdown Options
    echo "<select name='select'>";
    for($i=0; $i<$numrows; $i++)
    {
            $OPTION=$dropdown_value[$i]["dropdown_name"];
            $VALUE=$dropdown_value[$i]["dropdown_barcode"];
            echo "<option value=$VALUE>$OPTION</option>";
    }
    echo "</select><br>";
    $count++;
    }
    }
    ?>
    blizbiggy is offline Junior Member
    Join Date
    Jun 2011
    Location
    Ohio
    Posts
    2

  2. Similar Questions and Discussions

    1. Global Array
      Hello, I want to organize XML information into an array that can be accessed by any function in the timeline. I also want to give the array an...
    2. Global array slows script way down
      ....been screwing around with multidimensional arrays in this script I'm writing and when I make the arrays global the script slows to the point...
    3. Global array usage?
      This is probably one of the dumbest and simplest questions but I just can't find an answer. I have the following line in my PHP file: $version...
    4. PHP5 and Global Array ($_GET)
      I had a client recently contact me with a script that wasn't working. I quickly isolated the problem as to the fact that the $_GET array was not...
    5. how to make a global scope array
      <20030725224852.1123.qmail@pb1.pair.com> Jack Lee: global $a;
  3. #2

    Default Re: php global array help

    I figured out my problem... and simplified my code a bit... I was told you can do two mysql_fetch_arrays within each other because they use different resources. So, I went back through and tried to figure out why mine only displayed once. Here is my final code:


    Code:
    <?php
    include("../include/config.php");
    
    $checkout_connect = mysql_connect($dbhost,$dbUsername,$dbPassword);
    $selectdb1 = mysql_select_db($dbDatabase,$checkout_connect);
    if (!$checkout_connect || !$selectdb1){
    echo "Could <b>NOT</b> connect to database. Please check the config.php!";
    die;
    }
    
    /*Begin Query*/
    if(!isset($_POST['submit']))
    {
    ?>
    <form name="form" action="<?php echo $PHP_SELF;?>" method="post">
      <table width="700" border="0">
        <tr>
          <td width="200"><div align="right">Item Name:&nbsp;</div></td>
          <td width="100"><input type="text" name="name"><font size=1> Example: Colorjet Ink</font></td>
          <td width="400" align="left"></td>
        <tr>
          <td><width="200"><div align="right">&nbsp;</div></td>
          <td><input type="submit" value="submit" name="submit" /></td>
          <td width="400" align="left"></td>
        </tr>
    
      </table>
    </form>
    <?php
    }
    if(isset($_POST['submit']))
    {
    
    $sql = "SELECT * FROM checkout_item WHERE itemname like \"%$_POST[name]%\" OR barcode like \"%$_POST[name]%\"";
    $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
    
    $count=0;
    while ($search = mysql_fetch_array($result)){
    
    echo $search['itemname'];
    echo " ";
    
    echo "<select name='select'>";
    
    $sql_dropdown = "SELECT * FROM checkout_user WHERE admin='1'";
    $sql_dropdown_result = mysql_query($sql_dropdown) or die('Query failed: ' . mysql_error());
    $numrows = mysql_num_rows($sql_dropdown_result);
    if($numrows == 0)
    {
            echo "None Found";
    }
    else 
    {
            $count2 = 0;
            while ($search2 = mysql_fetch_array($sql_dropdown_result))
            {
                    $OPTION=$search2['name'];
                    $VALUE=$search2['barcode'];
                    echo "<option value=$VALUE>$OPTION</option>";
            $count2++;
            }
    }
    echo "</select><br>";
    $count++;
    }
    }
    ?>
    blizbiggy is offline Junior Member
    Join Date
    Jun 2011
    Location
    Ohio
    Posts
    2

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139