while ($row_comp = $comp->fetch_array())
{
$comp_count++;
$comp_id = $row_comp['TID'];
$SqlString = "select * from pers where TID = \"$comp_id\"";
echo "str = ".$SqlString."<br>";
$pers = $conn->query($SqlString);
while ($row_pers = $pers->fetch_array())
{
The screen output looks like this:
str = select * from pers where TID = "10019706"
str = select * from pers where TID = "10019771"
str = select * from pers where TID = "10019779"
Fatal error: Call to a member function fetch_array() on a non-object in /home/langsyst/public_html
Line 58 is the 2nd while
Otherwise, we have another error to deal with and we need to determine what that is. Do you have error reporting turned on? If it is turned on and you're not seeing an error, please replace your code with the following and take note of the additions I've added for exposing the error. My first change is on line 7 and then I've added code after the end of the second while loop.
while ($row_comp = $comp->fetch_array())
{
$comp_count++;
$comp_id = $row_comp['TID'];
$SqlString = "select * from pers where TID = \"$comp_id\"";
echo "str = ".$SqlString."<br>";
if ($pers = $conn->query($SqlString) ) {
while ($row_pers = $pers->fetch_array()) {
...
}
} else {
if ($conn->error) {
echo "{$conn->error}<br>SQL = $SqlString";
} else {
echo '$conn is a(n) '. gettype($conn);
}
}
}
This is weird?!?!?!
I modified the code per your example. I don't get an error message, however, if I keep refreshing the program, it will give me one more record before it craps out!
To turn on error reporting, place these two lines at the beginning of your PHP page.
error_reporting(E_ALL);
ini_set('display_errors','on');
And again, it keeps giving me one more record before it fails.
I've attached the code. It's small, I'm just trying to clean up some garbage data.
Thought this would be a piece of cake, after all how hard could it be!
Fix_Data_2A.php
$comp_count = 0;
$per_count = 0;
$SqlString = "select * from comp where ALFA = \" \" and COMPANY = \" \"";
$comp = $conn->query($SqlString);
while ($row_comp = $comp->fetch_array())
{
$comp_count++;
$comp_id = $row_comp['TID'];
$SqlString = "select * from pers where TID = \"$comp_id\"";
echo "str = ".$SqlString."<br>";
if ($pers = $conn->query($SqlString))
{
if ($pers->num_rows > 0)
{
while ($row_pers = $pers->fetch_array())
{
$pers_id = $row_pers['PNID'];
$SqlString = "delete from pers where TID = '$comp_id' and PNID = '$pers_id'";
$pers = $conn->query($SqlString);
$per_count++;
}
} else {
echo "<p>No records found for query $SqlString</p>\n";
}
}
else
{
if ($conn->error)
{
echo "{$conn->error}<br>SQL = $SqlString";
}
else
{
echo '$conn is a(n) '. gettype($conn);
}
}
}
I didn't think it would work because it keeps blowing up on the while statement.
Try this yourself (I'm not worried about the data, I have backups and it's really not current).
Go to:
1: http://langsystems.net/Lansco/
(you need to do this for the session vars)
2: http://langsystems.net/Lansco/Fix_Data_2A.php
Look at the last "TID"# in the query, then refresh the page. You'll get the next record.
There are only 234 records that match the 1st while loop. Do I have to hit refresh 234 times? :)
$SqlString = "delete from pers where TID = '$comp_id' and PNID = '$pers_id'";
$pers = $conn->query($SqlString);
to $SqlString = "delete from pers where TID = '$comp_id' and PNID = '$pers_id'";
$conn->query($SqlString);
There is no need to store the results of the delete into a variable unless you need to view results such as affected_rows. If you still want to store those results, store them in a new variable instead of reusing $pers.'WEB > jQuery' 카테고리의 다른 글
PHP array_push (0) | 2018.01.14 |
---|---|
Fatal error: Call to a member function query() on null (0) | 2018.01.14 |
달력 - 날짜입력기(Date Picker) (0) | 2018.01.14 |
javascript comma and uncomma (0) | 2018.01.14 |
[jQuery] following sidebar (0) | 2018.01.14 |