views:

473

answers:

3

What is the reason of the error on title? I tested mysql query at Mysql Front and no problem. My script is below. Thank you.

$fbFoodPerma = $fbSiteID."-".$fbFoodPerma;  
    $sql = mysql_query("  
        SELECT fbFoodPerma   
        FROM fbFoods   
        WHERE fbFoodPerma   
        LIKE '$fbFoodPerma'") or die(mysql_error());  
    $isStored = mysql_result($sql,0,"fbFoodPerma");  
    while ($isStored == "$fbFoodPerma") {  
    $fbFoodPerma = $fbFoodPerma."-";  
    $sql = mysql_query("  
        SELECT fbFoodPerma   
        FROM fbFoods   
        WHERE fbFoodPerma   
        LIKE '$fbFoodPerma'") or die(mysql_error());  
        $isStored = mysql_result($sql,0,"fbFoodPerma");  
        }  
A: 

looks like this query returned no rows.

Col. Shrapnel
I tested query on Mysql Front. It returns a row.
Ahmet Kemal
Also script was working for a month. It was returning this error rarely but stacked now.
Ahmet Kemal
@Ahmet you better get rid of this obsolete mysql_result function. use mysql_fetch_row/assoc instead. you have also very unusual logic in your code. I can't get it at all
Col. Shrapnel
A: 

Hmm, try this to see if it is picking up any data at all:

$sql="SELECT * FROM fbFoods";
$query = mysql_query($sql) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($query);

if ($num_rows > 0) {
    echo "rows found";
    } else {
    echo "none found";
}

Also make sure that $fbFoodPerma actually contains something - try echoing it at the end of your query.

echo $fbFoodPerma;

Tim
A: 

There's really lot's of weird stuff in that code. Are you absolutely positive this query even returns enough rows? Try to see if anything is returned with mysql_num_rows()-function.

And also you might wanna go for mysql_fetch_row() or mysql_fetch_assoc instead of mysql_result.

veturi
I think I should also explain why I am using this? This is just to generate a permalink. So I am checking whether permalink generated before or not. Is it wrong using mysql_result for that? And what is the difference between mysql_fetch_assoc and mysql_result?
Ahmet Kemal
`mysql_result()` lets you specify which row to retrieve, so you can in theory jump forward over multiple rows and cherry pick just the rows you want. `mysql_fetch_*()` will only retrieve the NEXT row available in the result set. Details here http://php.net/mysql_result and http://php.net/mysql_fetch_assoc
Marc B