Jump to content

[SOLVED] How do I show results of a query


elentz

Recommended Posts

I know how to connect to a Mysql table.  I want to run the query and show the results on my page.  I'll have about 25 different fields I need to show on the page.  Most of this information will be a couple of addresses.  Basically, a billing and then a shipping address.  Can someone show me how to show some of this on a page?  I'll need to align all this stuff around the page. 

 

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/56910-solved-how-do-i-show-results-of-a-query/
Share on other sites

Thanks for the example micah.

 

How can I make the info layout like:

 

1st street address                            2nd street address

1st city                                          2nd city

1st zipcode                                      2nd zipcode.

 

Thanks!

do what ever you want in the while loop, however if you want to restructure the data in a method other than basic tabular it would be better to take each form element and store it in an array like

 

<?php
while ($row = mysql_fetch_assoc($result)) {
$street1[$i] = $row['street1'];
$city1[$i] = $row['city1'];
//etc etc
$i++;
}
?>

Then later on you can recall them either as array index $i or all the streets together or citys or zips if that is what you talking about other wise try this:

 

<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<table>";
echo "<tr><td>".$row['street1']."</td><td>".$row['street2']."</td></tr>";
echo "<tr><td>".$row['city1']."</td><td>".$row['city2']."</td></tr>";
echo "<tr><td>".$row['zip1']."</td><td>".$row['zip2']."</td></tr>";
echo "</table><br/>";
}
?>

<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<table align=\"center\">";
echo "<tr><td>".$row['street1']."</td><td>".$row['street2']."</td></tr>";
echo "<tr><td>".$row['city1']."</td><td>".$row['city2']."</td></tr>";
echo "<tr><td>".$row['zip1']."</td><td>".$row['zip2']."</td></tr>";
echo "</table><br/>";
}
?>

 

notice the:

echo "<table align=\"center\">";

Well you could do it like this:

 

<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>HEADING</th></tr>"
echo "<tr><td>".$row['street1']."</td><td>".$row['street2']."</td></tr>";
echo "<tr><td>".$row['city1']."</td><td>".$row['city2']."</td></tr>";
echo "<tr><td>".$row['zip1']."</td><td>".$row['zip2']."</td></tr>";
echo "</table><br/>";
}
?>

 

 

or like this:

 

<?php
echo "<h1>Heading</h1>";
while ($row = mysql_fetch_assoc($result)) {
echo "<table border=\"1\" align=\"center\">";
echo "<tr><td>".$row['street1']."</td><td>".$row['street2']."</td></tr>";
echo "<tr><td>".$row['city1']."</td><td>".$row['city2']."</td></tr>";
echo "<tr><td>".$row['zip1']."</td><td>".$row['zip2']."</td></tr>";
echo "</table><br/>";
}
?>

You could simply output a title with PHP using an echo statement before the query.

 

<table align=\"center\" border=\"1\">

 

would be the code to add a small border to your table.

 

again, its a matter of outputting HTML at this point. Hope that helps!

 

good luck.

Sorry to be a pain but I am still having an issue here.  I get the following message when I run the script:

 

Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in /var/www/vtigercrm/modules/Quotes/CreatePDF.php on line 71

 

Line 71 is:

echo "<table border="1" align="center">";

 

The whole part of the table script is:

while ($row = mysql_fetch_assoc($result)) {

echo "<table border="1" align="center">";

echo "<tr><th>Bill to address // Service Address:</th></tr>";

echo "<tr><td>".$row['bill_street']."</td><td>".$row['ship_street']."</td></tr>";

echo "<tr><td>".$row['bill_city']."</td><td>".$row['ship_city']."</td></tr>";

echo "<tr><td>".$row['bill_state']."</td><td>".$row['ship_state']."</td></tr>";

echo "</table><br/>";

}

 

 

Thanks

 

 

please learn html and php and css and mysql

 

>>>links<<<<

 

php

http://www.hudzilla.org/php/

 

html

http://www.w3schools.com/html/default.asp

 

css

http://www.w3schools.com/css/default.asp

 

mysql

http://www.sql-tutorial.net/SQL-tutorial.asp

 

 

you can also get books form

 

php

http://www.amazon.com/Programming-PHP-Rasmus-Lerdorf/dp/1565926102

 

html

http://www.amazon.com/s/ref=nb_ss_b/104-6984062-0713547?url=search-alias%3Dstripbooks&field-keywords=html

 

css

http://www.amazon.com/s/ref=nb_ss_b/102-0027596-9128957?url=search-alias%3Dstripbooks&field-keywords=css

 

mysql

http://www.amazon.com/s/ref=nb_ss_b/102-0027596-9128957?url=search-alias%3Dstripbooks&field-keywords=mysql

 

 

you can also watch free php video

http://www.phpvideotutorials.com/

 

 

 

 

 

 

 

 

 

 

 

 

<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<table border='1' align='center">'';
echo "<tr><th>Bill to address // Service Address:</th></tr>";
echo "<tr><td>".$row['bill_street']."</td><td>".$row['ship_street']."</td></tr>";
echo "<tr><td>".$row['bill_city']."</td><td>".$row['ship_city']."</td></tr>";
echo "<tr><td>".$row['bill_state']."</td><td>".$row['ship_state']."</td></tr>";
echo "</table>
";
}
?>

 

 

 

It should be:

echo "<table border=\"1\" align=\"center\">";

 

because you have double quotes within double quotes, it expects the echo to stop here:

<table border="1"

 

For security reasons you should always try to use double quotes within html, just make sure you escape them with backslashes when you declare them in an echo or var etc.

 

so it would be:

 

echo "he said \"hello\"";

 

or:

 

$var = "he said \"hello\"";

 

the same applys for single quotes:

 

echo 'he said \'hello\'';

 

you can do it like this:

 

echo "<table border='1' align='center'>";

 

but for the best security all html should use double quotes for things like this.

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.