PHP - Print Specified Text, If The Sql Table's Column's Value Is 0.
while($row = mysql_fetch_row($query)) {
echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td>' . $row[3] . '</td>'; echo '<td>' . $row[4] . '</td>'; echo "</tr>\n"; } Currently I have this code. I would like to make it print certain text, let's say... 'car', if the value of table's column 'automobiles' is equal to 0. Otherwise - print the real value. I've tried if statement and $one = $two... But that apparently didn't worked. Thanks. Similar TutorialsHi
I am very new to PHP & Mysql.
I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion.
Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself.
Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows).
Ripon.
Below is my Code:
<?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?>Output is attached. We have booking data in spreadsheet looks like table in below, and each booking is for a full week. | wk1 | wk2 | wk3 | wk4 | wk5 |..........| wk52 | ================================== E1 | resv | |resv | |resv | |resv E2 | | resv |resv |resv | E3 | resv | resv |............................................... E4 | resv | E5 | ... | resv | resv|.................................... ... | E50|resv | resv | | resv It looks great excel but required one person to manage all bookings. So we moved to web interface and allow users to make their own bookings. Now, data moved to sql database with fields (id, wk#, room, other....), and records like below. 01 wk1 E1 02 wk1 E3 03 wk1 E4 ..... etc.... nn wk2 E2 nn wk2 E3 ... and more Now, I need a method in PHP to print above data in HTML table that looks like excel table in above. It doesn't have to print 52 wks in one page, but at least something like 4 wks view and next page to show the next 4 wks. At start it will print the first 4 wks from the current week (wk 11), and next page will print wk12 to wk15, etc. | wk1 | wk2 | wk3 | wk4 =================== E1 | resv | |resv | E2 | | resv |resv |resv E3 | resv | resv |............... E4 | resv | E5 | more rows...... Can someone here give me a direction how to code this in PHP? Thank you very much! bobo Simple question but I couldn't find any straight forward answers.
I have a customer details table with: customer ID, name, address, email.
I also have an delivery table with delivery ID, customer ID, order ID.
How can I link the customer ID column from the customer table to the delivery table so that when changes occur on the customer table they subsequently alter all other tables?
I know it might use foreign keys but I couldn't find any online resource that explained how to use them properly.
Cheers
This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355885.0 What I want to do is what is in the shown in the table. I want to only get the Math subject and order the units from unit 1 (UI) to the last available unit in the database; after this, under each unit, to show the homework related to each unit. I have tried to save it into an array with mysql_fetch_array but it stores the row that involves one unit. I want all the units and only the units with their homework under them.
My database is attached to this post in a txt file.
hope someone can help.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento sin título</title> </head> <body> <form action="" method="post" name="form1" id="form1"> <table width="200" border="1"> <tr> <td>Subject:</td> <td>Math</td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td>UI</td> <td>UI</td> <td>UII</td> <td>UIII</td> <td>UII</td> <td>...</td> </tr> <tr> <td>Home work</td> <td>Math work1</td> <td>Math work2</td> <td>Math work3</td> <td>Math work4</td> <td>Math work5</td> <td>...</td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> </form> </body> </html> [ Newbie Alert ] Hi i have an array of 39 arrays. Only 5 are shown below so that you have an idea before i ask my question. <? array(39) { [0]=> array(3) { [0]=> string(18) "unit name 1" [1]=> string(9) "category name 1" [2]=> string(20) "Course 1" } [1]=> array(3) { [0]=> string(54) "unit name 2" [1]=> string(15) "category name 2" [2]=> string(20) "Course 1" } [2]=> array(3) { [0]=> string(29) "unit name 3" [1]=> string(15) "category name 2" [2]=> string(20) "Course 1" } [3]=> array(3) { [0]=> string(64) "unit name 4" [1]=> string(30) "category name 3" [2]=> string(20) "Course 2" } [4]=> array(3) { [0]=> string(57) "unit name 5" [1]=> string(24) "category name 1" [2]=> string(20) "Course 1" } [5]=> array(3) { [0]=> string(50) "unit name 6" [1]=> string(24) "category name 4" [2]=> string(20) "Course 2" } } i want a php solution to print category names in table headers , unit names in table rows and course name(s) in table caption.I have tried foreach loop but how to remove duplicate entries as you can see category name 1 and 2 will become two separate headers instead of one and same is the case with Course 1 and 2. i have googled but could'nt find any solution. i don't want to remove duplicate entries , all i want to display them once in a table as described above. Hello, I have the following code writting IP,session, and date to a text file (it works) but I want to add a white space after the IP address. fwrite($fp, $_SERVER['REMOTE_ADDR']. $_SESSION["sess_name"]. " $dateTime\r\n"); At the moment it prints like this 16.17.51.41SESSION_ID 2011/01/23 12:53:32 thanks in advance. Hello, I am attempting to create a script where a user puts a text string into a form and clicking on submit. Then it adds that text string to a mysql database and gives the user a link back to it. Something like mysite.com/key.php?id=4 and when going to that link it will display the text string from the database but printed in an image. I wrote something up but I cannot get it to work. I may be a little in over my head. Any help is appreciated.
The way I coded this all to work is the user inputs the information into index.php which givekey.php inserts that into the database. I have not yet figure out how to do this in one single step. After that I wanted it to navigate directly to key.php which would display the key and the link to that page with the ?key=XX attribute. getkey.php <?php require_once 'dbinfo.php'; // database connection $id = $_GET['id']; // do some validation here to ensure id is safe $link = mysql_connect($servername, $username, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($database) or die( "Unable to select database"); $sql = "SELECT ukey FROM keycode WHERE id=$id"; $result = mysql_query("$sql"); $row = mysql_fetch_assoc($result); mysql_close($link); header("Content-type: image/png"); echo $row['ukey']; ?> key.php <html> <head> <title>Your Key Is Ready</title> </head> <body> <img src="getkey.php?id=1" width="175" height="200" /> </body> </html>index.php <html> <head> <title></title> </head> <body> <section id="mid_section"> <div id="boxes"> <h1> Testing input key </h1> <br/> <form id="myform" action="givekey.php" method="post"> Key:<br /> <input type="text" value="ukey"> Source:<br /> <input type="radio" value="hb">HB<br /> <input type="radio" value="ig">IG<br /> <input type="radio" value="other">Other<br /> <button id="sub">Submit</button> </form> </body> </html>givekey.php <?php include_once('dbinfo.php'); $conn = mysql_connect($servername, $username, $password); $db= mysql_select_db($database); $ukey =$_POST['ukey']; $hb =$_POST['hb']; $ig =$_POST['ig']; $other =$_POST['other']; if(mysql_query("INSERT INTO `keycode`(`ukey`) VALUES ([$ukey]); INSERT INTO `source`(`hb`,`ig`,`other`) VALUES ([$hb],[$ig],[$other]);")) ?> Edited by chrisb302, 13 November 2014 - 12:18 AM. Hi, I'm quite new to this and I'm trying to get this to line up in a table with 3 columns (unlimited rows) I have searched and tried but I'm not having any luck. Can any one help? Thank you Code: [Select] <?php echo '<div class="resultados_sub_cat">'; foreach($this->subcats as $key => $subcat) { $subcat->link = JRoute::_('index.php?option=classcliff&view=list&catid='.$subcat->id."&Itemid=".$this->Itemid); if ($key != 0) echo ' - '; echo '<a href="'.$subcat->link.'">'.$subcat->name.'</a>'; } ?> I have an existing two table structure where sub-data is related to main data in a many-to-one relationship.
There are several identically named columns in both tables.
(The PHP database class will return an associative array that did not deal with identical keys in the row.)
I'm LEFT JOINing the sub-data to the main-data tables.
When using a stand-alone query browser (to experiment), the display shows all columns, even those column names that appear more than once in the row.
Is there a general approach to making keys (column names) unique strictly using a MySQL SELECT statement?
Perhaps using table aliases, how can I concat the alias to the columns that come from each table?
What I am trying to avoid is giving an alias to each column in a list of column names, such as:
SELECT
C.name AS C_name
C.numb AS C_numb
D.name AS D_name
D.numb AS D_numb
etc.
I am wanting more like the result one could guess would be from:
C.* AS C_*
D.* AS D_*
Or better:
* AS CONCAT(__TABLE__, '_', *)
if __TABLE was a magic constant (like PHP's __LINE__, __FILE__, etc).
I have a mysql table named songs with 3 columns, id, artist,title. Most of the songs in the artist column are correct, ex: artist ------------------ John Denver Loretta Lynn Shania Twain Luke Bryan But some of the songs in the artist column are reveresed with a comma, ex: artist ----------------- Dever, John Lynn. Loretta Twain, Shania Bryan, Luke Is there an easy php code snippet or mysql statement that i can use to reverse the order of first name and last name and remove the comma in the last example so the artst columd matches the first example? I hope this makes sense, thanks, Dale.
Hello,
I have a table like this: CREATE TABLE days ( id INT AUTO_INCREMENT, daya INT, dayb INT, PRIMARY KEY (id) ); INSERT INTO days VALUES (70, 19, 18), (69, 20, 17), (68, 24, 25), (67, 19, 18), (66, 19, 17), (65, 17, 16);
$sql = "SELECT d1.id AS id1, d2.id AS id2, IF((d1.daya-d2.daya)=1,1,0) + IF((d1.daya-d2.dayb)=1,1,0) + IF((d1.dayb-d2.daya)=1,1,0) + IF((d1.dayb-d2.dayb)=1,1,0) AS tcount FROM days AS d1 , days AS d2 WHERE d1.id IS NOT NULL AND d2.id IS NOT NULL AND d1.id > d2.id"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["id1"] . "</td><td>". $row["id2"] . "</td><td>" . $row["tcount"]. "</td></tr>"; } echo "</table>";
Id1 Id2 Count 50 49 1 50 48 0 49 48 0 50 47 1 49 47 1 48 47 0 50 46 1 49 46 1 48 46 0 47 46 1 50 45 1 49 45 1 48 45 0 47 45 1 46 45 1 I need to convert the table into this form: id1 goes down the first column, and id2 is in the first row. How can i do this, please? can you give me some help? thank you! id2 49 48 47 46 45 id1 50 1 0 1 1 1 49 0 1 1 1 48 0 0 0 47 1 1 46 1 45
Hi, Stuck again with the Joomla/K2 coding. Trying to output this field in a 2 column table but failing badly. Any help or ideas would be greatly appreciated. <?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="catItemExtraFields"> <h4><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h4> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField): ?> <?php if($extraField->value): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <?php if ($extraField->name =='Closing date') : ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemDateCreated"><?php echo JHTML::_('date', $this->item->publish_down ); ?></span> <?php else :?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php endif; ?> </li> <?php endif; ?> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?> I have a table and one column has links that point to index.php?id= but I want it to display the info of that row of my database. On the index.php page i have this code Code: [Select] <?php include "dbaptsConfig.php"; // test id, you need to replace this with whatever id you want the result from $id = "1"; // what you want to ask the db $query = "SELECT * FROM `apartments` WHERE `id` = ".$id; // actually asking the db $res = mysql_query($query, $ms); // recieving the answer from the db (you can only use this line if there is always only one result, otherwise will give error) $result = mysql_fetch_assoc($res); // if you uncomment the next line it prints out the whole result as an array (prints out the image as weird characters) // print_r($result); // print out specific information (not the whole array) echo "id: ".$result['id']."<br />"; echo "username: ".$result['username']."<br />"; echo "type: ".$result['type']."<br />"; echo "title: ".$result['title']."<br />"; echo "description: ".$result['description']."<br />"; echo "county: ".$result['county']."<br />"; echo "town: ".$result['town']."<br />"; echo "phone: ".$result['phone']."<br />"; echo "rooms: ".$result['rooms']."<br />"; echo "bath: ".$result['bath']."<br />"; echo "squa ".$result['square']."<br />"; echo "rent: ".$result['rent']."<br />"; echo "time: ".$result['time']."<br />"; ?>I know there is something wrong with this cause I always get the same info no matter which apartment I click. Do I use the $_GET function and how do I implement this? Hi guys I hope I am in the right place on this forum, if not I apologise. A have been working with CS-Cart and had so much trouble trying to update product combinations so I searched for help on the data feeds I am using and found that there was a script that would update my products for os-commerce, this has worked out even worse. All I really need is for a script to update one column called amount in a Mysql table by referring to the product_code column, Eg If product_code NS324 is= to 5 ad 5 to the amount column. This sounds simple but I think it might be complex. Here is the Table Generated b\: phpM\Admin 3.4.9 / M\SQL 5.5.20-log SQL quer\: SELECT * FROM `cscart_product_options_inventor\` LIMIT 0, 30 ; Rows: 30 Column1-----------Column2---------------Column3--------------Column4----------Column5-------Column6-------Column7 product_id-----product_code---------combination_hash-----combination-------amount----------temp-----------position --29813--------------NS3455----------- --1447985068-----------738_3059-----------0-----------------N-------------------0 So if I can update the amount column using the product_code would solve all of my problems. So this is what I need to do, I need to add an amount to the amount column related to the product_code NS3455 or update amount or even replace amount it don't matter. Due to the nature of the feeds I receive I cannot use product_id or combination_hash or combination. Please help me do this. Lets see who is the clever one. Thanks for you time I am trying to set the column widths in my HTML 5 script, but what ever I do the widths stay the same?
I found that the <col width=""> tag does not work in HTML 5.
So I tried <th style="width:130px">Week #</th> and this did not work.
I have also created a special table div style #table1.
Nothing changes when I make these changes!
Here is the table part of my script: <div id="table1"> <table width="250%" cellspacing="1" border="1" BGCOLOR="white"> <tr> <th style="width:130px">Week #</th> <th style="width:80px">18</th> <th style="width:80px">19</th> <th style="width:80px">20</th> <th style="width:80px">21</th> <th style="width:80px">22</th> <th style="width:80px">23</th> <th style="width:80px">24</th> <th style="width:80px">25</th> <th style="width:80px">26</th> </tr> <tr> <td>Visits</td> <td>300</td><td>346</td><td>266</td><td>216</td><td>339</td><td>288</td><td>231</td><td>213</td><td></td></tr> <tr> <td>From</td> <td>28/04/2014</td><td>05/05/2014</td><td>12/05/2014</td><td>19/05/2014</td><td>26/05/2014</td><td>02/06/2014</td><td>09/06/2014</td><td>16/06/2014</td><td>23/06/2014</td> </tr> <tr> <td>To</td> <td>04/05/2014</td><td>11/05/2014</td><td>18/05/2014</td><td>25/05/2014</td><td>01/06/2014</td><td>08/06/2014</td><td>15/06/2014</td><td>22/06/2014</td><td>29/06/2014</td> </tr> <tr> <td>USA</td><td>161</td><td>158</td><td>148</td><td>79</td><td>132</td><td>105</td><td>81</td><td>70</td><td></td> etc......... </table> </div>here is my style.css script: /* Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License */ body { margin: 0; padding: 0; background: #F1F1F1 url(images/img01.gif) repeat-x left top; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: black; } quote { font-size:medium; } h1, h2, h3 { margin: 0; padding: 0; font-weight: normal; color: #023848; } h1 { font-size: 4em; } h2 { font-size: 2.4em; } h3 { font-size: 1.6em; } p, ul, ol { margin-top: 0; line-height: 180%; } ul, ol { font-size:large; } ul.a { list-style-type:circle; } ul.b { list-style-type:square; } ol.c { list-style-type:upper-roman; } ol.d { list-style-type:lower-alpha; } a { text-decoration: none; color: #4486C7; } p { font-size:large; } a:hover { } #wrapper { width: 980px; margin: 0 auto; padding: 0; } /* Header */ #header { width: 980px; height: 280px; margin: 0 auto; padding: 0px; background: url(images/head!.png) no-repeat left top; } /* Logo */ #logo { float: right; margin: 0; padding: 0; } #logo h1, #logo p { margin: 0; padding: 10px; } #logo h1 { float: left; padding-top: 223px; letter-spacing: -1px; text-align: right; text-transform: capitalize; font-size: 3.8em; color: purple; } #logo p { float: left; margin: 0; padding: 250px 0 0 10px; font: normal 20px Arial, Helvetica, sans-serif; font-style: italic; color: purple; } #logo a { border: none; background: none; text-decoration: none; color: black; } /* Search */ #search { float: right; width: 280px; height: 60px; padding: 20px 0px 0px 0px; background: #E2E2E2; border-bottom: 4px solid #FFFFFF; } #search form { height: 41px; margin: 0; padding: 10px 0 0 20px; } #search fieldset { margin: 0; padding: 0; border: none; } #search-text { width: 170px; padding: 6px 5px 2px 5px; border: 1px solid #DEDEDE; background: #FFFFFF; text-transform: lowercase; font: normal 11px Arial, Helvetica, sans-serif; color: #5D781D; } #search-submit { width: 50px; height: 22px; border: none; background: #B9B9B9; color: #000000; } /* Menu */ #menu { width: 980px; height: 90px; margin: 0 auto; padding: 0; } #menu ul { margin: 0; padding: 50px 0px 0px 0px; list-style: none; line-height: normal; } #menu li { float: left; } #menu a { display: block; width: 100px; height: 30px; margin-right: 1px; padding: 9px 0px 0px 0px; background: url(images/img02.gif) no-repeat left top; text-decoration: none; text-align: center; font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #FFFFFF; border: none; } #menu a:hover, #menu .current_page_item a { text-decoration: none; } #menu .current_page_item a { padding-left: 0; } /* Page */ #page { width: 940px; margin: 0 auto; padding: 0px 0px 0px 40px; background: url(images/img03.gif) repeat-y left top; } #page-bgtop { padding: 20px 0px; } #page-bgbtm { } /* Content */ #content { float: left; width: 580px; padding: 30px 0px 0px 0px; } .post { background: url(images/img07.gif) no-repeat left 50px; margin-bottom: 15px; } .post-bgtop { } .post-bgbtm { } .post .title { height: 38px; margin-bottom: 10px; padding: 12px 0 0 0px; letter-spacing: -.5px; color: #000000; } .post .title a { color: #023848; border: none; } .post .meta { margin-bottom: 30px; padding: 5px 0px 15px 0px; text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; } .post .meta .date { float: left; } .post .meta .posted { float: right; } .post .meta a { } .post .entry { background: url(images/img08.gif) no-repeat left top; padding: 0px 0px 20px 0px; padding-bottom: 20px; text-align: justify; } .links { padding-top: 20px; font-size: 12px; font-weight: bold; } /* Sidebar */ #sidebar { float: right; width: 280px; margin: 0px; padding: 0px 20px 0px 0px; color: lightgray; } #sidebar ul { margin: 0; padding: 0; } #sidebar li { margin: 0; padding: 0; } #sidebar li ul { margin: 0px 0px; padding-bottom: 30px; } #sidebar li li { line-height: 35px; border-bottom: 1px dashed #D1D1D1; margin: 0px 30px; border-left: none; } #sidebar li li span { display: block; margin-top: -20px; padding: 0; font-size: 11px; font-style: italic; } #sidebar h2 { height: 38px; padding-left: 30px; letter-spacing: -.5px; font-size: 1.8em; } #sidebar p { margin: 0 0px; padding: 0px 30px 20px 30px; text-align: justify; } #sidebar a { border: none; } #sidebar a:hover { text-decoration: underline; color: #8A8A8A; } /* Calendar */ #calendar { } #calendar_wrap { padding: 20px; } #calendar table { width: 100%; } #calendar tbody td { text-align: center; } #calendar #next { text-align: right; } #dtable { font-size:small; color:black; } #dtable>h1 { background: #F1F1F1; } #table { font-size:small; color:black; text-align:center; width:200px; } #table1 { font-size:small; color:black; text-align:center; width:200px; border: 1px solid black; table-layout: fixed; } th, td { border: 1px solid black; overflow:hidden; width: 100px; } /* Footer */ #footer { height: 50px; margin: 0 auto; padding: 0px 0 15px 0; background: #ECECEC; border-top: 1px solid #DEDEDE; font-family: Arial, Helvetica, sans-serif; } #footer p { margin: 0; padding-top: 20px; line-height: normal; font-size: 9px; text-transform: uppercase; text-align: center; color: #A0A0A0; } #footer a { color: #8A8A8A; }I am completely baffled as to why the widths of the columns does not change when I try to fix the widths. They are all the same size? Please enlighten me where I am going wrong? I have a table of restaurant menu items called menu_items. This table has a float row(3,2) called price. I have a query that looks like this: $query = mysql_query("SELECT * FROM menu_items WHERE restaurant = '".$restaurantid."'"); How would I find the average of the price row from that query? Basically I want to find the average item price for a restaurants menu. Hello Guys.
I am having a trouble viewing a specific column content both in phpMyAdmin and console.It only shows a partial info about the contents inside that column.
I have attached a screenshot of this to give you a demonstration inside that link:
http://i59.tinypic.com/2n6ymqf.jpg
as you can see , the user picked hamburger ,steak and ground beef (and some more), but it seems that it stops showing it right in the middle of the word. Is there any limit for characters in this case?
What would be possible to figure that out please?
Thanks in advance..
Edited by osherdo, 17 December 2014 - 09:11 PM. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=313840.0 Hi everyone, I'm having real problems trying to retrieve database records in a 3 column layout, I got there eventually with a huge amount of help. Unfortunately the code will only display records that are divisable by by three; for example for a database table that has 45 records there is no problem, as all records can be displayed in a 3 column layout. However if the table contains 47 records it won't display the 2 odd records. My php skills are limited so I need all the help I can get. I'm a bit desperate to sort this out for a project I'm doing, any help would be greatly appreciated - here is the php code: $total = count($records); $nocol = 3; $norows = $total / $nocol; for ($i=1; $i <= $norows; $i++) { $cell = 0; echo "<tr>"; for($col=1; $col <= $nocol; $col++) { echo "<td>"; if ($col == 1) { $cell += $i; echo '<strong class="navtext">'.$records[$cell - 1]['ret_name'].'</strong><br />'; echo $records[$cell - 1]['ret_add1'].'<br />'; echo $records[$cell - 1]['ret_add2'].'<br />'; echo $records[$cell - 1]['ret_town'].'<br />'; echo $records[$cell - 1]['ret_county'].'<br />'; echo $records[$cell - 1]['ret_pcode'].'<br />'; echo $records[$cell - 1]['ret_phone'].'<br />'; echo $records[$cell - 1]['ret_email'].'<br />'; echo $records[$cell - 1]['ret_web'].'<br />'; } else { $cell += $norows; echo '<strong class="navtext">'.$records[$cell - 1]['ret_name'].'</strong><br />'; echo $records[$cell - 1]['ret_add1'].'<br />'; echo $records[$cell - 1]['ret_add2'].'<br />'; echo $records[$cell - 1]['ret_town'].'<br />'; echo $records[$cell - 1]['ret_county'].'<br />'; echo $records[$cell - 1]['ret_pcode'].'<br />'; echo $records[$cell - 1]['ret_phone'].'<br />'; echo $records[$cell - 1]['ret_email'].'<br />'; echo $records[$cell - 1]['ret_web'].'<br />'; } echo"</td>"; } echo"</tr>"; } I'm also trying to paginate the results, is this actually possible when using a three column layout? I look forward to any suggestions. |