[advanced search]
Results from the most recent live auction are here.
23 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Closed Thread
 
Thread Tools
Old 04-13-2006, 01:43 PM   · #1
tm
Senior Member
 
tm's Avatar
 
Name: TheMoose
Location: on a oil rig just off Ireland
Trader Rating: (24)
Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 (Donate)
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
What the **** is up with my script?!?

Hey,

Im trying to find a string in a database.

I KNOW the string is there, i can find it easily in phpmyadmin.

I'm DEFINATELY connecting to the database, otherwise the script would die().

I've checked that everything is spelled correctly.

so WHY is it returning 0 numrows?!? There's definately a good two or three in the database (WHERE string='$q').

I've turned on error reporting
error_reporting(E_ALL);
but nothings coming up.

Me and several other people are STUMPED, so I need help!

thanks,

tm


Please register or log-in into NamePros to hide ads
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline   Reply With Quote
Old 04-13-2006, 02:01 PM   · #2
ninedogger
DNOA Member
 
ninedogger's Avatar
 
Location: Iowa
Trader Rating: (38)
Join Date: Jun 2004
Posts: 655
NP$: 13.10 (Donate)
ninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of light
Save The Children
whats the whole query?
__________________
Want to prove yourself?

CHECK OUT MY DOMAINS!
ninedogger is offline  
  Reply With Quote
Old 04-13-2006, 02:05 PM   · #3
Xyzer
Steven
 
Xyzer's Avatar
 
Name: Steven Gibbons
Location: United Kindom
Trader Rating: (45)
Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 (Donate)
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
Tsunami Relief AIDS/HIV
I dont know, we would have to see the code!
Xyzer is offline   Reply With Quote
Old 04-13-2006, 07:04 PM   · #4
Palyriot
NamePros Regular
 
Palyriot's Avatar
 
Name: Derek
Location: Seattle, Wa
Trader Rating: (14)
Join Date: Jul 2004
Posts: 597
NP$: 69.00 (Donate)
Palyriot is a jewel in the roughPalyriot is a jewel in the roughPalyriot is a jewel in the rough
use echo $q to make sure that $q isn't blank or something like that. Just check the small things. Also, instead of using $q, try an actual word instead of a variable. Will show you if it's a problem in the variable. Sorry if this doesn't help, but I tried.
Palyriot is offline   Reply With Quote
Old 04-13-2006, 07:38 PM   · #5
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 (Donate)
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
Autism Autism Autism Autism Autism Autism Autism
If the row has more than just $q in it, that won't work.

Use:

