PHP - Print On Two Columns
I'm working on a site where I've implemented a simple back end wysiwyg editor for content on a page. Then on the public page I run a php query to pull that content and display it. But doing this cancels out the css I have been using to split content into two columns. Is there a way to do this in php, or is there a way to circumvent the problem? ( also tried echoing the entire css style along with the query result - that didn't work either)
The <p id='container_sub'> is what is split into two columns. I tried it outside of the query, and inside the query around where I echo results. Neither worked. Here's the basic php code, and further down the css that makes two columns: Code: [Select] <?php $pageid = '2'; // Formulate Query // This is the best way to perform an SQL query // For more examples, see mysql_real_escape_string() $query = sprintf("SELECT content FROM tbl_pages WHERE page_id='%s'", mysql_real_escape_string($pageid)); // Perform Query $result = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } // Use result // Attempting to print $result won't allow access to information in the resource // One of the mysql result functions must be used // See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc. while ($row = mysql_fetch_assoc($result)) { echo "<p id='container_sub'>".$row['content']."</p>"; } // Free the resources associated with the result set // This is done automatically at the end of the script mysql_free_result($result); ?> The css.... Code: [Select] #container_sub {-moz-column-count: 2; -moz-column-gap: 25px; -webkit-column-count: 2; -webkit-column-gap: 20px; column-count: 2; column-gap: 20px;} #container_sub2 {-moz-column-count: 2; -moz-column-gap: 25px; -webkit-column-count: 2; -webkit-column-gap: 20px; column-count: 2; column-gap: 20px;} Similar TutorialsWhat 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> Is there a way to echo the results of a query as separate columns as opposed to one under the other? This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=359199.0 I have a 2 part question i hope is an easy Fix, i know very little about any of this, I have a list of teams that shows up and is is showing in ONE long column, i want to do to things, Make it multiple columns & sort alphabetically like this: 123 456 789 Here is the link to the test page right now http://tspclan.com/SS/test.php And the page code (top half of it anyways) Code: [Select] <?php require_once("global.php"); $id = htmlentities($_GET['id']); $order = mysql_real_escape_string($_GET['order']); if($order == "levela") { $order = "ORDER BY `defwin` ASC"; $l_pre = "<a href='?id=$id&order=leveld'>"; $l_suf = "</a>"; } elseif($order == "leveld") { $order = "ORDER BY `defwin` DESC"; $l_pre = "<a href='?id=$id&order=levela'>"; $l_suf = "</a>"; } else { $order = "ORDER BY `defwin` DESC"; $l_pre = "<a href='?id=$id&order=levela'>"; $l_suf = "</a>"; } $team = mysql_query( "SELECT * FROM `teams` WHERE `id`='".$id."'"); $t = mysql_fetch_array($team); $team_title = mysql_real_escape_string($t['title']); $t_tag = $t['tag']; $page1 = $t['page1']; $user = mysql_query( "SELECT * FROM `users` WHERE `team`='".$id."' $order"); ?> <script src="http://tspclan.com/js/fbid.js" type="text/javascript"></script> <script src="http://tspclan.com/js/pid.js" type="text/javascript"></script> <script src="http://tspclan.com/js/sorttable.js" type="text/javascript"></script> <title><?php echo $team_title; ?></title> </head> <link href="http://tspclan.com/mkportal/templates/TSP/style.css" rel="stylesheet" type="text/css" /> <body> <div align="center"> <?php if(mysql_num_rows($team) == false) { $team2 = mysql_query( "SELECT * FROM `teams`"); ?> <table width="100%" border="0" class="unsortable" cellspacing="0" cellpadding="0"> <tr> <td background="img/hdr_left.jpg"> </td> <td width="590"><div align="center"><img src="img/hdr.jpg" width="590" height="346" /></div></td> <td background="img/hdr_right.jpg"> </td> </tr> </table> <br><br> <table width="250" cellspacing="0" class="unsortable" cellpadding="5" border="0" id="mwid"> <tr> <td align="center" valign="top" class="index_title unsortable" col span="3" >Team Name</td> </tr> <?php while($t2 = mysql_fetch_array($team2)) { $t_name = "<a style='font-weight:bold; font color:#333333;' href='?id=".$t2['id']."'>".$t2['title']."</a>"; echo " <tr> <td valign='top' align='center' width='50' class='row1 b_t' style='border-bottom:none; width:5px; background-color:#333333;'>".$t_name."</td> "; } ?> 2nd Part of my question, When i call for a team my link is test.php?id=(team id) Is there a way to bring up multiple teams at the same time? I am editing code to get sku numbers, for now it just prints as below: SKU: 123 SKU: 322 SKU: 444 SKU: 555 SKU: 666 I want to put them in columns so it prints as: SKU: 123 SKU: 322 SKU: 444 SKU: 555 SKU: 666 etc. etc. So it is devided into 4 columns. The code that controls is: Code: [Select] <?php if (is_array($order->products)) { $context = array( 'revision' => 'formatted', 'type' => 'order_product', 'subject' => array( 'order' => $order, ), ); foreach ($order->products as $product) { $price_info = array( 'price' => $product->price, 'qty' => $product->qty, ); $context['subject']['order_product'] = $product; $context['subject']['node'] = node_load($product->nid); ?> <?php echo $product->model; ?><br /> <?php } }?> i would appreciate some help Hi, I have a piece of code which I trying to search two columns but I just cant get it to work. Instead it just dumps around 30 entries onto the page. Can anyone point me in the direction of how to search two columns? Code: [Select] $query = "SELECT * FROM questions"; if(isset($_GET['question']) && !empty($_GET['notes'] )) { /*query the database*/ $question = $_GET['question']; $notes = $_GET['notes']; $query .= " WHERE question && notes like '%$question%' LIMIT 0, 10"; } $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $question = $row['question']; $notes = $row['notes']; echo "$question $notes </br>"; } Hello - hope you are all well.
I am creating a website for a family friend who has a shop. See preview of the site in this picture ....
Picture1.jpg 40.32KB
0 downloads
Currently the results are showing in one column. I want to show them in three columns in the format of:
1 2 3
4 5 6
7 8 9 etc
But formatted with the picture and then the title and the border.
The current code i have is....
HEAD
<?php
$sql = "SELECT * FROM abs_productcat WHERE catid = $catid ORDER BY catid ASC"; $can = mysql_query($sql); $catname = mysql_fetch_assoc($can); ?> BODY <?php while ($row_pro = mysql_fetch_assoc($rs_proddetails)) { ?><tr> <td><table width="243" border="0" align="left" cellpadding="15" cellspacing="0" class="sectionborders"> <tr> <td height="120" align="center"><p><strong><a href="indproducts.php?ProductID=<?php echo $row_pro['ProductID']; ?>"><img src="products/product_<?php echo $row_pro['ProductID']; ?>" alt="<?php echo $row_pro['ProductName']; ?>" height="120" class="sectionborders" border="0" /></a></strong></p> <p><strong><a href="indproducts.php?ProductID=<?php echo $row_pro['ProductID']; ?>" class="products"><?php echo $row_pro['ProductName']; ?></a></strong></p></td> </tr> </table></td> </tr> <tr> <td> </td> </tr> <?php } ?> THANK YOU FOR YOUR HELP!!! i have this code but it shows the password of the user to... Code: [Select] <?php $database="dynamicg_sites"; mysql_connect ("localhost","dynamicg_sites","boom123"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT * FROM sites order by votes DESC" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<br>\n"; print "There are $num_rows News Articles"; print "<br>\n"; print "<table width=457 border=0>\n"; print "<tr>\n"; print "<td>\n"; echo "Title:"; print "</td>\n"; print "<td>\n"; echo "Description:"; print "</td>\n"; print "<td>\n"; echo "Votes:"; print "</td>\n"; print "</tr>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=2/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; print "<br />\n"; print "<br />\n"; ?>i was wondering how do i make this only show certain columns... thanks in advance... Hi, having stopped php for a while, i'm a little rusty, can someone help me - instead of the results returning in a row by row format, can i have it so it returns column by column? so, rather than result 1 being first, then 2 underneath then 3 etc etc, can i have result 2 next to result 1? heres my code $result = mysql_query("SELECT * FROM members ORDER BY member_id DESC") or die(mysql_error()); echo "<table border='2'>"; echo "<tr> <th></th> <th></th> <th></th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row[printf('<img src="%s" height="96" width="128" style="border: 0" />', $row['profile_pic_short'])]; echo "</td><td>"; echo "<a href=\"PHP-Login/advert_pages/view_profile_specific.php?seller_name=$row[login]\">". $row['login'] . "</a>"; echo "</td></tr>"; } echo "</table>"; ?> all help appreciated thanks Hi! I have a table called "Categories" Here is the structu id | Categories | ParentCategories 1 | Rings | Parent Category 2 | Pendants | Parent Category 3 | Ladies Rings | Rings 4 | Ladies Pendants | Rings 5 | Gents Rings | Gents 6 | Necklaces | Parent Category But Necklaces is one of those who is not going to have any subcategories or you can say, it is going to be a category by itself. So how can I construct a php statement to get data out of MySQL to determine that Necklaces is a Category which does not have subcategories. Please help ! Thank you ! - Xeirus. Hey guys, I have made an array where only the name shows up, but I want the price next to it. I adapted the query, but how do I need to adapt the array? peace Code: [Select] <?php // connect to your database $DrinkArray=array() ; $DrinkResult=mysql_query("SELECT name,price FROM products")or die(mysql_error()); while($DrinkRow=mysql_fetch_assoc($DrinkResult)){ $DrinkArray[]=$DrinkRow['name']; } //check your output with something like this foreach($DrinkArray as $value){ echo $value.'<br />'; } ?> I have a page that displays a list of retail locations (est. 100-150 locations). I have my layout setup to fit 3 columns side by side. Ex: <div class="col"></div> <div class="col"></div> <div class="col"></div> .. with the "col" class having a specific width and float: left. Basically, I want to print out the locations in the column and when a column reaches a certain number of locations, it closes that div and starts a new one and continues printing the rest of the locations. How would I go about making sure that once a column has reached a certain number of locations, it closes the div and starts the new one? Hi all, This application is given me a nightmare. The code fetches root categories and its sub categories from the a database table. The div table have only 2 columns. I want to add 2 extra columns so that I have 4 columns. Because we have a long list of subcategories meaning I have to scroll down to view the category. Please help Code: [Select] {include file='t_javascript_language.tpl'} {set_css} {set_js} <!--<div class="componentheading">{$page_title}</div>--> <div class="adds_man_list"> <span>{$category_pathway}</span> {if $current_category->catname!=""} <div style="border:2px solid #000;"> {include file='elements/display_fields.tpl' position='categoryicon' this_add=$current_category->id} <strong>{$current_category->catname}</strong> <div class="adds_subcat" style="text-align:right;background:#F5F5F5; border:1px solid #FFFFFF; " > {include file='elements/display_fields.tpl' position='categorydetails' this_add=$current_category->id} <span style="font-size:12px;"> {jtext text="ADS_SUBCATEGORIES"}: {$current_category->kids} {jtext text="ADS_ADS"}: {$current_category->nr_ads} <a href="{$current_category->view}" title="{jtext text='ADS_VIEW_LISTINGS'}"> <img src="{$IMAGE_ROOT}view_listings.gif" class="ads_noborder" alt="{jtext text='ADS_VIEW_LISTINGS'}" /> </a> </span> </div> </div> {/if} {if $categories|@count<=0} <h2>{jtext text="ADS_NO_CATEGORIES_DEFINED"}</h2> {/if} <table id="adds_categories" class="ads_table"> {section name=category loop=$categories} {if $smarty.section.category.rownum is odd} <tr> {/if} <td width="50%" class="adsman_catcell" valign="top"> <div class="adds_maincat" {if $categories[category]->watchListed_flag}class="cat_watchlist"{/if}> {include file='elements/display_fields.tpl' position='categoryicon' this_add=$categories[category]->id} <a href="{if $categories[category]->kids>0}{$categories[category]->link}{else}{$categories[category]->view}{/if}" > {$categories[category]->catname} </a> {if $categories[category]->is_new} <!--NEW!!--> <img src="{$IMAGE_ROOT}new.png" alt="new ads" /> {/if} <a href="{$categories[category]->view}" title="{jtext text='ADS_VIEW_LISTINGS'}"> <img src="{$IMAGE_ROOT}view_listings.gif" class="ads_noborder" alt="{jtext text='ADS_VIEW_LISTINGS'}" /> </a> {if $is_logged_in} {if $categories[category]->watchListed_flag} <img src="{$IMAGE_ROOT}watchlist.png" width="16"class="ads_noborder" /> {/if} <a href="{$categories[category]->link_watchlist}"> <img src="{$categories[category]->img_src_watchlist}" width="16" class="ads_noborder" title="{if $categories[category]->watchListed_flag}{jtext text='ADS_REMOVE_FROM_WATCHLIST'}{else}{jtext text='ADS_ADD_TO_WATCHLIST'}{/if}"/> </a> {/if} <br /> </div> <div class="adds_subcat" style="background:#F5F5F5; border:1px solid #FFFFFF; " > {include file='elements/display_fields.tpl' position='categorydetails' this_add=$categories[category]->id} <br /> {section name=subcategory loop=$categories[category]->subcategories} {include file='elements/display_fields.tpl' position='categoryicon' this_add=$categories[category]->subcategories[subcategory]->id} <a href="{if $categories[category]->subcategories[subcategory]->kids>0}{$categories[category]->subcategories[subcategory]->link}{else}{$categories[category]->subcategories[subcategory]->view}{/if}">{$categories[category]->subcategories[subcategory]->catname}</a> {if $categories[category]->subcategories[subcategory]->is_new==1} <img src="{$IMAGE_ROOT}new.png" alt="new ads" /> {/if} ({$categories[category]->subcategories[subcategory]->nr_a} {jtext text="ADS_ADS"}) {if $categories[category]->subcategories[subcategory]->watchListed_flag} <img src="{$IMAGE_ROOT}watchlist.png" width="16" class="ads_noborder" /> {/if} {if $is_logged_in} <a href="{$categories[category]->subcategories[subcategory]->link_watchlist}"> <img src="{$categories[category]->subcategories[subcategory]->img_src_watchlist}" width="14" class="ads_noborder" title="{if $categories[category]->subcategories[subcategory]->watchListed_flag}{jtext text='ADS_REMOVE_FROM_WATCHLIST'}{else}{jtext text='ADS_ADD_TO_WATCHLIST'}{/if}"/> </a> {/if} <br /> <p style="margin-left:25px;"> {include file='elements/display_fields.tpl' position='categorydetails' this_add=$categories[category]->id} </p> {/section} </div> </td> {if $smarty.section.category.rownum is not odd} </tr> {/if} {/section} </table> </div> Many thanks Hello.
i am totally new to php and just started to learn now. i just dont understand why the following code is not printing the username that i enter on the page.
Please note that the code itself is saved with the name "basicForm.php".
Thanks.
<html> Hello, How to customize print page in php ? I had a page, but I need to print it like an invoice look page. Thanks in advance Code: [Select] $query ="SELECT oneID FROM table WHERE table.PersonID = 'game.PlayerA'" ; $result = mysql_query($query); $row = mysql_fetch_array($result); $oneID = $row[0]; [code] If I then echo "$oneID" why does it not print anything? $result echos resource7 I have a table that holds a set of matches in a football (soccer) league. On a teams individual page I want to show just their matches and am very close to getting it right but just cannot get there! I am using 2 tables for this.... teams team_id team_name 1 TEAM1 2 TEAM2 3 TEAM3 4 TEAM4 and all_games game_id home_team home_score away_team away_score 1 1 2 2 0 2 3 0 4 1 3 4 2 1 1 4 2 0 3 0 Both 'home_team' and 'away_team' are foreign keys to teams.team_id. The query that I have used to almost get it working is SELECT * FROM all_games, teams WHERE '%s' IN (home_team, away_team ) AND all_games.home_team=teams.team_id And the html is Code: [Select] <tr> <td>all_games_id</td> <td>home_team</td> <td>home_goals</td> <td>away_team</td> <td>away_goals</td> </tr> <tr> <td><?php echo $row_all_games['all_games_id']; ?></td> <td><?php echo $row_all_games['team_name']; ?></td> <td><?php echo $row_all_games['home_goals']; ?></td> <td><?php echo $row_all_games['team_name']; ?></td> <td><?php echo $row_all_games['away_goals']; ?></td> </tr> This pulls the correct games into the page but will show the 'home_team.team_name' as both 'home_team' and 'away_team'. For example the page for TEAM1 shows up as match_id home_team home_score away_team away_score 1 TEAM1 2 TEAM1 0 3 TEAM4 2 TEAM4 1 What it should show is match_id home_team home_score away_team away_score 1 TEAM1 2 TEAM2 0 3 TEAM4 2 TEAM1 1 Obviously in the current query there is nothing to show that the 'away_team' is also equal to 'teams.team_id'. I have tried this query SELECT * FROM all_games, teams WHERE '%s' IN (home_team, away_team ) AND (all_games.home_team=teams.team_id OR all_games.away_team=teams.team_id) But this gives the exact opposite result with just the 'away_team.team_name' showing up as 'home_team' and 'away_team' match_id home_team home_score away_team away_score 1 TEAM2 2 TEAM2 0 3 TEAM1 2 TEAM1 1 while SELECT * FROM all_games, teams WHERE '%s' IN (home_team, away_team ) AND (all_games.home_team=teams.team_id AND all_games.away_team=teams.team_id) throws up an empty query. Does anyone have any suggestions on how this can be done? I have exhausted my patience with Google simply as I do not know what the correct search term is. As an aside, when I do get it working, I want the format on the page to be slightly different in that instead of showing both home_team and away_team names I would want it to show "H" if the team in question is the 'home_team' and "A" if it is the 'away_ team' plus the name of the team that they played and whether the 'home_score' or 'away_score' belonged to them, as well as whether they won, drew or lost the game. So, staying with the page for TEAM1 it would show as MATCH ID HOME or AWAY OPPONENT W/D/L SCORE FOR SCORE AGAINST 1 H TEAM2 Won 2 0 3 A TEAM4 Lost 1 2 I am currently planning on doing this with IF statements in the html, something along these lines if home_team = %s echo "Home" else echo "Away" and if home_team = %s AND home_score>away_score echo "Won" else if away_team = %s and away_score>home_score echo "Won" else if home_score= away_score echo "Drew" else echo "Lost If anyone can think of a better way to do this ( I am naturally assuming that it would not work in the way I intend!)I would be extremely greatful too! Thanks in advance for any advice, pointers or offers to write the whole code!!! Steve I have this code which works fine. I want to improve it by displaying it into multiple columns. Current output: TITLE 1 JOB1 --------- TITLE 2 JOB 2 --------- ETC... I want it to display like this instead: TITLE 1 | TITLE 2 JOB 1 | JOB 2 Here is my code: $sql = "SELECT * FROM coaches WHERE position = 'Junior Coach'"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)){ $id = $row["id"]; $firstname = $row["firstname"]; $lastname = $row["lastname"]; $position = $row["position"]; $image = $row["image"]; ?> <table width="183" border="1"> <tr> <td align="center" height="18"> <?php echo "<img id='image_shadowCoaches' src=" . $image . ">"; ?><br /> <?php echo "<div id='Coaches_Detail'>".$firstname." ".$lastname."</div>" ?> <?php echo "<div id='Coaches_DetailLower'>".$position."</div>" ?> </td> </tr> </table> <?php } ?> i have a file called filename.txt with the csv as below Date,cet,predict,16d Wed 02/15 @ 12Z,0.7,3.4,x Wed 02/15 @ 18Z,0.7,3.3,x Thu 02/16 @ 00Z,0.7,3.3,x Thu 02/16 @ 06Z,1.1,3.7,x Thu 02/16 @ 12Z,1.1,3.7,x i would like the date to be replaced by numbers 1,2,3... and to be an array, and also the 2nd value in each row to be an array. the number of rows is not fixed and grows day by day. so the result would be (1,2,3,4,5) and (0.7,0.7,0.7,1.1,1.1). can someone please help? i guessed that some sort of loop is needed to go through row by row, adding values to an array. I have tried the following with no success: Code: [Select] // get data from the file $data = file_get_contents('filename.txt'); // use the newline as a delimiter to get different rows $rows = explode("\n", $data); // go through all the rows starting at the second row // remember that the first row contains the headings for($i = 1; $i < count($rows); $i++){ $temp = explode(',', $rows[$i]); $date = $temp[0]; $cet = $temp[1]; $stack = array($stack); array_push($stack, $cet);} print_r ($stack); |