I'm having a problem doing the following. I've created a form to print certain results in a table depending on the selection of the user.
I'm trying to create an elseif statement which looks something like this.
PHP Code:
<?php
require_once 'dbinfo.php';
<rest of code............>
<form...........>
$q1_error = "SELECT this FROM that WHERE country=''Canada";
$r1_error = mysql_query($q1_error);
Obviously because I haven't defined the variable $row1_error, I'll get an undefined variable.
The problem is that when I define it in my variables section, it only grabs the 1st row. Now I can't figure out how to do this so it will apply to the entire column from $row1_error['this']. I tried creating a while loop, but it didn't work as I had intended. Nothing needs to be echoed from this column, it's just a condition.
Does anyone have any suggestions on fixing this problem?
Well the code you offered is missing a lot of elements and is pretty broken (guessing due to your trimming to hide unnecessary data). Importantly the IF is missing and just a typo, the sql string is ''Canada, instead of 'Canada'.
What does var_dump($row1_error); provide? Ccan you use mysql_num_rows() to check if there are results returned? If so inside that conditional statement do a while loop $rows = mysql_fetch_array();
Shorts. Thanks for your reply. The problem is that I do not want the while loop to print any records. Maybe that's not a problem and it may be due to my limited knowledge. Basically, I would like to put in my elseif statement something like...
Since I can't make define $row1_error['carrier'] in the elseif statement, I can't get the condition to be true. I'm wondering how I can use that condition.
In short, I want to say that if all those things are TRUE, and $_POST['carrier'] is equal to any thing in column 'carrier' from mysql, then echo _____________________
Edit: Nevermind, i completely misunderstood your problem.
If you want your conditional statement to be evaluated for all rows returned from your query you have no choice but to use a while loop. You'll want to nest your conditional statements within your while loop so that it is evaluated for each value returned.
PHP Code:
while($row = mysql_fetch_array($r1_error)){ if{
}elseif{
}else{
}
}
If that isn't possible then you have some flow issues within your code and you'll need to rework it.
Last edited by Jarrod1937; 04-05-2010 at 10:35 AM.
Bookmarks