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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basic list screen rookie problem

Status
Not open for further replies.

iamsw00sh

Programmer
May 21, 2003
92
RO
// Printing results in HTML
echo "<table border=1>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";



my question is
how can I make this without "foreach ($line as $col_value)"
because :
let's say i have a 5 columns table in 2 rows ...
i would like to display only 2 columns, and the rest of them ... 3 more ... only have in some variable per row, so i can use it as ID-s or something ...

do i make sense?

in asp I had something like this:
a = returnedrecordset(rownumber, columnnumber)
print a

:)

got it?

thanks!

--
cucu bau
 
Well you could use this:
Code:
  echo "\t\t<td>".$line['col_name']."</td>\n";
instead of this:
Code:
foreach ($line as $col_value) {
       echo "\t\t<td>$col_value</td>\n";
   }

Just replace col_name with whatever you column names are.
 
wow that is great
i'll check if it work out for me

i love you !!!

:)))

--
cucu bau
 
Let's see if I have interpreted your request correctly.

You have 5 fields in your database table. You always want to display two of the fields. The other three fields, you want to display if some condition is met.

If that's what you're asking, then try this:
Code:
<?
echo "<table border=1>\n";
while ($line = mysql_fetch_assoc($result)) {
  echo "\t<tr>\n";
   foreach ($line as $key => $value) {
       switch ($key) {
          case 'req_field1':
          case 'req_field2':
            echo "\t\t<td>$value</td>\n";
            break;
          case 'opt_field3':
          case 'opt_field4':
          case 'opt_field5':
            if (some_condition)
                echo "\t\t<td>$value</td>\n";
            break;
       }
   }
   echo "\t</tr>\n";
}
echo "</table>\n";
?>

If this is NOT what you meant, try to explain it a little better. Also, not all of us know (or want to know) ASP, so giving that as an example is meaningless to us. :)

Ken
 
cool

working ;-)

man i still have a lot to learn

--
cucu bau
 
can i use instead of this:

Code:
// Printing results in HTML
echo "<table border=1>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  echo "\t<tr>\n";
   echo "\t\t<td>".$line['Title']."</td>\n";
   echo "\t\t<td>".$line['Description']."</td>\n";
   echo "\t</tr>\n";
}
echo "</table>\n<br>";


something like this:
Code:
<table border="1">
<?
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<tr>
<?
	foreach ($line as $col_value)
	{
?>
		<td><?echo "$line['Title']"?></td>
		<td><?echo "$line['Description']"?></td>
<?
	}	
?>
</tr>
<?
}
?>
</table>
????

is seems a lot easier to debug ...

by the way ... this one is crashing ... :-(

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\inetpub\ on line 59


--
cucu bau
 
General recommendation:

Whenever the PHP interpreter has to switch from PHP context to HTML context time is consumed and scripts run slow.
I recommend that you just add a few echo or print statements and output the table related tags also. It will make your easier to read and will keep a better structure with the brackets.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top