Note that there are some explanatory texts on larger screens.

plurals
  1. POloop through mysql_query and replace value OR 1 query to do work
    primarykey
    data
    text
    <p>I am running a sql query, that pulls the id, catid, name, subof from two tables using inner join.</p> <pre><code>select shop.id, shop.catid, shop.name, shop_cat.catname, shop_cat.subof from shop inner join shop_cat on shop.catid = shop_cat.id where shop.active='1' order by shop_cat.catname, shop.name </code></pre> <p>Now this results everything i need but I need to loop through the result and do another sql query for the subof value (which is a value, the value being a ID number of the shop_cat). I need to pull the catname of the subof value #, then update the result/array field subof to the name of the cat. </p> <p>So if the original query gave me a value of 15 for subof, it would do a select catname from shop.cat where id='15' i would take the catname from that query and then update subof = catname for every value in the original result that has a subof value.</p> <p>EDIT 3/23/13 12:30pm MST: Using more of the code that Opeyemi wrote, to explain more of what I need. I am not sure how else to explain it...</p> <pre><code>$q = "select shop.id, shop.catid, shop.name, shop_cat.catname, shop_cat.subof from shop inner join shop_cat on shop.catid = shop_cat.id where shop.active='1' order by shop_cat.catname, shop.name"; $r = mysql_query(); while(list($shopid, $catid, $name, $catname, $subof) = mysql_fetch_array($r)) { $getname = mysql_query("select catname from shop_cat where id='$subof'"); $rowname = mysql_fetch_assoc($getname); //code to update array to change value of $subof to new $rowname['catname'] } </code></pre> <p>The DB query runs, gets me my values.</p> <p>I then need to run a loop of some kind, which will loop through every result PHP aquired from the query. This loop will take the subof value (which is a integer ID number) then run a query to get the value catname of that integer value. Then the loop will update the current result and change the subof value from the integer to the catname pulled from the DB in the loop. </p> <p>I do not need to update the database at anytime, I need to update the result/array from the first query.</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.
 

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