1

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'">
<input 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); 
5
  • 1
    You can have as many arrays as you like. You can definitely have more than 1 array :) Can you post your code so we can see where the problem is? Commented May 26, 2011 at 13:37
  • What do you mean by "array does not work" ? Commented May 26, 2011 at 13:38
  • show some code ? what u mean not work ? Commented May 26, 2011 at 13:38
  • Can you post your SQL query related code? Commented May 26, 2011 at 13:38
  • What is the schema of the table InspEmail ? What is the content of $user? What happens when you run the query directly ? Commented May 26, 2011 at 14:28

3 Answers 3

2

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. ;)

Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

0

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/>";
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.