Problem with where clause or ....??

Thread Solved

Join Date: Nov 2008
Posts: 2
Reputation: CodeMama is an unknown quantity at this point 
Solved Threads: 0
CodeMama's Avatar
CodeMama CodeMama is offline Offline
Newbie Poster

Problem with where clause or ....??

 
1
  #1
Nov 28th, 2008
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:
  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. /* }?> */
Thank For the Help and Clues!!
Terion
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

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

 
0
  #2
Nov 28th, 2008
Just use > instead of GREATER THAN. Since xCount is numeric, you also won't need quotes around it. So I think:
  1. $sql = "SELECT * FROM `textads` WHERE `expos` > xCount ORDER BY RAND() LIMIT 3";
should work.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

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

 
0
  #3
Nov 28th, 2008
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);

  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
  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.
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: CodeMama is an unknown quantity at this point 
Solved Threads: 0
CodeMama's Avatar
CodeMama CodeMama is offline Offline
Newbie Poster

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

 
0
  #4
Nov 28th, 2008
thank you thank you thank YOU!!!
Thank For the Help and Clues!!
Terion
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC