473,466 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

showing data from mysql in horizontal manner using php and html

Vkas
78 New Member
I had one problem in php

below is the code which fetches campus id and campus name form the mysql database and store them in two variables and using while loop i had fetch all the records from the Related table (Campus) by the code below
Expand|Select|Wrap|Line Numbers
  1.                                              <?php
  2. $query="SELECT * FROM campuses ORDER BY campus_id ASC"; 
  3. $result=mysql_query($query) or die(mysql_error());
  4. $rClr="ffffff";
  5.               while($row=mysql_fetch_array($result)) {
  6.                if($rClr=="ffffff"){
  7.               $rClr="F7F7F7";
  8.               }else{
  9.               $rClr="ffffff";
  10.               }    
  11.               $campid= $row['campus_id'];
  12.               $campnam= $row['campus_name'];
  13.  
  14. ?>
  15.  
Below is the HTML embedded code that i want to repeat
its a HTML table in which each campus name is fetched and shown and loop repeats itself until the last record is fetched

Expand|Select|Wrap|Line Numbers
  1.  
  2. <tr>
  3.                        <td align="center" valign="middle"><table width="260" border="0" cellpadding="2" cellspacing="2">
  4.                           <tr>
  5.  
  6.                             <td align="center" valign="middle"  style="background-repeat:no-repeat;"  class="Eventheading"><a href="eventsdetail.php?camp_id=<?php print $campid?>&amp;campus_name=<?php print $campnam ?>" class="Eventheading" ><?php echo $row['campus_name'];?></a></td>
  7.  
  8.                          </tr>
  9.                         </table></td>
  10.  
  11.  
  12.                       </tr>
  13.  
  14.  
ending tag of the loop

Expand|Select|Wrap|Line Numbers
  1.     <?php }?> 

My problem is that the loop always repeat the content vertical mean row wise

such as
( campus name 1
Campus name 2
campus name 3 )
but i want it to be shown horizontally

LIke this ( campus name 1 Campus name 2 campus name 3)


any idea can any one
Mar 31 '10 #1
4 9795
Mayur2007
67 New Member
Hello Vkas,

You have to generate tr conditionally like below
Expand|Select|Wrap|Line Numbers
  1. if($counter % 5 == 0) {
  2. echo "</tr><tr>"
  3.  
<td><table>......</table></td>
the counter variable will be set to zero before while loop and incremented in the loop.

Hope this will help you.

Thanks & Regards,
Mayur Bhayani
Mar 31 '10 #2
Vkas
78 New Member
mean you want to say that

Expand|Select|Wrap|Line Numbers
  1. if($counter % 5 == 0) {
  2.  echo "</tr>
  3.  
  4. Remain content!!!!! here
  5. <tr>"
  6.  } 
Apr 2 '10 #3
Vkas
78 New Member
this process works!!!
but in this it tries to show all of the record in a single row by dividing that single row in several columns

i want o display
Campus name1 Capmus name 2 Campus name 3

three values in a row
Apr 2 '10 #4
Vkas
78 New Member
i had almost done let me explain you again

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.       <?php
  3. $query="SELECT * FROM campuses ORDER BY campus_id ASC"; 
  4. $result=mysql_query($query) or die(mysql_error());
  5. $rClr="ffffff";
  6.               while($row=mysql_fetch_array($result)) {
  7.                if($rClr=="ffffff"){
  8.               $rClr="F7F7F7";
  9.               }else{
  10.               $rClr="ffffff";
  11.               }    
  12.               $campid= $row['campus_id'];
  13.               $campnam= $row['campus_name'];
  14.  
  15. ?>    
  16.        <!-- BEGIN Grid range_menu -->
  17. <div id="horiz">
  18. <!-- BEGIN Row --><td align="center" valign="middle"><table width="248" border="0" cellpadding="2" cellspacing="0">
  19.   <tr>
  20.  
  21.     <td width="248" height="69" align="center" valign="middle" background="http://bytes.com/images/eventsbg.jpg"  style="background-repeat:no-repeat;"  class="Eventheading"><a href="eventsdetail.php?camp_id=<?php print $campid?>&amp;campus_name=<?php print $campnam ?>" class="Eventheading" ><?php echo $row['campus_name'];?></a></td>
  22.   </tr>
  23.  
  24. </table></td> 
  25. </div>
  26.       <?php }?>                   <td align="center" valign="middle">&nbsp;</td>
  27.   </tr>
  28.  
i have implemented the while loop like this

table
inside table row
created a div and repeted the <td> from the above code


i had achieved the target that it repeats the table column but it reapers all the column in a single row which disturbs the whole page layout

i want this that it should only show three records in a single row and then repeats the row also !!!


please any of the person that can give guideline
Apr 3 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Peter Mount | last post by:
Hi When I zoom into my site (http://www.petermount.au.com) with Opera 7.54 the horizontal scrollbar doesn't show when the site image is bigger than my screen. Yet the horizontal scrollbar shows...
2
by: Sam White | last post by:
I have set up a MySQL db on one server, IIS 6.0 on another. Using Frontpage I created some forms to input data. On a test page I made, I have 4 fields. First is the ID which is autonumber (I leave...
1
by: Gh! | last post by:
How can I see how much disk space is being occupied by an InnoDB table? Looking into /var/lib/mysql doesn't seem to work anymore for InnoDB tables. Please tell also if there is a way to see how...
10
by: lothar | last post by:
for the horizontal rule element, the w3c HTML 4.01 specification http://www.w3.org/TR/html4/cover.html states that the align, noshade, size and width attributes are deprecated. it gives an...
1
by: Rich | last post by:
Hello, I am trying to draw a graph on a form. I can draw the box using drawline, and bars inside the box using drawrectangle, but when I try to draw a line inside the box the inner lines are...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
1
by: Shiraz | last post by:
i did "select * into outfile 'data.sql' from CDRS" to backup my data. what is the reverse to get the data back in? it looks liek the fields are delimited by tabs in the file. tjanks
1
by: dbalan | last post by:
I have excel file where the data is in horizontal manner. I have an output in access table, in vertical manner. I have a snap shot of data which I would like to attach which better describes my...
2
by: sunadumari | last post by:
Hi, I'm using a database (mysql) called by php. The data is put in the $key variable. This $key includes some html-code such as <B> or <BR> which I want to show not as <BR> but as html (wysisyg)....
5
by: rahullko05 | last post by:
Hi, I am developing forum website as my final year project. I am having problem in generating different URLs but keeping the same page.. Scenario: I am showing threads for different languages in...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.