douzhantanju1849 2015-03-25 05:16
浏览 56

如何在循环中比较2表

I have this code and i want to display genres table (ID, name) from my database with checkboxes and this works. Then i want to put old values from genres that become from another book_genre(ID,ID_book, ID_genre) table where i keep ids old and this didn't work. In that while i put all genres from my table and then in that input i want to check where is my old genre from my book_genre table and this not work because my loop through 4 times in genres (1.Action, 2. Thriller, SF, Comedy) and in the book_genre he found 2 values (2,3). At first loop check 1Action with 2 and i want to check 1 Action but without nothing from book_genre and i don't know how... .

                $id_book = $_GET['id'];

                $qr_genres_old = 'SELECT genres.name,book_genre.ID_genre,book_genre.ID
                                        FROM genres
                                        INNER JOIN book_genre
                                        ON book_genre.ID_genre = genres.ID
                                        WHERE ID_book = "'. $id_book .'"
                                        ORDER BY ID_genre ASC';
                 $res_genre_old = mysql_query($qr_genres_old);


                 $qr_select_genres = 'SELECT * FROM genres';
                 $res_select_genre = mysql_query($qr_select_genres);


    while( $row_genre_new = mysql_fetch_assoc($res_select_genre) ){ 
                         $row_genre_old = mysql_fetch_assoc($res_genre_old); 

                        ?>

                    <div>
                        <input type="checkbox" name="ID_gen<? echo $id=$row_genre_new['ID']; ?>" 
                                value="1" <? if($row_genre_old['ID_genre']==$row_genre_new['ID'] ) echo 'checked="checked"';  ?> />
                        <? echo $row_genre_new['name']; ?>
                    </div>  
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
    • ¥15 Python报错怎么解决
    • ¥15 simulink如何调用DLL文件
    • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
    • ¥30 线性代数的问题,我真的忘了线代的知识了
    • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
    • ¥188 需要修改一个工具,懂得汇编的人来。
    • ¥15 livecharts wpf piechart 属性
    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了