Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Queries: Multi Variables or One Query
    primarykey
    data
    text
    <p>I had a lot of help in writing all of this in php (mainly the first long query).</p> <pre><code>// Query the database for data $query = "SELECT cards.card_id, concat(title, \" By Amy\") AS TitleConcat, description, meta_description, seo_keywords,concat(\"http://www.amyadele.com/attachments//cards/\",cards.card_id,\"/\",card_image) AS ImageConcat,price FROM cards, card_cheapest WHERE cards.card_id = card_cheapest.card_id ORDER BY card_id"; $result = mysql_query($query); // Open file for writing $myFile = "googleproducts.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); // Loop through returned data and write (append) directly to file fprintf($fh, "%-25s %-200s %-800s %-200s %-800s %-800s\n", "id", "label","description","price","image","seo keywords"); fprintf($fh, "\n"); while ($row = mysql_fetch_assoc($result)) { fprintf($fh, "%-25s %-200s %-800s %-200s %-800s %-800s\n", $row['card_id'], $row['TitleConcat'], $row['description'],$row['price'],$row['ImageConcat'], $row['seo_keywords']); } // Close out the file fclose($fh); echo "The file has been written sucessfully to googleproducts.txt. It will run again tomorrow at 12:00pm." ?&gt; </code></pre> <p>However, over the last couple of days I have written a couple other queries which leads me to my question. Would it be easier to somehow stick this other queries into the first "select", or would it be easier to set up multiple queries and then just insert that into the rows as well (I dont even know if that is even possible).</p> <p>Query: Selecting the Min Price</p> <pre><code>select card_id, min(card_price) from card_lookup_values where card_price &gt; 0 group by card_id; </code></pre> <p>Query: Creating URL Structure</p> <pre><code>SELECT CONCAT('http://amyadele.com/', cards.title, '/', categories.seoname, '/', cards.seoname),cards.card_id FROM cards LEFT JOIN card_categories ON card_categories.card_id = cards.card_id LEFT JOIN categories ON card_categories.category_id = categories.category_id ORDER by card_id; </code></pre> <p>I guess my question is is it best to set up my queries (which I already know work) into multiple variables and then somehow push that into the table format I have set up, or to somehow format all of these queries into one long query?</p> <p>I recently just wrote </p> <pre><code> SELECT replace(lower(concat( 'http://www.amyadele.com/', pcat.seoname,'/',cat.seoname, '/', cards.seoname, '.htm' )),' ','+') AS link, concat(pcat.name,'&gt;',cat.name) as category, replace(lower(concat( 'http://www.amyadele.com/', cat.seoname, '/', cards.seoname, '.htm' )),' ','+') AS add_to_cart_link FROM cards INNER JOIN card_categories cc ON cards.card_id = cc.card_id AND cards.card_live = 'y' AND cards.active = 'y' AND cc.active = 'Y' INNER JOIN categories cat ON cat.category_id = cc.category_id AND cat.active = 'Y' INNER JOIN categories pcat ON cat.parent_category_id = pcat.category_id INNER JOIN card_lookup_values clv on clv.card_id=cards.card_id and clv.lookup_detail_id WHERE cat.parent_category_id &lt;&gt;0 ORDER BY cc.card_id </code></pre> <p>However, I am really confused on how to even add this now</p>
    singulars
    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