Reaper0167 Posted June 29, 2009 Share Posted June 29, 2009 i have an a sql select statement <?php $sql = mysql_query("SELECT id, category, thumb_1, thumb_2, thumb_3, thumb_4, thumb_5, item_name, description, in_return FROM member_trades WHERE user_id = " . $e_row['id'] . " $limit"); ?> it works good, I then have the info echoed into a table using while ($row = mysql_fetch_array($sql)) my question is, when i add other columns from my database into $sql, do i have to use them in the array? All i want to do is get the value of the other columns to use somewhere else but do not want to use them in the table that is being shown. if i add the other columns into the sql select statement, i get an error, i think because there not being used in the array? anyone understand? Quote Link to comment https://forums.phpfreaks.com/topic/164043-solved-array-question/ Share on other sites More sharing options...
Philip Posted June 29, 2009 Share Posted June 29, 2009 If I'm understanding you correctly, you want to store your results for a later use? $sql = mysql_query("SELECT `id`, `foo`, `bar` FROM `table` WHERE `status`=1"); $results = array(); while($row = mysql_fetch_assoc($sql)) { $results[] = $row; // You could even limit what you save for later: // $results[] = array('id'=>$row['id'], 'bar'=>$row['bar']); echo $row['foo'].'<br>'; } // ... later in the script: foreach($results as $key=>$value) { echo $value['bar'].' '.$value['id'].'<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/164043-solved-array-question/#findComment-865367 Share on other sites More sharing options...
Reaper0167 Posted June 29, 2009 Author Share Posted June 29, 2009 this is similar than what I explained. having an error when I have all the impaths and the thumbs in the query. this is only part of what is being displayed in the table. <?php $query="SELECT id, user_id, category, imgpath, imgpath_2, imgpath_3, imgpath_4, imgpath_5, thumb_1, thumb_2, thumb_3, thumb_4, thumb_5, item_name, description, in_return FROM member_trades WHERE id = '$got_item'"; $result = mysql_query($query); echo '<table width="954" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">'; while($row = mysql_fetch_assoc($result)) { echo '<tr><td height="151"><table width="100%" border="0" cellpadding="0" cellspacing="3">'; echo '<tr><td height="150"><div align="center">'; echo "<a href=\"{$row['imgpath']}\" onClick=\"window.open('{$row['imgpath']}', width=700); return false\"><img src=\"{$row['thumb_1']}\" width=\"150\" alt=\"\" border=\"0\"></a>"; echo '</div></td> ?> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result sorry to get off track, but I guess both are within the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/164043-solved-array-question/#findComment-865374 Share on other sites More sharing options...
Philip Posted June 29, 2009 Share Posted June 29, 2009 If it shows that, it means your query is failing. Have you tried running it in PHPMyAdmin, or the like? Quote Link to comment https://forums.phpfreaks.com/topic/164043-solved-array-question/#findComment-865376 Share on other sites More sharing options...
Reaper0167 Posted June 29, 2009 Author Share Posted June 29, 2009 sorry about the post with the on click stuff, I have that figured out. So I am back to my original post about having the extra columns in the select statement. Could I just have a hidden field in the table that displays in the array? U know, so I can get the info to use later on? Quote Link to comment https://forums.phpfreaks.com/topic/164043-solved-array-question/#findComment-865383 Share on other sites More sharing options...
Reaper0167 Posted June 29, 2009 Author Share Posted June 29, 2009 this is what confuses me. sorry, this is something i have not done before. If I'm understanding you correctly, you want to store your results for a later use? $sql = mysql_query("SELECT `id`, `foo`, `bar` FROM `table` WHERE `status`=1"); $results = array(); while($row = mysql_fetch_assoc($sql)) { $results[] = $row; // You could even limit what you save for later: // $results[] = array('id'=>$row['id'], 'bar'=>$row['bar']); echo $row['foo'].'<br>'; } // ... later in the script: foreach($results as $key=>$value) { echo $value['bar'].' '.$value['id'].'<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/164043-solved-array-question/#findComment-865393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.