MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old December 14th, 2004, 06:36 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
supplied argument is not a valid MySQL result resource

ERROR: supplied argument is not a valid MySQL result resource

Refers to this code:

$date=mysql_result ($result,$i,"date");

The MySQL version on my server is 4.0.22-standard-log



Reply With Quote
  #2  
Old December 14th, 2004, 09:30 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
The mysql_query() that's supposed to populate $result is failing for some reason, probably either a connection issue or a syntax error. You can add an 'or die(mysql_error())' to the end of you query call to get a more informative error message. Also double-check your query string, especially if you're using variables in it.

Reply With Quote
  #3  
Old December 14th, 2004, 10:23 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
Quote:
Originally Posted by Madpawn
The mysql_query() that's supposed to populate $result is failing for some reason, probably either a connection issue or a syntax error. You can add an 'or die(mysql_error())' to the end of you query call to get a more informative error message. Also double-check your query string, especially if you're using variables in it.

Here is the full error message:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/jwgmgcom/public_html/index_data.php on line 29


And here is the complete code, except for the html part.

<?php
include
("dbinfo.inc.php");

$query
= "SELECT * FROM programs WHERE field='date' ORDER BY date DESC('$date','$progname','$progurl','$joinbonus','$reflevels','$earnratio','$surftimer','$allowurls')or die(mysql_error())";
$result
=mysql_query($query);

$i
=0;
while($i < $num)
$num
=mysql_numrows($result);
{

$date
=mysql_result($result,$i,"date");
$progname
=mysql_result($result,$i,"progname");
$progurl
=mysql_result($result,$i,"progurl");
$joinbonus
=mysql_result($result,$i,"joinbonus");
$reflevels
=mysql_result($result,$i,"reflevels");
$earnratio
=mysql_result($result,$i,"earnratio");
$surftimer
=mysql_result($result,$i,"surftimer");
$allowurls
=mysql_result($result,$i,"allowurls");
?>


Reply With Quote
  #4  
Old December 15th, 2004, 06:53 AM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
Quote:
Originally Posted by mlmpros
Here is the full error message:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/jwgmgcom/public_html/index_data.php on line 29


And here is the complete code, except for the html part.

<?php
include
("dbinfo.inc.php");

$query
= "SELECT * FROM programs WHERE field='date' ORDER BY date DESC('$date','$progname','$progurl','$joinbonus','$reflevels','$earnratio','$surftimer','$allowurls')or die(mysql_error())";
$result
=mysql_query($query);

$i
=0;
while($i < $num)
$num
=mysql_numrows($result);
{

$date
=mysql_result($result,$i,"date");
$progname
=mysql_result($result,$i,"progname");
$progurl
=mysql_result($result,$i,"progurl");
$joinbonus
=mysql_result($result,$i,"joinbonus");
$reflevels
=mysql_result($result,$i,"reflevels");
$earnratio
=mysql_result($result,$i,"earnratio");
$surftimer
=mysql_result($result,$i,"surftimer");
$allowurls
=mysql_result($result,$i,"allowurls");
?>


You were right. My query syntax was in error. The script works just fine now.

However, I wish to select only records that have data in the date field. How do I do that?

The current correct query syntax is:
$query
="SELECT * FROM programs ORDER BY date DESC";


Reply With Quote
  #5  
Old December 15th, 2004, 05:27 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Actually, the or die() call needs to go after the '$result=mysql_query()' line, not the '$query=' line.

Depending on what sort of default you've got your date field set to, this may work:

Code:
 SELECT
  *
 FROM
  programs
 WHERE
  date != ''
 ORDER BY
  date
   DESC
 

Reply With Quote
  #6  
Old December 15th, 2004, 05:36 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
Quote:
Originally Posted by Madpawn
Actually, the or die() call needs to go after the '$result=mysql_query()' line, not the '$query=' line.

Depending on what sort of default you've got your date field set to, this may work:

Code:
SELECT
*
FROM
programs
WHERE
date != ''
ORDER BY
date
DESC

Already moved the or die(). And here's the new $query and $result:
$query="SELECT * FROM programs WHERE date LIKE '1%' ORDER BY date DESC";
$result
=mysql_query($query)or die(mysql_error());
Thanks for your help!






Reply With Quote
  #7  
Old December 15th, 2004, 05:44 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Will your date data always start with a 1?

Reply With Quote
  #8  
Old December 15th, 2004, 07:19 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
Quote:
Originally Posted by Madpawn
Will your date data always start with a 1?

Nope. Date format is dd/mm. Will your example work with that?

Reply With Quote
  #9  
Old December 15th, 2004, 08:58 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Depends on what that field's supposed to default to. If it defaults to empty, it should. If that doesn't work, you can also try WHERE date IS NOT NULL instead of WHERE date != ''.

Reply With Quote
  #10  
Old December 15th, 2004, 09:20 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
Quote:
Originally Posted by Madpawn
Depends on what that field's supposed to default to. If it defaults to empty, it should. If that doesn't work, you can also try WHERE date IS NOT NULL instead of WHERE date != ''.

It works like it is, but I'll save this info in case there is a problem down the line.

On to the next issue, numerical items.

Some of the programs start with a number like 01likeit. I want all those programs listed on one page. Will this do the trick?
$query="SELECT * FROM programs WHERE progname REGEXP '^[^A-Za-z]' ORDER BY progname ASC";


Reply With Quote
  #11  
Old December 15th, 2004, 09:43 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
I'd probably try something like

WHERE progname REGEXP '^[0-9]'

instead. That'll guarantee a numeral.

Reply With Quote
  #12  
Old December 15th, 2004, 09:58 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
Quote:
Originally Posted by Madpawn
I'd probably try something like

WHERE progname REGEXP '^[0-9]'

instead. That'll guarantee a numeral.
Excellent

If I use WHERE progname LIKE 'C%'will that return
all entries beginning with the letter c, or just those
that begin with an uppercase c?

Reply With Quote
  #13  
Old December 23rd, 2004, 12:25 AM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
Using this query

$query="SELECT * FROM programs WHERE progname REGEXP '^[0-9]' ORDER BY progname ASC";

how can I exclude data from the query?

What I want to exclude is data with the entries AE and BE in the CODE field.

In other words, all records 0-9 that do not have AE or BE in the code field.

Reply With Quote
  #14  
Old December 23rd, 2004, 08:23 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
My MySQL skills are a bit rusty, but I think this works:

Code:
SELECT * 
FROM programs 
WHERE progname REGEXP '^[0-9]' 
AND code NOT LIKE '%AE%'
AND code NOT LIKE '%BE%'
ORDER BY progname ASC";


Keeping up with Regular Expressions... you could try:
Code:
SELECT * 
FROM programs 
WHERE progname REGEXP '^[0-9]' 
AND code NOT REGEXP '(AE|ae|BE|be)'
ORDER BY progname ASC";


Then again, my regular exression skills are even rustier than my mysql skills. =)

Let me know if either of these work

Reply With Quote
  #15  
Old December 23rd, 2004, 03:05 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 31 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 51 sec
Reputation Power: 4
Quote:
Originally Posted by MadCowDzz
My MySQL skills are a bit rusty, but I think this works:

Code:
SELECT * 
FROM programs 
WHERE progname REGEXP '^[0-9]' 
AND code NOT LIKE '%AE%'
AND code NOT LIKE '%BE%'
ORDER BY progname ASC";


Keeping up with Regular Expressions... you could try:
Code: