drsb77336 2016-11-03 14:45
浏览 40

排序mysql控制台输出和mysql_fetch_array之间的差异

I setup up a mysql chemistry database using the mychem cartridge. I use the JSME javascript module by Peter Ertl to draw molecules and feed the molecular 'smiles' string to build the mysql query.

When I type my request in the mysql console, I get the results in the correct order, sorted on the column tan.

When I send the query through php to the mysql database using :

$db = mysql_connect('localhost', '****', '****') or die ('Unable to connect');
mysql_select_db('mychem', $db)  or die(mysql_error($db));
$query = "SET @fp = (SELECT FINGERPRINT2(SMILES_TO_MOLECULE('".$_POST['smiles']."')))";
$results = mysql_query($query, $db) or die(mysql_error($db));

$query = "SELECT No, Name from (SELECT No, Name, tan from (SELECT No, Name, TANIMOTO(@fp, fin) as tan FROM (SELECT compounds.name as No, pdt.fullname as Name, bin_structures.fp2 as fin  From pdt,compounds,bin_structures WHERE pdt.name=compounds.name AND compounds.id=bin_structures.compound_id AND MATCH_SUBSTRUCT('".$_POST['smiles']."',obserialized)) x order by tan DESC) y)z";

$results = mysql_query($query, $db) or die(mysql_error($db));

php code to populate the table :

while ($row = mysql_fetch_assoc($results)) {
echo "<tr>";
echo '<td><a href="info.php?name='.$row["No"].'">'.$row["No"].'</a></td><td>'.$row["Name"]./*'</td><td>'.$tan.*/'</td><td><img src ="structures/'.$row["No"].'.png" height="150"></td>';
echo "</tr>";
}
mysql_free_result($results); ?>

then I get the results sorted on the name column.

Do you have an idea of what I am doing wrong ?

I added an echo statement for print out my query. I used that query in the mysql console and I get the results in the correct order though.

Thank you for your inputs

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看