Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 19:18

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Help] Numbering PHP table

Discussion on [Help] Numbering PHP table within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2012
Posts: 372
Received Thanks: 21
[Help] Numbering PHP table

Hi,
i am trying to make a table using PHP, and i have a problem numbering each cell with a different number. So if the table is 3x3, like this
1 2 3
4 5 6
7 8 9

Here is what i got (i know what is worng, i am displaying td numbers, but i dont know how to do it like i want...) :
Code:
<?php 

function drawTable(){

$rows = 4; // amout of tr
$cols = 4;// amjount of td

echo "<table border='1'>"; 


for($tr=1;$tr<=$rows;$tr++){ 

    echo "<tr>";
    for($td=1;$td<=$cols;$td++){
    	echo "<td align='center'>".$td."</td>";
    }
	
    echo "</tr>";
}
 
echo "</table>";
}

drawTable();
?>
Hikarim is offline  
Old 01/26/2013, 11:44   #2
 
elite*gold: 0
Join Date: Apr 2005
Posts: 323
Received Thanks: 114
PHP Code:
<?php 

function drawTable(){

$rows 4// amout of tr
$cols 4;// amjount of td

echo "<table border='1'>"
$cnt 1;

for(
$tr=1;$tr<=$rows;$tr++){ 

    echo 
"<tr>";
    for(
$td=1;$td<=$cols;$td++){
        echo 
"<td align='center'>".$cnt."</td>";
$cnt++;
    }
    
    echo 
"</tr>";
}
 
echo 
"</table>";
}

drawTable();
?>
MrPuschel is offline  
Thanks
1 User
Old 01/26/2013, 16:35   #3
 
elite*gold: 0
Join Date: Apr 2012
Posts: 372
Received Thanks: 21
Ok, 1 more thing, how can i make the user to input number of rows and cols? ($rows; $cols; )
Hikarim is offline  
Old 01/26/2013, 17:09   #4
 
elite*gold: 0
Join Date: Apr 2005
Posts: 323
Received Thanks: 114


Don't get me wrong, but it is kinda obvious that you need this for school. Other people doing that for you won't help you if it comes to exams.
MrPuschel is offline  
Old 01/26/2013, 17:11   #5
 
elite*gold: 0
Join Date: Apr 2012
Posts: 372
Received Thanks: 21
yea, i also checked that but i couldnt get it to work... im not sure what the "action=""" to set to, as my whole code is in one file...
Hikarim is offline  
Old 01/26/2013, 17:30   #6
 
kissein's Avatar
 
elite*gold: 0
Join Date: Sep 2005
Posts: 427
Received Thanks: 87

Quote:
'PHP_SELF'
The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.
PHP Code:
action="<? $_SERVER['PHP_SELF'?>"
Modify your function drawTable to accept params. Check if Post params are set and combine it with your function.
kissein is offline  
Old 01/26/2013, 17:35   #7
 
tayfe's Avatar
 
elite*gold: 104
Join Date: Jun 2010
Posts: 547
Received Thanks: 127
You can just leave it blank if it's the same file:
HTML Code:
<form action="" method="post">
Otherwise you just use your file name. So if your file is called "index.php" you just write
HTML Code:
<form action="index.php" method="post">
It's that easy

And if you want to add some parameters you can just attach them using a "?":
HTML Code:
<form action="index.php?page=createTable" method="post">
But you should already know this stuff
tayfe is offline  
Old 01/26/2013, 17:58   #8
 
elite*gold: 0
Join Date: Apr 2012
Posts: 372
Received Thanks: 21
ok, thank you for that,... but still, how can i change my variable with using $_GET ?
because there is already a variable $rows=5; and it draws a table with 5 rows... how can i make it to change the $rows:5; to lets say $rows=9; if the user sets so? -It is easy to do it with just basic name submision forms, but this is confusing as nothing that i tryed works :S
Hikarim is offline  
Old 01/26/2013, 18:42   #9
 
elite*gold: 0
Join Date: Apr 2005
Posts: 323
Received Thanks: 114
First, you should use the superglobal . Everything else is deprecated and shall not be used.

Your code would look like:

PHP Code:

$row 
5;
$myRow =  $_REQUEST['myRow'] ;

// Has $myRow any content?
// Keep in mind that it checks only for content. Not valid content.

if ( $myRow 
   
$row $myRow 
MrPuschel is offline  
Old 01/26/2013, 18:43   #10
 
tayfe's Avatar
 
elite*gold: 104
Join Date: Jun 2010
Posts: 547
Received Thanks: 127
You really dont know?

I could tell you but this wont help you much. You should really read a tutorial! This are the absolutly basics!

But to give you a hint: Use something like this:

PHP Code:
$rows $_POST['rows']; 
But you will need to add some lines to your formular. Just read a tutorial and you will be able to do it on your own very quick!
tayfe is offline  
Reply


Similar Threads Similar Threads
about table
07/04/2012 - SRO Private Server - 2 Replies
hey everyone, SORRY FOR THE WHOLE THREAD, but i couldn't find how to do can anyone tell me how to to make that black table, i can create the normal one like this test test
[Help] WHICH TABLE?
01/14/2012 - EO PServer Hosting - 1 Replies
I have four tables, levexp, levexp_0, levexp_1, and levexp_x. One of them doesnt contain the same tables as the other three, that one being levexp_x. What I am trying to do is make it harder to level. I have made adjustments to the column usruplevexp in levexp. I have tried it with high and low numbers, the same and different. When i restart the server, the levelling becomes stupid- Kill 3 madbulls and go up an amazing 97 levels in total. I have noticed that all three tables, (0, 1...
Table wie?
06/22/2011 - Main - 1 Replies
Hallo, Also ich weiß wie ich eine Tabelle mache,aber da ist dann oben nicht der Schwarze Begriffwie mache ich das?
ce table
05/27/2011 - AutoIt - 7 Replies
hallo zusammen ich suche aion ce table fuer version 2.1.x.x hab schon parr werte gefunden fuer mein bot projekt in nomad kann mir eventuell hier aus der sektion wer helfen??? mfg
Table of EXP
03/19/2011 - WarRock - 7 Replies
i need the table of how much need to up level and 1% plz who can give me?



All times are GMT +1. The time now is 19:18.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.