Note that there are some explanatory texts on larger screens.

plurals
  1. POMySql - select two tables with different limit
    primarykey
    data
    text
    <p>I have two tables like this:</p> <p>om_manga:</p> <pre><code>id | link | manganame | viewed --------------------------------------------- 1 | naruto | naruto | 11215 2 | bleach | bleach | 32442 3 | one piece | one_piece | 11215 4 | gents | gents | 4334 </code></pre> <p>om_chapter:</p> <pre><code>id | manganame | chapter | volume ----------------------------------------- 1 | naruto | 1 | 1 2 | naruto | 12 | 1 3 | naruto | 22 | 1 4 | bleach | 10 | 1 5 | bleach | 15 | 1 6 | gents | 1 | 1 </code></pre> <p>What i want is to select, for example 10 rows form om_manga by order viewed and select 1 last row form om_chapter with equal manganame in two tables...</p> <p>What i want in query result is this:</p> <pre><code>id | manganame | viewed | chapter | volume ---------------------------------------------------- 1 | naruto | 14511 | 22 | 1 2 | bleach | 45151 | 15 | 1 </code></pre> <p>This is my PHP code:</p> <pre><code>$query = mysql_query("SELECT `link`,`cover`,`manganame` FROM `om_manga` WHERE `Active`='1' ORDER BY `viewed` DESC LIMIT ".$options['number_of_popular_manga']); // while($row = mysql_fetch_array($query)){ $rww = mysql_fetch_array(mysql_query("SELECT `chapter`,`volume`,`manganame` FROM `om_chapter` WHERE `manganame`='".sql_quote($row['link'])."' AND `Active`='1' ORDER BY `etime` DESC LIMIT 1")); // if (isset($rww['chapter'])) $volchap = '&lt;a href="read.php?manga='.$row['link'].'&amp;amp;chap='.$rww['chapter'].'"&gt;Vol.'.$rww['volume'].' CH.'.$rww['chapter'].'&lt;/a&gt;'; else $volchap = ''; echo '&lt;li class="index-right-ul-li"&gt;&lt;img onerror="this.src=\'images/noimage.jpg\'" src="images/info/'.$row['cover'].'" width="30" height="33"/&gt;&lt;div class="index-right-ul-div"&gt;&lt;p class="index-right-ul-div-tital"&gt;&lt;a href="manga.php?manga='.$row['link'].'"&gt;'.htmlspecialchars($row['manganame'], ENT_QUOTES).'&lt;/a&gt;&lt;/p&gt;&lt;p class="index-right-ul-div-chapter"&gt;'.$volchap.'&lt;/p&gt;&lt;/div&gt;&lt;/li&gt;'; } </code></pre> <p>I want to change this code in to one query instead two queries..</p> <p>How can I do that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload