 |
Results from the most recent live auction are here.
23 members in the live chat room. Join Chat!
| |
04-13-2006, 01:43 PM
|
· #1 | | Senior Member Name: TheMoose Location: on a oil rig just off Ireland Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 ( Donate)
| 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
__________________ 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. |
| |
04-13-2006, 02:01 PM
|
· #2 | | DNOA Member Location: Iowa Join Date: Jun 2004
Posts: 655
NP$: 13.10 ( Donate)
| whats the whole query?
__________________ Want to prove yourself? CHECK OUT MY DOMAINS! |
| |
04-13-2006, 02:05 PM
|
· #3 | | Steven Name: Steven Gibbons Location: United Kindom Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 ( Donate)
| I dont know, we would have to see the code! |
| |
04-13-2006, 07:04 PM
|
· #4 | | NamePros Regular Name: Derek Location: Seattle, Wa Join Date: Jul 2004
Posts: 597
NP$: 69.00 ( Donate)
| 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. |
| |
04-13-2006, 07:38 PM
|
· #5 | | Buy my domains. Name: Dan Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 ( Donate)
| 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.';
}
}
}
|
| |
04-13-2006, 08:58 PM
|
· #6 | | NamePros Member Name: Mattijs Naus Location: Hat Yai, Thailand Join Date: Jun 2005
Posts: 165
NP$: 104.00 ( Donate)
| 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 |
| |
04-13-2006, 09:10 PM
|
· #7 | | I'll do it Name: Keral. Patel. Location: India Join Date: Dec 2005
Posts: 5,716
NP$: 12478.15 ( Donate)
| well if you are finding it in phpmyadmin then just clikc the create php code link on the top and copy-paste it.  |
| |
04-14-2006, 01:54 AM
|
· #8 | | Senior Member Name: TheMoose Location: on a oil rig just off Ireland Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 ( Donate)
| 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. |
| |
04-14-2006, 02:27 AM
|
· #9 | | while ($awake){ code(); } Name: Eric Location: Kentucky Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 ( Donate)
| Your problem is quite simple: PHP Code: $num = mysql_numrows($result);
//Should be
$num = mysql_num_rows($result);
 |
| |
04-14-2006, 02:32 AM
|
· #10 | | Senior Member Name: TheMoose Location: on a oil rig just off Ireland Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 ( Donate)
| 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. |
| |
04-14-2006, 04:02 AM
|
· #11 | | Law and disorder Name: Kate Location: Expat Join Date: Aug 2005
Posts: 5,481
NP$: 1585.11 ( Donate)
| 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 ? |
| |
04-14-2006, 05:01 AM
|
· #12 | | Senior Member Name: TheMoose Location: on a oil rig just off Ireland Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 ( Donate)
| 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. |
| |
04-14-2006, 08:16 AM
|
· #13 | | Senior Member Name: Chong Xie Location: Hong Kong Join Date: Nov 2005
Posts: 1,150
NP$: 2507.40 ( Donate)
| 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-------------|
----------------------------------------------------- |
| |
04-14-2006, 09:04 AM
|
· #14 | | NamePros Regular Name: 'Flubb' Location: Swindon, UK Join Date: Jun 2005 | 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 |
| |
04-14-2006, 09:24 AM
|
· #15 | | Buy my domains. Name: Dan Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 ( Donate)
| If sdsinc is right, you need to change the name of it from string to something else. |
| |
04-14-2006, 10:31 AM
|
· #16 | | NamePros Regular Name: Trevor Location: Atlanta, GA, USA Join Date: Feb 2006 | |
| |
04-14-2006, 10:41 AM
|
· #17 | | Senior Member Name: TheMoose Location: on a oil rig just off Ireland Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 ( Donate)
| 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. |
| |
04-14-2006, 11:08 AM
|
· #18 | | Buy my domains. Name: Dan Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 ( Donate)
| 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.. |
| |
04-14-2006, 11:22 AM
|
· #19 | | Senior Member Name: TheMoose Location: on a oil rig just off Ireland Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 ( Donate)
| 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. |
| |
04-14-2006, 11:28 AM
|
· #20 | | Buy my domains. Name: Dan Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 ( Donate)
| I think I know what it is.
Replace
$query = "SELECT * FROM `table` WHERE strng = '".$q."'";
With
$query = "SELECT * FROM table WHERE string = '$q'"; |
| |
04-14-2006, 11:35 AM
|
· #21 | | Senior Member Name: TheMoose Location: on a oil rig just off Ireland Join Date: Nov 2005
Posts: 1,409
NP$: 374.65 ( Donate)
| 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. |
| |
04-14-2006, 11:39 AM
|
· #22 | | while ($awake){ code(); } Name: Eric Location: Kentucky Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 ( Donate)
| Like many have mentioned, echo $query and paste it here. |
| |
04-14-2006, 11:57 AM
|
· #23 | | DNOA Member Location: Iowa Join Date: Jun 2004
Posts: 655
NP$: 13.10 ( Donate)
| escape the $ sign
__________________ Want to prove yourself? CHECK OUT MY DOMAINS! |
| |
04-14-2006, 12:05 PM
|
· #24 | | Buy my domains. | |