| | |
need help with table
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2009
Posts: 22
Reputation:
Solved Threads: 0
i have a table with 14 columns and 4 rows. i know how to echo a result with a table from a query but how do i input results into a table thats already there? results go into cell 1, cell 2, cell 3 etc
been having trouble on this. table id= stack
its pretty long but i'll post the example so i can relate it to my code..
so how do i get $id to go to cell 1, cell 2, cell 3 etc and fill up the table. its easy when you echo it into a table but i need the table there before.
been having trouble on this. table id= stack
its pretty long but i'll post the example so i can relate it to my code..
PHP Syntax (Toggle Plain Text)
mysql_connect("localhost", "Master", "password; mysql_select_db("Ustack"); $report = mysql_query("SELECT * FROM Reply ")or die (mysql_error()); while($row = mysql_fetch_array( $report)) { $id = $row['id']; } <table border="0"> <tr> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> <td width="70" height="70"> </td> </tr> </table>
so how do i get $id to go to cell 1, cell 2, cell 3 etc and fill up the table. its easy when you echo it into a table but i need the table there before.
Last edited by MDanz; Nov 4th, 2009 at 1:55 pm.
•
•
Join Date: Apr 2009
Posts: 144
Reputation:
Solved Threads: 19
0
#2 Nov 4th, 2009
im not really following what you are trying to do if you wanna tell me with a little bit better of a explanation i can def help but i think this is what you are trying to do let me know
php Syntax (Toggle Plain Text)
echo "<table border='0'><tr>"; for ( $counter = 0 ; $counter <= 1000; $counter += 1) { echo "<td width='70' height='70'> $id[$counter]</td>"; } echo "</tr></table>";
0
#3 Nov 4th, 2009
MDanz,
You must build the table as you go, in two nested loops :-
Off-the-cuff; not tested
Airshow
You must build the table as you go, in two nested loops :-
- Outer loop - table rows
- Inner loop - table cells (forming colums)
php Syntax (Toggle Plain Text)
<?php mysql_connect("localhost", "Master", "password; mysql_select_db("Ustack"); $report = mysql_query("SELECT * FROM Reply ")or die (mysql_error()); echo "<table border=\"0\">\n"; while($row = mysql_fetch_array( $report)){ echo "<tr>\n"; foreach ($row as $value){ echo "<td width=\"70\" height=\"70\">$value</td>\n"; } echo "</tr>\n"; } echo "</table>\n"; ?>
Airshow
Last edited by Airshow; Nov 4th, 2009 at 3:16 pm.
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Sep 2009
Posts: 22
Reputation:
Solved Threads: 0
0
#4 Nov 4th, 2009
heres a better question..
how do i echo 1st result, 2nd result, 3rd result? i know how to echo all of them, how do i echo the specific... e.g. 2nd result in query. or the 3rd result in the query
how do i echo 1st result, 2nd result, 3rd result? i know how to echo all of them, how do i echo the specific... e.g. 2nd result in query. or the 3rd result in the query
PHP Syntax (Toggle Plain Text)
$addz = mysql_query("SELECT * FROM Stacks WHERE username = 'Admin'")or die (mysql_error()); while($rowrun = mysql_fetch_array( $addz)) { $idz = $rowrun['id']; }
0
#5 Nov 4th, 2009
•
•
•
•
how do i echo 1st result, 2nd result, 3rd result? i know how to echo all of them, how do i echo the specific... e.g. 2nd result in query. or the 3rd result in the query
Your query yields only one result ($result), which is (in all probability) "2-dimensional"; an array of arrays. The top level array should be indexed by integer ([1], [2], [3], [4]), while the level-2 arrays should be indexed by column name (as established in the database).
Therefore any particular item of data should be addressable as $result[n]['columnId']. This is effectively what happens (via different syntax) in my nested loops example above.
Airshow
50% of the solution lies in accurately describing the problem!
-1
#6 Nov 4th, 2009
You should use the LIMIT keyword in the sql query.
SELECT ... FROM ... WHERE .... ORDER BY .... LIMIT(x,y)
The WHERE and ORDER BY clauses are optional
LIMIT has two parameters (both integers)
The first integer is the offset - i.e. start returning records from record number (x) of the query - the first record is 0 - not 1!
The second integer (y) will limit the resulting recordset to that number of records.
To return the only 2nd record, just do: LIMIT(1,1)
To return the 2nd and 3rd record, do: LIMIT(1,2)
To return the first 10 records, do: LIMIT(0,10)
I don't know if this is what you're looking for.
SELECT ... FROM ... WHERE .... ORDER BY .... LIMIT(x,y)
The WHERE and ORDER BY clauses are optional
LIMIT has two parameters (both integers)
The first integer is the offset - i.e. start returning records from record number (x) of the query - the first record is 0 - not 1!
The second integer (y) will limit the resulting recordset to that number of records.
To return the only 2nd record, just do: LIMIT(1,1)
To return the 2nd and 3rd record, do: LIMIT(1,2)
To return the first 10 records, do: LIMIT(0,10)
I don't know if this is what you're looking for.
Happy Humbugging Christmas
•
•
Join Date: Aug 2009
Posts: 49
Reputation:
Solved Threads: 8
0
#7 Nov 4th, 2009
•
•
•
•
PHP Syntax (Toggle Plain Text)
while($row = mysql_fetch_array( $report)) { $id = $row['id']; }
As for having the table already there and then later inserting the data, that sounds more like something you'd need JavaScript or AJAX to do -- though I'm not sure if that's even possible, as I'm no expert in either.
Last edited by EvolutionFallen; Nov 4th, 2009 at 5:17 pm.
0
#8 Nov 4th, 2009
Last edited by Airshow; Nov 4th, 2009 at 5:45 pm.
50% of the solution lies in accurately describing the problem!
0
#9 Nov 4th, 2009
•
•
•
•
As for having the table already there and then later inserting the data, that sounds more like something you'd need JavaScript or AJAX to do -- though I'm not sure if that's even possible, as I'm no expert in either.
It's certainly possible to replace the contents of individual table cells using AJAX/DHTML methods in Javascript. As far as I can tell, that does not apply here but I may be wrong.
Airshow
50% of the solution lies in accurately describing the problem!
•
•
Join Date: Aug 2009
Posts: 49
Reputation:
Solved Threads: 8
0
#10 Nov 4th, 2009
•
•
•
•
That's exactly what I thought Evo but I sort of ignored it because the question is posed in the PHP forum.
It's certainly possible to replace the contents of individual table cells using AJAX/DHTML methods in Javascript. As far as I can tell, that does not apply here but I may be wrong.
![]() |
Similar Threads
- ASP PERL script table (Perl)
- I have a problem in my table (PHP)
- Display Table From MySQL DB (C#)
- Dreamweaver MX - unwanted white table space at top (Graphics and Multimedia)
Other Threads in the PHP Forum
- Previous Thread: how to set a session to destroy itself unset whatever in a certain amount of time
- Next Thread: Question about mass mail function
Views: 357 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cookies cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla js limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube






