Hi, I'm a newbie and am having a problem with either my where clause in my sql statement or something else, I think its the where because if I take that out the script works fine...
Here is the error I get:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\NewBeginnings\jobsOutput.php on line 12
Here is the code:

<?php  include 'inc/dbconnOpen.php';
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);

 $sql = "SELECT * FROM `textads` WHERE `expos` GREATER THAN `xCount` ORDER BY RAND() LIMIT 3"; 
$result = mysql_query($sql);

echo "<b><center>Database Output</center></b><br><br>
<table border= 1 height=90px width=468px bgcolor=#cccccc>

while ($row = mysql_fetch_array($result)) {
    echo "
    <A HREF='{$row['href']}'>{$row['href']}</a></td>";
    //Add to exposure count
    $views = $row['xCount'] + 1;
    mysql_query("UPDATE `textads` SET `xCount` = '{$views}' WHERE `ID` = '{$row['ID']}'");

echo " </tr>

/* $num=mysql_num_rows($result);


echo "<b><center>Database Output</center></b><br><br>";

while ($i < $num) {


echo "<table border= 1 height=90px width=468px bgcolor=#0066CC><tr><td>$title<br>$blurb<br>
<A HREF='$href'>$href</a></td><td>$title<br>$blurb<br>
<A HREF='$href'>$href</a></td><td>$title<br>$blurb<br>
<A HREF='$href'>$href</a></td></tr></table>";

$i++; */

/* }?> */
peter_budo commented: Nice to see person using code tags on very first post. Thank you! +12

Just use > instead of GREATER THAN. Since xCount is numeric, you also won't need quotes around it. So I think:

$sql = "SELECT * FROM `textads` WHERE `expos` > xCount ORDER BY RAND() LIMIT 3";

should work.

Member Avatar for Rhyan

Ok, the error says that no result has been returned from sql. This may be caused either by no data in tables or by a wrong sql statement.
I suggest you to put this line just after $result=mysql_query($sql);

if (!$result)
die mysql_error();

If this does not return an error, then your tables are empty, or your sql is valid, but returns no records.
I think that you need to revise your sql statement though.
I don't really get the idea of this statement


First of all, I would remove the useless quotes around the column names and table name.
Then - greater than, you can just use '>' sign.
Next, what do you mean by setting an ordering which uses RAND() function - you want to randomize your results or what?
And last - LIMIT 3 - the limit clause normally should be used like
Limit "# of records to omit, # of records to return". So if you want to see only the first 3 records only, LIMIT 0,3 should be used instead.

thank you thank you thank YOU!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.