Jump to content

[SOLVED] array question


Reaper0167

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/164043-solved-array-question/
Share on other sites

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>';
}

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.

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?

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>';
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.