mysql - Need help simplifying my php table -


I am relatively new to PHP and I have realized that I am going a long way while displaying data from mysql.

I have a table, which I want to show some fields from my database.

How do I get it without resigning every bit of the table << p>

Here is the code:

   '; Echo & lt; Td width = "335" & gt; '; Echo ['first name'] per line; Echo '& amp; Nbsp; '; Echo ['last name'] per line; Echo & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Email address & lt; / Td> & Lt; TD & gt; '; Echo ['email'] per line; Echo & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Username & lt; / TD & gt; & Lt; TD & gt; '; Echo ['user'] per line; Echo & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Country & lt; / TD & gt; & Lt; TD & gt; '; Echo ['country'] per line; Echo & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Time zone & lt; / Td> & Lt; TD & gt; GMT + 1 & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Active & lt; / TD & gt; & Lt; Td> December 16, 2009 & lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; '; }? & Gt;  

You can first obtain all the data in an array and then on that array Can iterate

On top of your file , you should do all processing (i.e., receiving,

Separates the fraction, others mention the template engine (smerty, etc.). I do not think that you really need it, because PHP itself is a template engine.
Examples to do refined stuff in your presentation Do not;)

It is also very useful for presentation Use it in conjunction with this because it is very much readable.


I changed the table structure slightly, because you were not generating more generic HTML (you create multiple tables with the same ID your original code).
It generates a table with one line for each customer.

  & lt ;? Php $ customers = array (); $ Query1 = mysql_send ("Choose first name, last name, email, user, country by country where id = '". $ _COOKIE [' custid ']. "'" "); While ($ line = mysql_fetch_array ($ query1)) {$ cusomters [] = $ line; }? & Gt; & Lt; Table id = "account_table" style = "width: 550px; range: none;" & Gt; & Lt; TR & gt; & Lt; Width = "155" & gt; Contact name & lt; / Th & gt; & Lt; Th & gt; Email address & lt; / Th & gt; & Lt; Th & gt; Username & lt; / Th & gt; & Lt; Th & gt; Country & lt; / Th & gt; & Lt; Th & gt; Time zone & lt; / Th & gt; & Lt; Th & gt; Active & lt; / Th & gt; & Lt; / TR & gt; & Lt ;? Php foreach ($ clients as customer $):? & Gt; & Lt; TR & gt; & Lt; Td width = "335" & gt; & Lt ;? Php echo $ row ['firstname']? & Gt; & Amp; Nbsp; & Lt ;? Php echo $ row ['lastname']? & Gt; & Lt; / TD & gt; & Lt; Td> & Lt ;? Php echo $ row ['email']? & Gt; & Lt; / TD & gt; & Lt; Td> & Lt ;? Php echo $ row ['user']? & Gt; & Lt; / Td> & Lt; Td> & Lt ;? Php echo $ row ['country']? & Gt; & Lt; / Td> & Lt; TD & gt; GMT + 1 & lt; / TD & gt; & Lt; Td> December 16, 2009 & lt; / Td> & Lt; / TR & gt; & Lt ;? Php endforeach; ? & Gt; & Lt; / Table & gt;  

Comments