Notice: Undefined variable: sql13parta

Why is it that the sequel statement is not being defined? I did this so many times and it worked but not now:
tables.php (6.6 KB)

If the first query returns no results, that is if the array $joinids12 has no content, then the entire loop that creates $sql13parta doesn’t run - could that be the problem? Also you seem to spend time in that loop building up a variable called $sql13 with all the “text_data LIKE” clauses, but then never use it in the query, which leaves the beginning of the query with incorrect syntax because it ends in “AND”.

Also, think of new variable names - by calling them $sql13a and the like, you have to spend ages trying to figure out whether you’ve mis-typed an l or a 1 because they look similar and are adjacent.

In the loop that builds $joinids12, you check for each element of that array being !=NULL || !="" - shouldn’t that be an AND condition rather than an OR? I may be wrong, it just seems that condition won’t actually exclude anything.

Yes you got a point. Although I’m not sure how to get past this.tables.php (6.7 KB)

Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
)
The array isn’t empty but the results are empty.
I want the sql to work when this column is filled.

Looks very much to me as if the array is empty. I can’t see why it would give ‘variable not found’ (presumably that’s when you try to execute the query you’ve built up) as the array has some elements and it should be building the queries. What does count() return for an array with seven empty elements? And your modified code still builds up $sql13 but doesn’t use it.

i want it to work once i fill up the column. But either way count shows one thing. And the value is empty.
` if(0<count($joinids12)){
for($j=0;$j<count($joinids12);$j++){
$join_ids = explode(“-”, $joinids12[$j]);
$sql13part = "SELECT * FROM “.$dbTable3.” WHERE ";
$sql13parta = "(book = “.$b1.” AND chapter = “.$c1.”) AND ";
$sql13partb = "(book = “.$b2.” AND chapter = “.$c2.”) AND “;
$sql13 = “”;
for($k=0;$k<count($join_ids);$k++){
$sql13 .= “text_data LIKE '%”.$words12[$join_ids[$k]-1].”%’ ";
}
$sql13a = $sql13part.$sql13parta;
$sql13b = $sql13part.$sql13partb;
}
}

echo $sql13a."<br /><br /><br />\n";
echo $sql13b."<br /><br /><br />\n";`

Can’t I add an if statement somehow to take out the sql statement if the column is empty entirely?

Yes, you can and should check whether your second queries exist before trying to execute them - if the $joinids12 array is empty, you won’t build the query and therefore you cannot execute it, nor do anything with the results, so the query and anything you do with the results should be within the if().

Your code above still builds $sql13 from the contents of $join_ids[], but then does nothing with it. Don’t you need to have something like:

$sql13a = $sql13part . $sql13parta . $sql13;
$sql13b = $sql13part . $sql13partb . $sql13;

What is the output from the echo $sql13a line?

`SELECT * FROM bible WHERE (book = 11 AND chapter = 8) AND

SELECT * FROM bible WHERE (book = 1 AND chapter = 8) AND `

but should also have "text_data LIKE ‘word’ " but it’s empty.

I could put:
for($i=0;$i<count($join_ids);$i++){
if($join_ids[$i]!=“” || $join_ids[$i]!=NULL){
}
}

Yes, but that’s because you build that into the variable $sql13 in the loop, but don’t do anything with it in your code. Or is it still empty?

If the $joinids12[] array is still empty, though, surely none of it will work anyway. Have you got some content in that array now? If not, do you know why not?

yes i’m filling it up manually. But if they’re still empty I want the script to ignore it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.