Hi All, I’m new to PHP and stumped by the results (or lack thereof) that I’m getting from a mysql_fetch_array when attempting to pull data from a MySQL table into an html table. Here is the part that’s puzzling me:
while ($p = mysql_fetch_array($result)) {
<td><? if ($p[‘service’] == ‘manualqotd_no_rev’) {
echo ‘Manual Conversions’;
}
else if (($p[‘points’] == 0) AND ($p[‘service’] != ‘manualqotd_no_rev’)) {
echo $p[‘network’];
}
else
echo $p[‘service’];?></td>
I’m seeing expected results for the final 2 statements, but the entries where $p[‘service’] == ‘manualqotd_no_rev’ are not displayed in the table, they are getting skipped! Is there a certain syntax I should use in order to echo text (instead of listing db results) when a particular db field (‘service’ in this case) contains a certain value ( ‘manualqotd_no_rev’ in this case)?
I’m sure this is a blatant mistake on my part - any help much appreciated. Thanks!
Thanks Steve, but no luck. I’m still getting the same results.
I am connecting to the db and pulling data from two tables that have overlapping data, like this:
$result = mysql_query(“SELECT nloppoints.points, nloppoints.service, nloppoints.posttime, redirects.network, redirects.name, redirects.value FROM nloppoints, redirects WHERE nloppoints.qotdid = redirects.qotdid AND nloppoints.posttime BETWEEN ‘$fromdate’ and ‘$todate’ ORDER BY nloppoints.posttime”);
The results are sent to a 4-column html table like this:
At the end of your line containing the while() statement you do not have an opening brace {.
Also you then don’t have a closing php tag before the <td>.
You’re either showing selected snips of code (which isn’t useful because the error could be somewhere else) or you simply haven’t coded it properly.
If you’re going to show selected snips of code you at least ensure that you have all the tags and braces in there to stop any confusion otherwise you will have people poking at various shadows for days. You’ll then get frustrated, members start trying to outsmart each other and then no-one gets anywhere.
Yeah that suggestion didn’t do the trick, Ryan. Thanks for the tip though.
Tango, I may have left out some code as I was just pasting snippets. Here it is in it’s entirety:
<?
$result = mysql_query(“SELECT nloppoints.points, nloppoints.service, nloppoints.posttime, redirects.network, redirects.name, redirects.value FROM nloppoints, redirects WHERE nloppoints.qotdid = redirects.qotdid AND nloppoints.posttime BETWEEN ‘$fromdate’ and ‘$todate’ ORDER BY nloppoints.posttime”);
$num_results = mysql_num_rows($result);
echo ‘Total Number of Conversions:’ . " " . $num_results;
?>
<br>
<?
Field Type Collation Attributes Null Default Extra Action
bpid int(11) No None AUTO_INCREMENT
uid int(11) No None
points int(11) No None
qotdid int(11) No None
posttime timestamp No CURRENT_TIMESTAMP
‘redirects’ contains the following fields:
Field Type Collation Attributes Null Default Extra Action
oid int(11) No None AUTO_INCREMENT
network varchar(255) utf8_unicode_ci No None
name varchar(255) utf8_unicode_ci No None
value int(11) No None
redirect varchar(255) utf8_unicode_ci No None
qotdid int(11) No None
created_date timestamp on update CURRENT_TIMESTAMP No CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Here is the query again:
$result = mysql_query(“SELECT nloppoints.points, nloppoints.service, nloppoints.posttime, redirects.network, redirects.name, redirects.value FROM nloppoints, redirects WHERE nloppoints.qotdid = redirects.qotdid AND nloppoints.posttime BETWEEN ‘$fromdate’ and ‘$todate’ ORDER BY nloppoints.posttime”);
In the query i’ve indicated that nloppoints.qotdid = redirects.qotdid. What the output should produce is a 4-column table listing:
the redirects.network name (which in some cases can be replaced by the nloppoints.service name)
The offer (redirects.name) name
The offer value, which depending on the value of nloppoints.service could be pulled from either nloppoints.points or redirects.value
The timestamp (nloppoints.posttime)
As I said before the results are all displayed as I expect, except in the instances when nloppoints.service=‘manualqotd_no_rev’. In these cases I want to override the associated db values for the corresponding qotdid with ‘Manual Conversions’ for (1.), ‘No Revenue Earned’ for (2.), ‘0’ for (3.), and keep the timestamp as is.
This must be possible, I just obviously don’t have a firm grasp on how to do it…