开发者

Multiple Arrays

开发者 https://www.devze.com 2023-03-08 23:55 出处:网络
I have 2 Arrays in my code.$id = array();gets its values from the previous page.And $nameArray = array(); gets its values from an sql query.The $id array works fine, but my $nameArray doesn\'t work, a

I have 2 Arrays in my code. $id = array(); gets its values from the previous page. And $nameArray = array(); gets its values from an sql query. The $id array works fine, but my $nameArray doesn't work, and I'm assuming because you can only have 1 array?

Is there a way to store the values for $id in their own array, and also store the values for $nameArray in a seperate array or is that not possible?

Thanks!

Here is the code for the $id

$id = array();

$street = $_POST['site_street'];

$db_link = mysql_connect('example', 'example', 'example');
if (!$db_link)
    die('Cannot connect : ' . mysql_error());

$db_selected = mysql_select_db('Orders', $db_link);
if (!$db_selected)
    die ('Cannot select database : ' . mysql_error());

$sql = "SELECT clientreferrance, clientname, sitestreet, inspectiontype FROM  `PropertyInfo` WHERE  `sitestreet` LIKE  '$street'";
$result = mysql_query($sql);

if (!$result)
    die('Could not successfully run query: ' . mysql_error());

if (mysql_num_rows($result) > 0)
{

?>
<form action="noJavaScript.php" name="theForm" method="post">
<table style="border: 1px solid black">
    <?php
        while ($row = mysql_fetch_assoc($result))
        {
            echo '<tr><td>';
            echo '<input type="checkbox" name="selected[]" value="'.$row['clientreferrance'].'"/>';
            echo '</td>';
            foreach ($row as $key => $value)
                echo '<td>'.htmlspecialchars($value).'</td>';
            echo '</tr>';
        }
    ?>
</table>
<input type="submit" name="submit" value="Edit/Modify Order" onClick="document.theForm.action='modify.php'">
<input type="submit" name="submit" value="Clone Order" onClick="document.theForm.action='clone.php'">
<开发者_如何学JAVAinput type="submit" name="submit" value="Archive Order" onClick="document.theForm.action='../member-index.php'">
</form>

And the code for the $nameArray SQL query:

$nameArray = array();
$dbh2 = mysql_connect("example", "example", "example", true); 
mysql_select_db('Inspectors', $dbh2);

//Create query
$query2 = mysql_query("SELECT * FROM `InspEmail` WHERE `Company` LIKE '$user'");

// display query results
while($row2 = mysql_fetch_array($query2)) {
    $nameArray[] = $row2['name']; 
}
mysql_close($dbh2); 


You can have as many differently named arrays as you want (assuming you don't run out of memory).

The problem will lie in your code elsewhere. As a rule of thumb, blame your own shortcomings before pointing the finger at a well established language, compiler, library, etc. ;)


Array is the fundamental types in any programming language, as it is one of the basic features, and the advantage of using a computer.

Of course you're allowed to multiple arrays. Similarly, you're allowed to have multiple integer:

$int1 = 1;
$int2 = 2;
$string1 = "string";
$string2 = "otherstring";

If you are allowed to do the above, why are you not allowed to have multiple arrays. With the logic of only have 1 array, you would only be allowed to have 1 integer, 1 string, 1 double etc..

Allowing multiple variables with different values is the fundamental concept of computers, basically. (We can go deeper and talk about memory and how variables are store, but you probably don't need that information)


using Multiple arrays at the same time-

1)

<?php
$FirstArrays = array('a', 'b', 'c', 'd');
$SecondArrays = array('1', '2', '3', '4');

foreach($FirstArrays as $index => $value) {
    echo $FirstArrays[$index].$SecondArrays[$index];
    echo "<br/>";
}
?>

or 2)

<?php
$FirstArrays = array('a', 'b', 'c', 'd');
$SecondArrays = array('1', '2', '3', '4');

for ($index = 0 ; $index < count($FirstArrays); $index ++) {
  echo $FirstArrays[$index] . $SecondArrays[$index];
  echo "<br/>";
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消