overlordofevil Posted August 20, 2008 Share Posted August 20, 2008 I got a question with arrays. What I want to do is pull data from mysql in to an array. now I know how to pull the info and get an array that uses a loop to show the data. example $query = "SELECT * FROM skill"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); echo $row[whatever]; } what I want to do is pull the data and store it in an array that I can then use to test data. What I have is a script that tests for a specific variable and then compares it to what is stored in a separate table. What I am having trouble doing is when it needs to check for 2 separate values in the table. while ($row = mysql_fetch_array($result)) { extract($row); $cost = getskillcost($skillID, $classid); echo "<tr><td>\n"; $preq= explode(",",$prereq); foreach ($preq as $value) { if ($value == $n) { echo "<a href='addskill.php?action=add&skillID=$skillID'>$skillName</a> ($cost)"; } Ok as you see with the first part is is pulling the general data and checking for the the value. if it is '0' then the item is printed if it is any other value it goes to the next step. else { $query1 = "SELECT * FROM skill where id = '$id'"; $result1 = mysql_query($query1) or die (mysql_error()); while ($row1 = mysql_fetch_array($result1)) { extract($row1); if ($value == $skill) { echo "<a href='addskill.php?action=add&skillID=$skillID'>$skillName</a> ($cost)"; } } } } echo "</td></tr>\n"; } Now as you can see on the second part it works when it comes to pulling just one value to compare but for a few items i have multiple values that I need to compare. So I guess what I am asking is there a way to pull the data and store it as skill[] and use that reference to check the values Or I might be completely off and looking at this the wrong way. Any suggestions would be appreciated. Link to comment https://forums.phpfreaks.com/topic/120616-questions-about-arrays/ Share on other sites More sharing options...
genericnumber1 Posted August 21, 2008 Share Posted August 21, 2008 <?php $resultArray = array(); while ($row = mysql_fetch_assoc($result)) { $resultArray[] = $row; } ?> that will load a mysql query resource, in this case $result, into an array $resultArray. I couldn't understand your exact problem (I'm out of it right now) so I couldn't advise you if you're going about it the wrong way Link to comment https://forums.phpfreaks.com/topic/120616-questions-about-arrays/#findComment-621554 Share on other sites More sharing options...
overlordofevil Posted August 22, 2008 Author Share Posted August 22, 2008 I will try this and see if it helps. I think I understand how it is suppose to work and it looks simple enough. If it doesn't work or I have more problems I will post again. Thanks Link to comment https://forums.phpfreaks.com/topic/120616-questions-about-arrays/#findComment-622668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.