2

How do I add each result from $row to the $valueIDArray? I then want to use the $valueIDArray to get results from a second database, how do I do that?

$sql = "SELECT * FROM venue
WHERE capacity >= 'partySize'";

//step 2 - executing the query
$result =& $db->query($sql);
if (PEAR::isError($sql)) {
    die($result->getMessage());
}


while($row = $result -> fetchrow()){
    $valueIDArray = $row[0];
}

2 Answers 2

2

You should do it this way:

$valueIDArray = array()

while($row = $result -> fetchrow()){
    $valueIDArray[] = $row[0];
}

Define array before loop, and in loop simple add elements to array using [] after array name

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

Comments

2
$sql = "SELECT * FROM venue WHERE capacity >= 'partySize'";

//step 2 - executing the query
$result =& $db->query($sql);
if (PEAR::isError($sql)) {
    die($result->getMessage());
}

$valueIDArray = array();
while($row = $result -> fetchrow()){
    $valueIDArray[] = $row[0];
}

You have to add the [] braces. Like this, you always add another entry for the row.

1 Comment

I see you added declaring array before loop :)

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.