$query = "SELECT * FROM TOAWorkOrders WHERE TechNum = $TechNum AND WorkDate = $IncDate";
if ($result = $mysqli->query($query))
{
while ($row = $result->fetch_assoc())
{
echo $row['BBT'];
}
}
}
The $query itself is valid. I have tried several different queries, and no matter what i try, the script still dies prematurely. I'm still trying to get this 'mysqli' system down. I one other loop where the same thing is happening. What am I missing?
I'm guessing (without going through everything with a fine-toothed comb) that you could get what you need with a single query, using a BETWEEN <start_date> AND <end_date> clause in your WHERE clause, eliminating the for_loop.
Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett
"But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html
No, the for_loop is necessary because I need to know if the criteria is null. Using 'BETWEEN' only returns data that matches the criteria, in this case, 4 or 5 days out of 7. I need the full array from 0 to 6.
Why do you need a "full array from 0 to 6" ? If you use the single query method and only get results for days 1, 3, and 4, isn't it straightforward that days 0, 2, and 5-6 need to have "empty" place holders?
Let's play a game. Think of the set of integers between 1 and 5 (inclusive). Now think of the integers 1, 3, and 4. Which values are missing from the second set that are present in the first set?
If you said "2 and 5, of course!", then how did you know this without me going through every number in the first place and telling you whether it was or was not present in the second list?
I still don't see what the problem is with the BETWEEN approach.
You execute the query, get the results - store them in an array (indexed by day). Then you do a for() loop to loop through all days you want to display. For each of the days, if data exists in the results array you previously created, display the data from the DB. Otherwise, the DB didn't return anything from that day, so output some empty placeholder and move on. Lather, rinse, repeat.
$query2 = "SELECT * FROM TOAWorkOrders WHERE TechNum = $TechNum AND WorkDate BETWEEN $StartDate AND $EndDate";
if (!$mysqli->query($query2)) {
print_r($mysqli->error_list);
}
else
{
echo 'the bear went over the mountain' . '<br><br>';
if ($result = $mysqli->query($query2))
{
while ($row = $result->fetch_assoc())
{
$BBT = $row['BBT'];
echo $BBT;
Also, in queries dates aren't numbers and need quotes.
Last edited by Weedpacket; 02-26-2013 at 04:32 PM.
Reason: reinserted a vital negation
Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail I'd rather be a comma, then a full stop. User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning
Also, in queries dates aren't numbers and need quotes.
Unless its actually an integer field storing a UNIX timestamp (though I really don't like doing that, myself, for whatever that's worth )?
Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett
"But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html
Y'all are majoring in minors and still haven't answered my question.
Either way I word the query, it doesn't work. If i use
PHP Code:
$query = "SELECT * FROM TOAWorkOrders WHERE TechNum = $TechNum AND `WorkDate` BETWEEN '$StartDate' AND '$EndDate'";
if ($result = $mysqli->query($query))
{
while ($row = $result->fetch_assoc())
{
$BBT = $row['BBT'];
echo $BBT . ' <br>';
}
You said earlier that your original code "dies after the first iteration". If you're not getting anything then it would seem that it's dying during the first iteration (of either loop).
Does "not getting anything" include not getting anything from the echo $Count . ' !! ' . $IncDate . '<br>'; line?
Have you verified that the query itself is correct, and not simply failing (i.e., perhaps $result is false - what then? The value of $mysqli->error would give MySQL's reason for failing such as, for example, unquoted non-numeric values.)
$query = "SELECT * FROM TOAWorkorders WHERE TechNum = $TechNum AND WorkDate = '$IncDate'";
if ($result = $mysqli->query($query))
{
printf("Select returned %d rows.\n", $result->num_rows);
$result->close();
}
}
I get:
Code:
0 yy 25842 qq Timothy qq Lear qq 5804307158
0 !! 2013-01-29 Select returned 5 rows.
1 !! 2013-01-30 Select returned 5 rows.
2 !! 2013-01-31 Select returned 4 rows.
3 !! 2013-02-01 Select returned 5 rows.
4 !! 2013-02-02 Select returned 0 rows.
5 !! 2013-02-03 Select returned 0 rows.
6 !! 2013-02-04 Select returned 5 rows.
old begins here
The query returns the expected result, but the loop dies at the query in the first iteration. Where did the numbers for Darron Kolb go?
Bookmarks