Link to home
Start Free TrialLog in
Avatar of breeze351
breeze351

asked on

Php unexplained results form mysql query

I'm doing a query with php.  The data doesn't exist in the table but mysql_num_rows is returning a count of "1".  Here's the code in question:

// Build Sql query & execute
$Work = str_replace(" ","",$Street);
$SqlString1 = "SELECT * FROM saka WHERE HUH LIKE '$Work%'";
echo "$SqlString1 <br>";
$Saka_File = mysql_query($SqlString1);
$count = mysql_num_rows($Saka_File);

// If no street name
echo "count = $count <br>";

The query is correct.  I'm not sure what this could be.

Also, I'm not sure if this is the correct forum.   I have a login page which displays correctly in Firefox but not in IE.  If you would like to take a look it's "mrbreeze.net".

Thanks
Glenn
Avatar of EMB01
EMB01
Flag of United States of America image

I wouldn't use mysql_num_rows, I would use this:

if ($aka_File = mysql_query($SqlString1))

Ref.  http://stackoverflow.com/questions/3772791/mysql-num-rows-always-returns-1
Avatar of Dave Baldwin
Try putting a value in place of $Work in the SQL statement and see what happens.  I'm wondering if you ending up with a blank string that matches something in the database.

Your page looks the same in both IE8 and Firefox12.  But you haven't fixed the errors that were there the last time you posted.  So I fixed them for you.  I put the <form> tag where it belongs and fixed the image link.  And in the CSS I changed 'hissen' to 'hidden' like it should be.  You may find that those three fix your display problem.
mrbreeze.net.htm
lansco.css
Avatar of breeze351
breeze351

ASKER

I need to know the number of rows.  So you're solution doesn't work for me.
ASKER CERTIFIED SOLUTION
Avatar of EMB01
EMB01
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To EMB01:
I tried the code you suggested at the end of your message.  This is what I got!!:

SELECT * FROM saka WHERE HUH LIKE 'FRED%'
count = 1
result = FREDERICKDOUGLASSB

The table name saka stands for "Street Also Know As".   I can assure you that in Manhattan there is no "FREDERICKDOUGLAS..." in this table.   I have no idea where this data is coming from.  

To Ray:
Thanks for the lead.  My experience was using php with ODBC.  I have several sites using ODBC that are very similar to what I'm trying to do now.  How hard could be this be?  I already have the logic!  

Glenn
Saka-from-query-from-hosting24
The computer isn't just making up "FREDERICKDOUGLASSB" so it must be coming from somewhere.  There simply must be an entry in your database called "FREDERICKDOUGLASSB."  Have you checked?  Thanks.
Yes I did. Look at the attached print screen.
For some reason I can't open your file (Saka-from-query-from-hosting24).
See if this works better.
saka-query.doc
You should just attach a .GIF.  But, that worked.  So, from the image, "FREDERICKDOUGLASSB" was being returned from the query because it's in the database!  So, your query accurately returns one result (the correct result).  Let me know if I am misunderstanding you.
Using phpMyAdmin you can run any query you want in a "test mode" and see the results immediately.  It helps remove mysteries like this one!
No you have it right.  

I'm going to kill my partner on this deal.  He updates the data from the client and doesn't tell me (so you can tell the client's data sucks, as I said before there is no "Fred.." street in Manhattan).  I ran this query on Monday and there were no results.  I didn't even look at the new query because I assumed the data was the same.

I'm sorry for wasting your time.

Thanks
Glenn
I've requested that this question be closed as follows:

Accepted answer: 0 points for breeze351's comment #38003642

for the following reason:

My bad, didn't know someone else updated the data.
I recommend choosing a solution since, technically, the solution was reached.  Glad you found out what the problem was, after all.  Thanks.
@EMB01:
I recommend choosing a solution...
Yep!  Couldn't agree more.

And I recommend getting a copy of phpMyAdmin, installing it, and learning to use it frequently to look at the data.  It would have saved hours, if not days, on this problem.  And since everything we do in information technology is all about transforming data from one kind to another, it's not an overstatement to say that data visualization is the single most important thing a software developer can do.
3) Accept one or more Expert posts as the answer

ID#:  37994978