Languages :: PHP :: outputting php variables |
|||
| By: eire_ireland |
Date: 09/04/2003 00:00:00 |
Points: 30 | Status: Answered Quality : Excellent |
|
Hi Is there any way I can amend the following code so that the variables "1" and "2" are outputted into a table or something close? Cheers..... ----------------------php code-------------------------- $ = mysql_query ("SELECT * from table"); if ($row = mysql_fetch_array($result)) { do { $1 = $row["1"]; $2 = $row["2"]; echo("$1"); echo("$2"); } while($row = mysql_fetch_array($)); } else {print "Sorry, no records were found!";} |
|||
| By: VGR | Date: 09/04/2003 22:58:00 | Type : Comment |
|
| oeuf cortse : <? // snip connecting to DB $query="SELECT * from table"; $result = mysql_query ($query) or die ("invalid query '$query', error was : ".mysql_error()); // now check the results set if (mysql_num_rows($result)>0) { // table prologue echo "<table>"; // now get all returned lines while ($row = mysql_fetch_array($result)) { // process a line $v1 = $row['field1']; $v2 = $row['field2']; echo "<tr><td>$v1</td><td>$v2</td></tr>"; } // end while rows // table epilogue echo "</table>"; } else echo "Sorry, no records were found!"; ?> |
|||
| By: sumotimor | Date: 09/04/2003 23:02:00 | Type : Comment |
|
| $result = mysql_query ("SELECT * from table"); echo"<table>" while ($row = mysql_fetch_array($result)) { echo"<tr>"; foreach($row as $value) { printf("<td>%s</td>",$value); } echo"</tr>"; } echo"</table>"; hope there's no syntax error... |
|||
| By: eire_ireland | Date: 13/04/2003 04:48:00 | Type : Comment |
|
| Cheers VGR, thats working grand... just one thing, can I put the variables in a table of some kind or at least how can I space out the variables going across the screen. Thanks again |
|||
| By: VGR | Date: 13/04/2003 17:00:00 | Type : Answer |
|
| huh ? Values ARE in a table, no ? if youwant to table's border to appear, amend this line : echo "<table border=1>"; is this what you wanted ? Playing with cellspacing etc can also lead to more "sparsely scattered" :D data, or you can add (two white spaces) before and after values in the TDs, like this : echo "<tr><td> $v1 </td><td> $v2 </td></tr>"; |
|||
|
Do register to be able to answer |
|||
©2012 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