PHP Code:
$query = "SELECT * FROM table";
$result = mysql_query($query);
if (
mysql_num_rows($result) == 0) {
     echo
'No results.';
} else {
     while (
$row = mysql_fetch_assoc($result) {
          if (
eregi($q, $row['string'])) {
               echo
'I don\'t know what you want it to write.. so edit this.';
          }
     }
}
Dan is offline   Reply With Quote
Old 04-13-2006, 08:58 PM   · #6
monty
NamePros Member
 
monty's Avatar
 
Name: Mattijs Naus
Location: Hat Yai, Thailand
Trader Rating: (0)
Join Date: Jun 2005
Posts: 165
NP$: 104.00 (Donate)
monty is an unknown quantity at this point
What I always do in a situation like yours, I just echo the query and run the same query in phpMyAdmin. Then you usually find out in a couple of seconds what's wrong with the original query.

If you don't give us your code/query, there's not much else we can do.

best of luck!

-monty
monty is offline   Reply With Quote
Old 04-13-2006, 09:10 PM   · #7
-Nick-
I'll do it
 
-Nick-'s Avatar
 
Name: Keral. Patel.
Location: India
Trader Rating: (100)
Join Date: Dec 2005
Posts: 5,716
NP$: 12478.15 (Donate)
-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute
Member of the Month
September 2007 Adoption
well if you are finding it in phpmyadmin then just clikc the create php code link on the top and copy-paste it.
__________________
-Nick- is offline   Reply With Quote
Old 04-14-2006, 01:54 AM   · #8
tm
Senior Member
 
tm's Avatar
 
Name: TheMoose
Location: on a oil rig just off Ireland
Trader Rating: (24)
Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 (Donate)
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
Here is the code:

$query = "SELECT * FROM `table` WHERE string = '$q'";
$result = mysql_query($query) or die("Query failed 2: " . mysql_error());
$num = mysql_numrows($result);


there is nothing else in that table part other than $q (not even spaces).

I do die($q) and it echoes the string.
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline   Reply With Quote
Old 04-14-2006, 02:27 AM   · #9
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (142)
Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
Your problem is quite simple:
PHP Code:
$num = mysql_numrows($result);

//Should be

$num = mysql_num_rows($result);

__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.3 now available!!
SecondVersion is offline   Reply With Quote
Old 04-14-2006, 02:32 AM   · #10
tm
Senior Member
 
tm's Avatar
 
Name: TheMoose
Location: on a oil rig just off Ireland
Trader Rating: (24)
Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 (Donate)
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
Still doesnt work.. :S
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline   Reply With Quote
Old 04-14-2006, 04:02 AM   · #11
sdsinc
Law and disorder
 
sdsinc's Avatar
 
Name: Kate
Location: Expat
Trader Rating: (57)
Join Date: Aug 2005
Posts: 5,481
NP$: 1585.11 (Donate)
sdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond reputesdsinc has a reputation beyond repute
Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV
So you have a field called 'string' in your table ?
Isn't it a reserved keyword ? Be careful when using reserved keyword in field names as this can lead to unpredictable results.
Did you try your query in phpmyadmin ?
sdsinc is offline   Reply With Quote
Old 04-14-2006, 05:01 AM   · #12
tm
Senior Member
 
tm's Avatar
 
Name: TheMoose
Location: on a oil rig just off Ireland
Trader Rating: (24)
Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 (Donate)
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
Yes string is in the table.

Whats a reserved keyword? :s

Query in phpmyadmin returns:
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0248 sec)
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline   Reply With Quote
Old 04-14-2006, 08:16 AM   · #13
aznchong91
Senior Member
 
Name: Chong Xie
Location: Hong Kong
Trader Rating: (10)
Join Date: Nov 2005
Posts: 1,150
NP$: 2507.40 (Donate)
aznchong91 is a jewel in the roughaznchong91 is a jewel in the roughaznchong91 is a jewel in the rough
then there is something wrong with the query. Can you echo the query and paste it here?
__________________
-----------------------------------------------------
|-----FREE BANNER EXCHANGE! 1:1 RATIO!!!!-----|
|-------------www.bannercenter.info-------------|
-----------------------------------------------------
aznchong91 is offline   Reply With Quote
Old 04-14-2006, 09:04 AM   · #14
Flubber
NamePros Regular
 
Flubber's Avatar
 
Name: 'Flubb'
Location: Swindon, UK
Trader Rating: (49)
Join Date: Jun 2005
Posts: 691
NP$: 0.95 (Donate)
Flubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to beholdFlubber is a splendid one to behold
Baby Health
Try the following.

PHP Code:
$query = "SELECT * FROM `table` WHERE string = ".$q."";
$result = mysql_query($query) or die("Query failed 2: " . mysql_error());
$num = mysql_num_rows($result);

//Debugging if it doesnt work,
echo "The Query Is ".$query."";


Run the query in phpmyadmin, and see what happens.

Flubb
Flubber is offline   Reply With Quote
Old 04-14-2006, 09:24 AM   · #15
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 (Donate)
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
Autism Autism Autism Autism Autism Autism Autism
If sdsinc is right, you need to change the name of it from string to something else.
Dan is offline   Reply With Quote
Old 04-14-2006, 10:31 AM   · #16
Tree
NamePros Regular
 
