elentz Posted June 24, 2007 Share Posted June 24, 2007 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 Quote Link to comment Share on other sites More sharing options...
mkoga Posted June 24, 2007 Share Posted June 24, 2007 Here's an example: $query = 'SELECT * FROM <tablename>'; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo $row['id']; echo $row['name']; echo $row['email']; } --micah Quote Link to comment Share on other sites More sharing options...
elentz Posted June 24, 2007 Author Share Posted June 24, 2007 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! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 24, 2007 Share Posted June 24, 2007 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/>"; } ?> Quote Link to comment Share on other sites More sharing options...
elentz Posted June 24, 2007 Author Share Posted June 24, 2007 Thanks cooldude that is getting me closer to what I want. Using your second code is it possible to "center" that information on the page? What this ultimately end up being is a page for a quote for services. I want to use it just before printing it. Quote Link to comment Share on other sites More sharing options...
.Stealth Posted June 24, 2007 Share Posted June 24, 2007 <?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\">"; Quote Link to comment Share on other sites More sharing options...
AndyB Posted June 24, 2007 Share Posted June 24, 2007 @ elentz - it's just a matter of adjusting the html code to get the visual result you want. It's no longer a php question. Quote Link to comment Share on other sites More sharing options...
elentz Posted June 25, 2007 Author Share Posted June 25, 2007 Sorry to be such a noob. But, given what Stealth has given as code, how would I add a heading and a simple border around what he has so kindly given as an example. I have tried many things with no luck. Thanks alot Quote Link to comment Share on other sites More sharing options...
.Stealth Posted June 25, 2007 Share Posted June 25, 2007 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/>"; } ?> Quote Link to comment Share on other sites More sharing options...
swoyercmk Posted June 25, 2007 Share Posted June 25, 2007 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. Quote Link to comment Share on other sites More sharing options...
per1os Posted June 25, 2007 Share Posted June 25, 2007 www.webmonkey.com Great site for HTML tutorials. It should only take you a week to know HTML from top to bottom. It is very basic. Quote Link to comment Share on other sites More sharing options...
elentz Posted June 26, 2007 Author Share Posted June 26, 2007 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 26, 2007 Share Posted June 26, 2007 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> "; } ?> Quote Link to comment Share on other sites More sharing options...
.Stealth Posted June 26, 2007 Share Posted June 26, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.