对mysql重复多次请求,如果id

ma8fv8wu  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(316)

这是我的代码,请帮助使它按数组(0100)循环 nav_tb_id 实际上,我有一个sql存储过程,需要使用不同的参数执行多次。然后换成两排
不过,我尝试了不同的方法,但没有结果:

<?php 
$nav01=mysql_query("SELECT * FROM nav_tb WHERE nav_tb_id = '1'");
$row_1=mysql_fetch_object($nav01);

    if ($_SESSION ['lang']==1){
       $nav_m_b_01=$row_1->RU;
    }elseif ($_SESSION ['lang']==2){
       $nav_m_b_01=$row_1->UA;
    }elseif ($_SESSION ['lang']==3){
       $nav_m_b_01=$row_1->EN;
    }

echo $nav_m_b_01; 

$nav02=mysql_query("SELECT * FROM nav_tb WHERE nav_tb_id = '2'");
$row_2=mysql_fetch_object($nav02);

    if ($_SESSION ['lang']==1){
       $nav_m_b_02=$row_2->RU;
    }elseif ($_SESSION ['lang']==2){
       $nav_m_b_02=$row_2->UA;
    }elseif ($_SESSION ['lang']==3){
       $nav_m_b_02=$row_2->EN;
    }

echo $nav_m_b_02; 

...
ovfsdjhp

ovfsdjhp1#

您也可以使用mysql查询来实现这一点,但我将继续您的php代码。您只需使用php do while构造来 Package 一个代码段:

$i = 0;
do {
    $nav=mysql_query("SELECT * FROM nav_tb WHERE nav_tb_id = $i");
    $row=mysql_fetch_object($nav);

    if ($_SESSION ['lang']==1){

        $nav_m_b_01=$row->RU;

    } elseif ($_SESSION ['lang']==2){

        $nav_m_b_01=$row->UA;

    } elseif ($_SESSION ['lang']==3){

        $nav_m_b_01=$row->EN;
    }

} while ($i < 100);

相关问题