0

Can anybody tell me what's wrong with the following code ---

for($i=0; $i<count($strnamearray); $i++){
echo $strnamearray[$i]."<br />";

$cordcquery = "SELECT `lat` , `lng` FROM `traffic` WHERE `strname` = '{$strnamearray[$i]}' LIMIT 0 , 30;";
$cordresult = mysql_query($cordcquery);

if (!$cordresult) 
 {
  die('Invalid strncquery: ' . mysql_error());
 }

while($cordrow = @mysql_fetch_assoc($cordresult)){
    echo $cordrow['lng'].",".$cordrow['lat'];
    echo "<br />";
}
}

Here $strnamearray[$i] is an array which contains some name. there is no error showed after executing this php code. But the problem is i am not getting my desired output...

3
  • 1
    Well, that's helpful. What is in the table? What is in the array? What is the output you are getting? Why are you using mysql in 2011 instead of mysqli or PDO and prepared statements? Are you so eager to get an SQL injection attack? Commented May 11, 2011 at 23:47
  • @chx: There is little strict advantage in using mysqli over mysql, just a change of interface. Not all code is OOP, nor should it always be. Commented May 14, 2011 at 17:20
  • First off, what does "$cordcquery" display? And can you run it manually? When I am dealing with SQL I always check that the query(ies) outputted can be entered on a command line or query window and run. Second, this may not be any consequence, but using "@" in front of a function suppresses error messages. Commented May 18, 2011 at 22:50

1 Answer 1

0

This is a shot in the dark here with out some more information but two things.

  1. echo $cordcquery just to make sure the sql looks right and you can execute it directly in MYSQL. From what I can tell it should but without knowing whats in the variables I'm not sure.

  2. Instead of LIMIT 0, 30 use just LIMIT 30. Should be the same thing but I have seen some funkiness depending on what versions of php and mysql you are using with passing LIMIT offset, row count. From what I can remember it would take the offset and not parse the row count and therefore would not return any information.

Let me know if this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.