amites Posted June 18, 2007 Share Posted June 18, 2007 Hello, I come to this board looking for some help I have a page which make multiple inquiries to a local mySQL DB, and in my attempt to avoid adding to the number of inquiries I am trying to set an array to a string of data pulled from a inquiry inside of a loop, specifically: foreach($product_array2 as $num_temp){ $num=$num_temp['parent']; $sql = "SELECT categories_name FROM categories_description WHERE categories_id='$num'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $cat_name_find=$row['categories_name']; //print $cat_name_find."--<br>"; if($cat_name_find==$temp){ $ct++; } } when I go back to call upon $cat_name I get array(1) { ["categories_id"]=> NULL } as a var-dump... any ideas what I'm doing wrong?? I'm not a strong coder my background has been development, design, and marketing but this time I don't have much choice, any help would be greatly appreciated I can post more of the code if needed Alvin Link to comment https://forums.phpfreaks.com/topic/56042-set-array-to-re-use-data-from-db-inquiry/ Share on other sites More sharing options...
Illusion Posted June 18, 2007 Share Posted June 18, 2007 try this $sql = "SELECT categories_name FROM categories_description WHERE categories_id=".$num; Link to comment https://forums.phpfreaks.com/topic/56042-set-array-to-re-use-data-from-db-inquiry/#findComment-276812 Share on other sites More sharing options...
amites Posted June 18, 2007 Author Share Posted June 18, 2007 I suppose I should have been more specific, the above Query is working, the trouble is that query is inside a foreach loop my goal is to save the results from that query into an array which I can call upon later for a better description: the page is located at: http://www.testequipmentconnection.com/index.php?main_page=manucat&manu=TEKTRONIX the code above generates a side menu of categories with entries that match $manufacturer my goal is to then use the list used to generate the menu to display a list entries from each category hope i haven't made this more confusing, it will likely make more sense if you look at the page Link to comment https://forums.phpfreaks.com/topic/56042-set-array-to-re-use-data-from-db-inquiry/#findComment-277022 Share on other sites More sharing options...
amites Posted June 18, 2007 Author Share Posted June 18, 2007 whittled away on this one a bit more today I have it down to a simple question. how do I set an array while inside a forloop specifically: $row_cat = mysql_fetch_assoc($result); //all good $cat_Number= $row_cat['categories_id']; // set current category ID // $cat_id_array[]=('cat_id'=>$cat_Number); // huh? var_dump($row_cat); the above gives me: array(4) { ["categories_id"]=> string(2) "17" ["language_id"]=> string(1) "1" ["categories_name"]=> string(14) "Power Supplies" ["categories_description"]=> string(0) "" } when I uncomment the above line I get: Parse error: syntax error, unexpected T_DOUBLE_ARROW for the line with that bit of code I believe everything else is correct, when I set a temporary category for display it displays properly any ideas? Link to comment https://forums.phpfreaks.com/topic/56042-set-array-to-re-use-data-from-db-inquiry/#findComment-277138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.