Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Select Statements
    primarykey
    data
    text
    <p>I am trying to create a list of items in which every fourth item in the list is an item that is on from New York and On Sale. The rest of the items in the list are the items that are from New York no matter if they are on sale or not. </p> <p>How can I properly use two select statements to break the list up into the order that I want? Below is what I'm using now. It creates a list of paragraphs but does not understand what the variables <code>$article</code> and <code>$article2</code> are.</p> <pre><code>&lt;ul&gt; &lt;? $sort = id; $sql = "SELECT * FROM `Catalog` WHERE state = 'New York' and in_stock = 'yes' ORDER BY $sort"; $result = mysql_query($sql); $sql2 = "SELECT * FROM `Catalog` WHERE state = 'New York' and sale_item = 'yes' ORDER BY $sort "; $result2 = mysql_query($sql2); $i = 0; while ( $article = mysql_fetch_array($result) || $article2 = mysql_fetch_array($result2) ) { if ($i == 0) { echo '&lt;li&gt;This item number is on sale:'.article2[id]. '&lt;/li&gt;'; $i++; } else if ($i == 3) { echo '&lt;li&gt;This item number is regular price'.article[id]. '&lt;/li&gt;'; $i = 0; } else { echo '&lt;li&gt;This item number is regular price'.article[id].'&lt;/li&gt;'; $i++; } } ?&gt; &lt;/ul&gt; </code></pre> <p>Based on Dave's suggestion I'm trying it this way. But php still doesn't know how to interpret $itemsOnSale or $items.</p> <pre><code>&lt;ul&gt; &lt;? $items = array(); $itemsOnSale = array(); $sql = "SELECT * FROM `Catalog` WHERE state = 'New York' AND in_stock = 'yes' ORDER BY $sort"; $result = mysql_query($sql); while ( $row = mysql_fetch_assoc($result) ) { if ( $row['sale_item'] == 'yes' ) { $itemsOnSale[] = $row; } else { $items[] = $row; } if ($i == 0) { echo '&lt;li&gt;This item number is on sale:'.$itemsOnSale[id]. '&lt;/li&gt;'; $i++; } else if ($i == 3) { echo '&lt;li&gt;This item number is regular price'.$items[id]. '&lt;/li&gt;'; $i = 0; } else { echo '&lt;li&gt;This item number is regular price'.$items[id].'&lt;/li&gt;'; $i++; } } ?&gt; &lt;/ul&gt; </code></pre>
    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.
    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