visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
316 experts, 1194 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: outputting php variables


By: eire_ireland U.S.A.  Date: 09/04/2003 00:00:00  English  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 English  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 English  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 English  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 English  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 &nbsp;&nbsp; (two white spaces) before and after values in the TDs, like this :
echo "<tr><td>&nbsp;&nbsp;$v1&nbsp;&nbsp;</td><td>&nbsp;&nbsp;$v2&nbsp;&nbsp;</td></tr>";


Do register to be able to answer

EContact
browser fav
page generated in 392.472980 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page