Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Temp Row

Status
Not open for further replies.

Xploder

Programmer
Apr 10, 2005
11
CA
How do I display all the values in a table in order from top to bottom, one after the other?
So fahr It only does it with specific values:

$result = mysql_query("SELECT * FROM map");
$row = mysql_fetch_row($result);
echo $row["1"];

how do I siplify it to any values, just read them out?
 
you try running it through a loop, something like this

for ($i=0; $i<count($row); $i++) {
echo $row[$i]."<br>";
}
 
no that doesn't work cause I could have repeated $i values.
 
Code:
$result = mysql_query("SELECT * FROM map");
while ($row = mysql_fetch_row($result)) {
  echo $row[0]."<br>";
}

or when you specify columna names

Code:
$result = mysql_query("SELECT col1,col2 FROM map");
while (list($col1,$col2) = mysql_fetch_row($result)) {
  echo "col1: $col1 , col2: $col2 <br>";
}

gry online
 
hmm, It doesn't work.

// works, but only if i values don't repeat in the table,
// if they do, any other occurance of it is ignored.
for ($i=0; $i<count($row); $i++) {
echo $row[$i]."<br>";
}

// works only for values of 1 in the table even if they
// repeat.
for ($i=0; $i<count($row); $i++) { // works, for repeated
echo $row["1"]."<br>";
}

my table look like this:
-----------
|id | land|
-----------
| 5 | 67 |
| 1 | 45 |
| 1 | 89 |
| 2 | 100|
| 1 | 34 |
| 2 | 12 |
| 4 | 35 |
-----------

I just want to get all the values output one after the other, without remembering all the values:

67, 45, 89, 100, 34, 12, 35


 
for ($i=0; $i<count($row); $i++) {
echo $row[$i].", ";
}

It doesn't work because in a table such as above when $i is 1 it gets the value from the table, but then $i is 2 it won't get another row with a value of 1.

Does MySQL not have a function to get all the values from the 'land' column?
 
well I did this:

$query = "SELECT * FROM map WHERE id>0 ORDER BY id";
$result = mysql_query($query) or die(mysql_error());

while ($fetched = mysql_fetch_assoc($result)){
echo $fetched['land']
}

I don't really need order by id...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top