/    Sign up×
Community /Pin to ProfileBookmark

Error msg with queries, but displaying data correctly

I’m getting the following errors when I run the code below:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/adman4054/Public/auto_news/admin/statsCompanyURLredirects.php on line 39

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/adman4054/Public/auto_news/admin/statsCompanyURLredirects.php on line 46

Rows 39 and 46 are the 2 inner while loops with the first beginning

while($row = mysql_fetch_array($query2)) {
and the second beginning
while($row2 = mysql_fetch_array($query3)) {

I don’t understand why I am getting them because underneath the errors, the code displays all the correct data!

Can someone help me get rid of these errors and/or pinpoint what is causing them?

[CODE]

<?php
include(“../inc/conn.php”);

$query = mysql_query(“SELECT listingID, SUM(urlcount) from countslisting GROUP BY listingID ORDER BY SUM(urlcount) DESC”);

$num_rows=mysql_num_rows($query);

echo “<table width=’650′ align=’center’>”;
echo “<tr> <td width=’7′></td>”;
echo “<td width=’601′ align=’left’ valign=’top’ class=’bodyTxt’>”;

echo “<table>”;
echo “<tr><td class=’headerText’ align=’center’>Listing ID</td><td class=’headerText’>Company Name</td><td class=’headerText’ align=’center’>Total # of URL Redirects</td><td class=’headerText’ align=’center’>Today’s # of URL Redirects</td><tr>”;
//$exists = 0;
while($get = mysql_fetch_array($query)) {
$listingID = $get[‘listingID’];

//GET COMPANY NAME
$query2 = mysql_query(“SELECT listCompName FROM listing WHERE listingID = $listingID”);
[B]while($row = mysql_fetch_array($query2)) {[/B]
$companyName = $row[‘listCompName’];
}
//GET COUNT FOR TODAY
$today = date(“Y-m-d”);
$count=0;
$query3 = mysql_query(“SELECT SUM(urlcount) from countslisting WHERE listingID=$listingID AND listdate=’$today’ GROUP BY listingID”);
[B]while($row2 = mysql_fetch_array($query3)) {[/B]
$count= $row2[‘SUM(urlcount)’];
}

echo “<tr>”;
echo “<td class=’bodyTxt’ width=’150′ align=’center’ >”. $get[‘listingID’]. “</td>”;
echo “<td width=’350′ class=’bodyTxt’>”.$companyName.” </td>”;
echo “<td class=’bodyTxt’ width=’150′ align=’center’>”.number_format($get[‘SUM(urlcount)’],0).”</td>”;
echo “<td class=’bodyTxt’ width=’125′ align=’center’>”.$count.”</td>”;
echo “</tr>”;
}//end while
?>
</table>

[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMar 02.2009 — Make sure mysql_query finds a match before calling mysql_fetch_array.
[code=php]
<?php
//GET COMPANY NAME
$query2 = mysql_query("SELECT listCompName FROM listing WHERE listingID = $listingID");
$companyName = 'Not Found';
if(mysql_num_rows($query2))while($row = mysql_fetch_array($query2)) {
$companyName = $row['listCompName'];
}

//GET COUNT FOR TODAY
$today = date("Y-m-d");
$count=0;
$query3 = mysql_query("SELECT SUM(urlcount) from countslisting WHERE listingID=$listingID AND listdate='$today' GROUP BY listingID");
if(mysql_num_rows($query3))while($row2 = mysql_fetch_array($query3)) {
$count= $row2['SUM(urlcount)'];
}
?>
[/code]
×

Success!

Help @our5 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...