Skip to main content

PHP query does not return result



This query is not returning any result as there seems to be an issue with the sql.







$sql = "select region_description from $DB_Table where region_id='".$region_id."' and region_status =(1)";

$res = mysql_query($sql,$con) or die(mysql_error());

$result = "( ";

$row = mysql_fetch_array($res);

$result .= "\"" . $row["region_description"] . "\"";

while($row = mysql_fetch_array($res))

{

echo "<br /> In!";

$result .= " , \"" . $row["region_description"] . "\"";

}

$result .= " )";

mysql_close($con);

if ($result)

{

return $result;

}

else

{

return 0;

}







region_id is passed as 1.





I do have a record in the DB that fits the query criteria but no rows are returned when executed. I beleive the issue is in this part ,







region_id='".$region_id."'







so on using the gettype function in my php it turns out that the datatype of region_id is string not int and thus the failure of the query to function as my datatype in my tableis int. what would be the way to get parameter passed to be considered as an int in php. url below







GetRegions.php?region_id=1







Thanks


Comments

  1. Try it like this:

    $sql = "SELECT region_description FROM $DB_Table WHERE region_id = $region_id AND region_status = 1"

    The region_id column seems to be an integer type, don't compare it by using single quotes.

    ReplyDelete
  2. Try dropping the ; at the end of your query.

    ReplyDelete
  3. First of all - your code is very messy. You mix variables inside string with escaping string, integers should be passed without '. Try with:

    $sql = 'SELECT region_description FROM ' . $DB_Table . ' WHERE region_id = ' . $region_id . ' AND region_status = 1';


    Also ; should be removed.

    ReplyDelete
  4. try this

    $sql = "select region_description from $DB_Table where region_id=$region_id AND region_status = 1";

    When you are comparing the field of type integer, you should not use single quote

    Good Luck

    Update 1

    Use this.. It will work

    $sql = "select region_description from " .$DB_Table. " where region_id=" .$region_id. " AND region_status = 1";

    ReplyDelete
  5. Who are all these people?
    What is this site?
    Where am I?

    Five answers and every one of them telling the OP to remove things that has absolutely no effect on the query.

    Why to answer a question if you have no knowledge nor practical experience on the matter at all?

    ReplyDelete
  6. You do not need the single quotes around the region id i.e.

    $sql = "SELECT region_description FROM $DB_Table WHERE region_id = $region_id AND region_status = 1"

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex