473,378 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

[SOLVED] how to close td tr after every three mysql record ?

khalidbaloch
hi : all Friend i am a new member of this comunity as well in php myqsl
i want learn that how to dispaly three or two record from a mysql table
for example ..
mysql table category has 21 columns, and i wish to close html tag TD TR after ever three myqsl columns .the mysql record should be shown as bellow

record 1 record 2 record 3
record 4 record 5 record 6
record 7 record 8 record 9
record 10 record 11 record 12
record 13 record 14 record 15
record 16 record 17 record 18
record 19 record 20 record 21

i apologize for my poor english i dont know whether anyone of you will understand me what i meam to ask ..
Oct 6 '06 #1
11 3615
bevort
53
how about looping?

echo("<tr><td>");
echo( record 1);
echo( record 1);
echo( record 1);
echo("<tr><td>");

Then loop back again
Oct 6 '06 #2
ronverdonk
4,258 Expert 4TB
This should do it
[PHP]echo "<table">;
$i = 0;
while ($rec = mysql_fetch_assoc(....)) {
$i++;
switch $i {
case 1 : echo "<tr><td>" . $rec[$i] . "</td>";
break;
case 2 : echo "<td>" . $rec[$i] . "</td>";
break;
case 3 : echo "<td>" . $rec[$i] . "</td></tr>";
$i=0;
break;
}
}
if ($i < 3)
echo "</tr>";
echo "</table>";[/PHP]

Ronald :cool:
Oct 6 '06 #3
thanx for your reply ronald but i did not uderstand . i am a newbhi in php mysql .please show me an example by using a mysql databse strurture

Thanks againg in advance,

i hope you will undestand what i mean to say
Oct 15 '06 #4
ronverdonk
4,258 Expert 4TB
How can I do that since I don't know what you db structure looks like, or at least how your table row looks.

Ronald :cool:
Oct 15 '06 #5
sorry i forgot to tell my my database structure here is my database structure..

i have a table which holds two column ,,

table | columns |
category | Id ,name |
Here is the code (do not forget to fill in your own values for host, user, psw and db!).
[php]
$conn = mysql_connect("host", "user", "psw")
or die("Cannot connect to server: " . mysql_error());
mysql_select_db("db")
or die("Cannot select database: " . mysql_error());
$res = mysql_query("SELECT * FROM category")
or die("Select errro: " . mysql_error());
echo "<table">;
$i = 0;
while ($row = mysql_fetch_assoc($res)) {
$i++;
switch $i {
case 1 : echo "<tr><td>{$row['Id']}</td><td>{$row['name']}</td>";
break;
case 2 : echo "<td>{$row['Id']}</td><td>{$row['name']}</td>";
break;
case 3 : echo "<td>{$row['Id']}</td><td>{$row['name']}</td></tr>";
$i=0;
break;
}
}
if ($i < 3)
echo "</tr>";
echo "</table>"; [/php]
Oct 16 '06 #6
sorry to distrube you agian n again n again .but yet my problem is not solved.
i put the code given by you in ur last reply .and i changed the detabase variables accordingly.when i put these code in my php page and pointed my browser to to this.
i got this parse error .
Parse error: parse error, unexpected ';' in D:\wwwroot\faq\index.php on line 8..

however i was able to solve this error by my own ..
acctully the error was caused by misstype in line 8

echo "<table">;
and then i changed this to
echo "<table>";

after making changes . i retried to poined my browser to this page .
but even this time i was dissopointed . there was an other error on line 12 and this time .i could not solve the error ..
this was the error .
Parse error: parse error, unexpected T_VARIABLE, expecting '(' in D:\wwwroot\faq\index.php on line 12

please resovle my this problem ...hope i will be get the solution in last you next reply .. may god Bless you
Oct 17 '06 #7
sorry to distrube you agian n again n again .but yet my problem is not solved.
i put the code given by you in ur last reply .and i changed the detabase variables accordingly.when i put these code in my php page and pointed my browser to to this.
i got this parse error .
Parse error: parse error, unexpected ';' in D:\wwwroot\faq\index.php on line 8..

however i was able to solve this error by my own ..
acctully the error was caused by misstyping in line 8

echo "<table">;
and then i changed this to
echo "<table>";

after making changes . i retried and poined my browser to this page .
but even this time i was dissopointed . there was an other error on line 12..
and this time .i could not solve the error ..
this was the error .
Parse error: parse error, unexpected T_VARIABLE, expecting '(' in D:\wwwroot\faq\index.php on line 12 ..

after making neccesory changes the code looked like Bellow

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $conn = mysql_connect("localhost", "root", "mypass") 
  3.     or die("Cannot connect to server: " . mysql_error());
  4. mysql_select_db("faq") 
  5.     or die("Cannot select database: " . mysql_error());
  6. $res = mysql_query("SELECT * FROM category") 
  7.     or die("Select errro: " . mysql_error());
  8. echo "<table>";
  9. $i = 0;
  10. while ($row = mysql_fetch_assoc($res)) {
  11.   $i++;
  12.   switch $i {
  13.     case 1 : echo "<tr><td>{$row['Id']}</td><td>{$row['name']}</td>";
  14.              break;
  15.     case 2 : echo "<td>{$row['Id']}</td><td>{$row['name']}</td>";
  16.              break;
  17.     case 3 : echo "<td>{$row['Id']}</td><td>{$row['name']}</td></tr>";
  18.              $i=0;
  19.              break;
  20.   }
  21. }
  22. if ($i < 3) 
  23.    echo "</tr>";
  24. echo "</table>"; 
  25. ?>
Oct 18 '06 #8
ronverdonk
4,258 Expert 4TB
I expect you to know SOME PHP, how else can you make an apoplication like this?!!!
I have not tested it and there are , of course, some typing errors in it!
The error is in the switch statement, which should be (of course)
[PHP]switch ( $i ) {
[/PHP]

If you have problems with code like this, it is time you took a tutorial.

Ronald :cool:
Oct 18 '06 #9
Thanx You Very Much this is Done .Thanks a lote dear friend
Oct 18 '06 #10
trhanx alots ronald this done ,let me tell you that i have almost completed my first php application .its a faq system ,, when it is ready i will launch my first script in this site phpbuilder.ifastnet.com in order to know php better i i would use friends like you and comunuty like this .thanx alot for you sincer corporation ..
Oct 18 '06 #11
Modulus!!!
Oct 18 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Graham Mattingley | last post by:
Hello Group, I have had an issue on my server for a long time and what ever I have tryed I just cant fix it. I run mySQL and IIS, and my server will crash every few days because a file on the...
0
by: Jim S. | last post by:
I had this problem where a user would attempt to change a record, and always get the 'write conflict', and that another user had changed the record... even though no other users were on the...
6
by: Rey | last post by:
How can I update every record of a given table one by one. I need to update a field (date) with a different, random date for each record. loop { generate random date; update one record with...
8
by: Al Reynolds | last post by:
Afternoon, In an earlier thread (http://tinyurl.com/5v4aa), I described a problem I was having which was rather bizarrely solved by changing the line: "inputbox.value = numq+ag-cw-cc;" to:...
0
by: Vladimir Oľura | last post by:
I solved the problem. Here is what you have to do if your table has an autonumber field (like mine): 1. Make a new row with the NewRow Method: DataRow dr = dataTable.NewRow(); 2. Add the new...
2
by: Bruce Wiebe | last post by:
hi all im having a problem accessing a text file on my hard disk after ive created it and added some text to it it would appear that the file is still locked. What happens is this i have...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
6
by: Richard Hollenbeck | last post by:
Thanks to everybody who has helped me to get this thing finally working (somewhat). I got the field names to properly display in the PageHeaderSection, so I won't post the code from that. Now I'm...
1
by: chrisdavis | last post by:
I have a submission form with data in it that is submitted into "tblSubmitter" with basic information. I need to take every third record and mark a "status" to it. For Example: (these are...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.