PHP - Columns
Is there a way to echo the results of a query as separate columns as opposed to one under the other?
Similar TutorialsHi, 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 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=359199.0 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>"; } 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 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 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... 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? 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? 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. 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'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;} Hey guys, I wrote a code for displaying images in columns, but for some reason it's not working. Can you take a look and tell me what I'm doing wrong? $i = 0; if($i % 4 == 0){ echo ' <td width="25%" align="center" valign="top"> <a href= "'.$slika_velika.''.$slika_v.'" rel="lytebox" title="'.$naziv.' - '.$mjesto.' - '.$medalja.'" target="_blank"><img src="'.$slika_mala.''.$slika_m.'"width="200" height="150" border="0"></a><br> </td> <td width="25%" align="center" valign="top"> '.$naziv.' - '.$mjesto.' </td> <td width="25%" align="center" valign="top"> '.$medalja.' </td><br /> '; echo '</tr><tr>'; } $i++; } The output I'm getting now is one image below another. I would like to display them one next to another. Please help!!! I can not figure this out... <?php include 'include/config.php'; $sql = mysql_query(" SELECT * FROM logos "); while($row = mysql_fetch_assoc($sql)) { echo $row['image']; echo "<br />"; } ?> now that is printing a nice list now how can I just split it into two columns? I'm wanting to output data into two columns. I've searched for this in a few places. A vast majority of the search results deal with getting data from multiple columns, and the the ones that deal with what I'm looking for don't really have any solutions attached to them. I'm not fully worried about the columns being equal length. The data is broken up into a certain number of rows in a given year. I have about 12 years, probably 6-8 rows per year. I just don't know how to get it into different columns. I don't care if it goes left to right then down or down then left to right. If there has been a solution to that here already, feel free to point me in that direction. Point me in any applicable direction, I'd fine with. I just can't locate anywhere what trigger would cause that. I have some code that selects one column from mysql table. However when I try to add more it doesn't work.
First the working code....
$query = "SELECT `profile_privacy` FROM `users` WHERE `user_username` = '$username'"; $result = mysql_query($query) or die($query."<br/><br/>".mysql_error()); $profile_privacy = mysql_result($result, 0);And here is where I have added another column.... $query = "SELECT `profile_privacy`, `profile_pictures` FROM `users` WHERE `user_username` = '$username'"; $result = mysql_query($query) or die($query."<br/><br/>".mysql_error()); $profile_privacy = mysql_result($result, 0); $profile_pictures = mysql_result($result, 1);What have I done wrong? Many thanks, Hi,
I am trying to make a list of all countries listed in a database and the number of times they appear. But I am clearly doing something wrong as I am not able to list out the number of times that they appear.
This is what I have got so far:
<h4>Countries</h4> <table><col width='150px'><col width='150px'> <tr> <th> Country </th> <th> Number of Occurences </th> </tr> <?php $location = DB::getInstance()->query("SELECT country, COUNT(country) as countCountry FROM users GROUP BY country ORDER BY count DESC"); foreach ($location->results() as $locations) { echo "<tr><td>"; echo $locations->country; echo "</td><td>"; echo $locations->countCountry; echo "</td></tr>"; } ?> </table>Can anyone point me in the right direction? I have put together a new website and I am having a problem that is frustrating me to no end so I am here looking for expert help.
In my "content" column, I am trying to have the article I have written. This content is going to change from page to page depending on the amount of content. At the bottom of the "content" I am trying to add a comments section.
To the right of the "content" column I have a "sidebar" and the problem I am having is as the "content" column grows or shrinks, it is effecting the positioning of the "sidebar" and moves the content of the "sidebar" up or down.
I have tried to investigate how to correct this and what I have read makes absolutely no sense to me so the only way I can figure out to fix this (keeping in mind that I am in the process of teaching myself CSS and I use the trial and error method of learning) is to set the height of the "content" column to a fixed number and then force the "sidebar" to move up or down by using something like 'margin-top: -1200px". The problem with this is when comments are added, the content of the "sidebar" moves down.
My question is, does anyone know of a way to get both columns to adjust to equal heights that won't cause me to pull what little hair I have left out? Would that anyone be willing to explain to me why your method should work?
I know that I should include the code for the page I am having the problem with, but it is (in my opinion) pretty extensive and if someone is willing to try to tackle this it might be easier to just bring up the source code.
Just FYI . . . the page in question can be seen at http://pickmysmoker....ne_smokers.php/
Thanks in advance . . .
Hi there, This is what I need to do, blow that is the code I have knocked up to do it but it doesn't seem to work. The main problem is the query that matches the atc callsigns to the pilots destinations.. can't fathom it myself. 1. Pull all the records from my database. 2. Assign their unique user id's, callsigns and destinations. 3. Execute a query in which you: SELECT * FROM CLIENTS WHERE (The 'clienttype' = 'ATC') AND match the callsign of the ATC users to the 'planned_destairport' of the 'clienttype' = 'PILOT'. For example if three people are going to Heathrow, then it would return 3 results. 4. Then do a mysql_num_rows of the result. 5. Lastly, execute a query that would update the 'atcarrivals' collumn in the database with the count number using the unique 'cid' as the identifier. All in a loop of course. // Selects all of the ATC Records. $atc_arrivals_selectquery = mysql_query ("SELECT * FROM CLIENTS"); // Starts the loop for fetching the records of the previous query. while($atc_arrivals_row = mysql_fetch_array($atc_arrivals_selectquery)){ // Sets the users cid, planned_destairport and callsign. $atc_cid = $atc_arrivals_row['cid']; $atc_destinations = $atc_arrivals_row['planned_destaiport']; $atc_callysign = $atc_arrivals_row['callsign']; // Searches the database and selects all records where the callsign is LIKE the destination airport. $atc_arrivals_check = mysql_query("SELECT * FROM CLIENTS WHERE clienttype = 'ATC' AND callsign LIKE '%$atc_destinations'"); // Counts previous query results. $atc_arrivals_count = mysql_num_rows($atc_arrivals_check); // Updates the atcarrivals column with the count.. $atc_arrivals_updatequery = mysql_query("UPDATE CLIENTS SET atcarrivals = '$atc_arrivals_count' WHERE cid = '$atc_cid' AND clienttype = 'ATC'"); // End loop. } Concerned columns are these: "cid" - Unique client id. "atcarrivals" - Number of arrivals from count. (This is the problem.) "planned_destairport" - Destination airport of pilot. Usually four letters long. IE. EGLL = Heathrow. Thanks. |