Tree's Avatar
 
Name: Trevor
Location: Atlanta, GA, USA
Trader Rating: (3)
Join Date: Feb 2006
Posts: 334
NP$: 0.00 (Donate)
Tree will become famous soon enoughTree will become famous soon enough
MySQL Manuel entry for reserved words.
__________________
NCIDev.com
Tree is offline   Reply With Quote
Old 04-14-2006, 10:41 AM   · #17
tm
Senior Member
 
tm's Avatar
 
Name: TheMoose
Location: on a oil rig just off Ireland
Trader Rating: (24)
Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 (Donate)
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
It's not actually string.. sorry for confusion, its actually a different (non-reserved) word.

Flubber, i changed the query to that and it still doesnt work... not sure where you're supposed to run php in phpmyadmin though :S
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline   Reply With Quote
Old 04-14-2006, 11:08 AM   · #18
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 (Donate)
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
Autism Autism Autism Autism Autism Autism Autism
PHP Code:
$query = "SELECT * FROM table";
$result = mysql_query($query);
if (
mysql_num_rows($result) == 0) {
     echo
'No results.';
} else {
     
$i = 0;
     while (
$row = mysql_fetch_assoc($result) {
          if (
eregi($q, $row['string'])) {
               
$i++;
          }
     }
}


Then $i will be the total number.. you shouldn't have to do this except you won't tell us the full code, or even the name of the row..
Dan is offline   Reply With Quote
Old 04-14-2006, 11:22 AM   · #19
tm
Senior Member
 
tm's Avatar
 
Name: TheMoose
Location: on a oil rig just off Ireland
Trader Rating: (24)
Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 (Donate)
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
OK here's basically the code i have atm:

Code:
$query = "SELECT * FROM `table` WHERE strng = '".$q."'"; $result = mysql_query($query) or die("Query failed 2: " . mysql_error()); $num = mysql_num_rows($result); if($num == 0) { echo "<B>$q</B><UL><LI>No result(s) found.</LI>"; echo "</UL>"; } else { echo "<B>$q</B>"; echo "<UL>"; $i = 0; while ($i < $num) { $desc = mysql_result($result,$i,"desc"); echo "<li>$desc</li>"; $i++; } echo "</UL>"; }


It always echoes:

$q (eg A)
No Results Found

even though $q is DEFINATELY in the database
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline   Reply With Quote
Old 04-14-2006, 11:28 AM   · #20
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 (Donate)
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
Autism Autism Autism Autism Autism Autism Autism
I think I know what it is.

Replace
$query = "SELECT * FROM `table` WHERE strng = '".$q."'";
With
$query = "SELECT * FROM table WHERE string = '$q'";
Dan is offline   Reply With Quote
Old 04-14-2006, 11:35 AM   · #21
tm
Senior Member
 
tm's Avatar
 
Name: TheMoose
Location: on a oil rig just off Ireland
Trader Rating: (24)
Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 (Donate)
tm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of lighttm is a glorious beacon of light
Still no..
__________________
You design in photoshop, I code into valid XHTML/CSS.
Professional PSD, PNG or HTML to tableless XHTML/CSS designs.
For more info, send me a PM.
tm is offline   Reply With Quote
Old 04-14-2006, 11:39 AM   · #22
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (142)
Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
Like many have mentioned, echo $query and paste it here.
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.3 now available!!
SecondVersion is offline   Reply With Quote
Old 04-14-2006, 11:57 AM   · #23
ninedogger
DNOA Member
 
ninedogger's Avatar
 
Location: Iowa
Trader Rating: (38)
Join Date: Jun 2004
Posts: 655
NP$: 13.10 (Donate)
ninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of light
Save The Children
escape the $ sign
__________________
Want to prove yourself?

CHECK OUT MY DOMAINS!
ninedogger is offline  
  Reply With Quote
Old 04-14-2006, 12:05 PM   · #24
Dan
Buy my domains.