7 Replies - 2135 Views - Last Post: 05 August 2012 - 11:52 PM Rate Topic: -----

#1 khorshidnam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-August 12

how to put php contents into a HTML table!

Posted 04 August 2012 - 03:59 AM

Hi all pro's:
I have a PHP file that i want to create a table for it..
Php file gets an information from another website (Such as RSS) and I want to put it in my website and i dont know how to make table for a PHP file..
this is my code:

<?php

$content = file_get_contents('http://www.mazanex.com/');

preg_match('#<div id="secondaryContent">(.*)<div class="counter t13" #', $content, $match);
$new_content = $match[1];

echo $new_content;

?>

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: how to put php contents into a HTML table!

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: how to put php contents into a HTML table!

Posted 04 August 2012 - 04:34 AM

Hey.

What do you mean? The code you posted already seems to print the data into a HTML table. How else do you want to show it?
Was This Post Helpful? 0
  • +
  • -

#3 khorshidnam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-August 12

Re: how to put php contents into a HTML table!

Posted 04 August 2012 - 04:53 AM

View PostAtli, on 04 August 2012 - 04:34 AM, said:

Hey.

What do you mean? The code you posted already seems to print the data into a HTML table. How else do you want to show it?


If you see This site: http://www.mazanex.com/ (Top left table)
the PHP file gets out the contents from this website..but how can i put this contents to my website..there is no way to change the colors or move the table to the right or top or bottom..
my friend just wrote that PHP and gave it to me..i dont know how can i customize the contents.
Thank you for your consideration by the way..:-)
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3030
  • View blog
  • Posts: 10,553
  • Joined: 08-August 08

Re: how to put php contents into a HTML table!

Posted 04 August 2012 - 10:59 AM

First you need to learn how to get PHP to generate an HTML table. Below is an example of how I'd do that. My questions for you are:
  • Why is there very little HTML in my PHP code?
  • Why do I use a function?
  • Why do I use HEREDOCs?
  • What would the $info array correspond to in your project?

Answering these questions properly will mean that you're on your way towards understanding how to solve your problem.

<?php
$rows = <<<MYROW
<tr><td>{first}</td><td>{second}</td><td>{third}</td></tr>

MYROW;

$header = <<<MYHEADER
<tr><th>Column One</th><th>Column Two</th><th>Column Three</th></tr>

MYHEADER;

$columns = array("{first}", "{second}", "{third}");

$info = array(
			array("first_item1","first_item2","first_item3"), 
			array("second_item1","second_item2","second_item3"), 
			array("third_item1","third_item2","third_item3")
		);

make_table($info, $rows, $header, $columns);


function make_table(&$data, &$row, &$head, &$cols) {
	echo '<table border="1">'.$head;
	foreach($data as $myinfo) {
		echo str_replace($cols, $myinfo, $row);
	}
	echo '</table>';
}


Was This Post Helpful? 0
  • +
  • -

#5 khorshidnam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-August 12

Re: how to put php contents into a HTML table!

Posted 04 August 2012 - 03:33 PM

View PostCTphpnwb, on 04 August 2012 - 10:59 AM, said:

First you need to learn how to get PHP to generate an HTML table. Below is an example of how I'd do that. My questions for you are:
  • Why is there very little HTML in my PHP code?
  • Why do I use a function?
  • Why do I use HEREDOCs?
  • What would the $info array correspond to in your project?

Answering these questions properly will mean that you're on your way towards understanding how to solve your problem.

<?php
$rows = <<<MYROW
<tr><td>{first}</td><td>{second}</td><td>{third}</td></tr>

MYROW;

$header = <<<MYHEADER
<tr><th>Column One</th><th>Column Two</th><th>Column Three</th></tr>

MYHEADER;

$columns = array("{first}", "{second}", "{third}");

$info = array(
			array("first_item1","first_item2","first_item3"), 
			array("second_item1","second_item2","second_item3"), 
			array("third_item1","third_item2","third_item3")
		);

make_table($info, $rows, $header, $columns);


function make_table(&$data, &$row, &$head, &$cols) {
	echo '<table border="1">'.$head;
	foreach($data as $myinfo) {
		echo str_replace($cols, $myinfo, $row);
	}
	echo '</table>';
}



Thank you for your reply..It's exactly what I want to draw a table with php and put those contents into it..
I have a question! how can I dedicate each item to every cell..? for example first word from first row..according to your sample I should have 21 columns. right?
so <tr><td>{first}</td><td>{second}</td><td>{third}</td></tr><tr><td>{4th}</td><td>{5th}</td><td>{6th}</td></tr> ... ?
what about fonts? colors?
I just need the codes..I can figure it out how to put em up together.

This post has been edited by CTphpnwb: 04 August 2012 - 03:45 PM
Reason for edit:: Removed duplicate post

Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3030
  • View blog
  • Posts: 10,553
  • Joined: 08-August 08

Re: how to put php contents into a HTML table!

Posted 04 August 2012 - 03:44 PM

View Postkhorshidnam, on 04 August 2012 - 06:33 PM, said:

I just need the codes..I can figure it out how to put em up together.

You have the codes. Now you need to figure them out. Why does $rows contain {first}, {second}, and {third} but the output contains the data sent to the function? Answer that and you should know how the code works.
Was This Post Helpful? 0
  • +
  • -

#7 khorshidnam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-August 12

Re: how to put php contents into a HTML table!

Posted 05 August 2012 - 11:30 PM

View PostCTphpnwb, on 04 August 2012 - 03:44 PM, said:

View Postkhorshidnam, on 04 August 2012 - 06:33 PM, said:

I just need the codes..I can figure it out how to put em up together.

You have the codes. Now you need to figure them out. Why does $rows contain {first}, {second}, and {third} but the output contains the data sent to the function? Answer that and you should know how the code works.


I made the table by php coding..but now i have this problem that how can I dedicate every content to specific place on my table..
http://artoftaxiderm...est/alisoli.php
See this link.
Was This Post Helpful? 0
  • +
  • -

#8 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: how to put php contents into a HTML table!

Posted 05 August 2012 - 11:52 PM

What do you mean there by specific place? You have put your data each one in its cell now it your css which will define the design. I see you define table with:
<table id="ex3" class="exch_tbl">

But no lead to what css says about id "ex3" or class "exch_tbl". If you just need borders, put them.
I am not sure if you event understand what CTphpnwb gave you!! Looks like you need to know how html tables works and how to use css and attributes
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1