943,638 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 598
  • PHP RSS
Nov 28th, 2008
1

Problem with where clause or ....??

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php include 'inc/dbconnOpen.php';
  2. ini_set('error_reporting', E_ALL);
  3. ini_set('display_errors', true);
  4.  
  5. $sql = "SELECT * FROM `textads` WHERE `expos` GREATER THAN `xCount` ORDER BY RAND() LIMIT 3";
  6. $result = mysql_query($sql);
  7.  
  8. echo "<b><center>Database Output</center></b><br><br>
  9. <table border= 1 height=90px width=468px bgcolor=#cccccc>
  10. <tr>";
  11.  
  12. while ($row = mysql_fetch_array($result)) {
  13. echo "
  14. <td>{$row['title']}<br>{$row['blurb']}<br>
  15. <A HREF='{$row['href']}'>{$row['href']}</a></td>";
  16. //Add to exposure count
  17. $views = $row['xCount'] + 1;
  18. mysql_query("UPDATE `textads` SET `xCount` = '{$views}' WHERE `ID` = '{$row['ID']}'");
  19. }
  20.  
  21. echo " </tr>
  22. </table>";
  23.  
  24. /* $num=mysql_num_rows($result);
  25.  
  26. mysql_close();
  27.  
  28. echo "<b><center>Database Output</center></b><br><br>";
  29.  
  30. $i=0;
  31. while ($i < $num) {
  32.  
  33. $href=mysql_result($result,$i,"href");
  34. $blurb=mysql_result($result,$i,"blurb");
  35. $title=mysql_result($result,$i,"title");
  36.  
  37.  
  38. echo "<table border= 1 height=90px width=468px bgcolor=#0066CC><tr><td>$title<br>$blurb<br>
  39. <A HREF='$href'>$href</a></td><td>$title<br>$blurb<br>
  40. <A HREF='$href'>$href</a></td><td>$title<br>$blurb<br>
  41. <A HREF='$href'>$href</a></td></tr></table>";
  42.  
  43. $i++; */
  44.  
  45. /* }?> */
Similar Threads
Reputation Points: 22
Solved Threads: 0
Newbie Poster
CodeMama is offline Offline
2 posts
since Nov 2008
Nov 28th, 2008
0

Re: Problem with where clause or ....??

Just use > instead of GREATER THAN. Since xCount is numeric, you also won't need quotes around it. So I think:
php Syntax (Toggle Plain Text)
  1. $sql = "SELECT * FROM `textads` WHERE `expos` > xCount ORDER BY RAND() LIMIT 3";
should work.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Nov 28th, 2008
0

Re: Problem with where clause or ....??

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);

PHP Syntax (Toggle Plain Text)
  1. if (!$result)
  2. {
  3. die mysql_error();
  4. }
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
PHP Syntax (Toggle Plain Text)
  1. SELECT * FROM `textads` WHERE `expos` GREATER THAN `xCount` ORDER BY RAND() LIMIT 3
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.
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Nov 28th, 2008
0

Re: Problem with where clause or ....??

thank you thank you thank YOU!!!
Reputation Points: 22
Solved Threads: 0
Newbie Poster
CodeMama is offline Offline
2 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP session problem
Next Thread in PHP Forum Timeline: Dynamic form from database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC