Avatar of MOSTAGHASSI
MOSTAGHASSI
Flag for United States of America asked on

Call custom function in php and arrange data as attach file

Hello;

I retrieve data with a query as a custom function as below:

QUERY

 <?php
		 
	 $query_artandculture = "select tbarticles.articleid,tbarticles.title,substr(tbarticles.articlebody,1,200) as description1,tbphotos.photofilename,tbarticles.deletitem ,tbarticlecategories.catid,tbcategories.parentid,tbarticles.mediastate,tbphotos.altdescription
	 
from  tbarticles 

INNER JOIN tbphotos on tbphotos.articleid = tbarticles.articleid 
INNER JOIN tbarticlecategories on tbarticlecategories.articleid =  tbarticles.articleid
INNER JOIN tbcategories ON tbcategories.catid = tbarticlecategories.catid


where tbarticles.deletitem='1'   AND (tbcategories.parentid ='1' or  tbcategories.parentid ='2' or tbcategories.parentid ='3')


	  ORDER BY tbarticles.articleid desc
LIMIT 8
";

$result_artandculture = mysql_query($query_artandculture);
?>

Open in new window


FUNCTION

function doArticle_image300_artandculture($articleid,$title,$description1,$photo,$parentid,$catid,$mediastate,$altdescription) {
{
    // CREATE A RETURN STRING IN HEREDOC NOTATION
      $tab = <<<EOD
    <div class="wrapper-for-datapakage-firstpage">
      <div class="articletitle"><a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title 
		   </strong></a></div>
      <div class="row2-main-datapakage"><a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
		   <img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/></div>
      <div class="row3-main-datapakage">$description1...</div><hr class='hr95'></div>
    </div>
EOD;

    return $tab;
}
		  
          }
          $tab = "";
}

Open in new window


I want that arrange each block of data (call function) as 2 columns and in each row 2 blocks .

Thanks
PHP

Avatar of undefined
Last Comment
MOSTAGHASSI

8/22/2022 - Mon
Kim Walker

I'm not sure I understand the question. But your function code contains some mismatched curly braces. Line 1 ends with a begin curly brace and then line 2 contains another begin curly brace. Then lines 15, 17, and 19 each begin with an end curly brace. So that section of code should throw an error when parsed.

The snippet of code you labeled query appears to perform a database query and store the results in the variable $result_artandculture. Are you asking how to get the results of your query into the function?

I want that arrange each block of data (call function) as 2 columns and in each row 2 blocks .
This sounds as if you want to separate each block of data into 2 columns and arrange two blocks side by side for 4 columns on each row. Is this correct? What are you referring to as a block of data? Is that one row in the query result? The HTML code in your function appears to divide the data into three divs which all are direct descendants of the same parent div. If you wish to arrange these divs side-by-side, you need to show us your CSS for these elements.
MOSTAGHASSI

ASKER
Thanks,sorry for mistake the  braces,it has happen during copy past,and forget it the function work well,

Are you asking how to get the results of your query into the function?

No.

This sounds as if you want to separate each block of data into 2 columns and arrange two blocks side by side for 4 columns on each row. Is this correct?

Yes and no.
the arrangement are like:

block1      block2

block3      block4

block5      block6

block7      block8

What are you referring to as a block of data?

Data block is 'function' that  contain 3 div(1-for title with a link-2 for image for the same link-3 small description for article).
Kim Walker

I'm sorry. I still don't understand what you're asking for. Are you asking how to arrange your blocks of data in two columns? Are your blocks of data contained in a parent div with class wrapper-for-datapakage-firstpage?

If so, arranging the parent divs side by side in two columns is done with CSS, not PHP. This can be accomplished by wrapping all the wrapper-for-datapakage-firstpage divs in another div (if they aren't already) which is wide enough for two, and then floating all the wrapper-for-datapakage-firstpage divs.

Executing your doArticle_image300_artandculture function eight times would generating the eight blocks of data within the two-columns div below.
<div class="two_columns">
	<!-- Block 1 (generated by function doArticle_image300_artandculture) -->
	<div class="wrapper-for-datapakage-firstpage">
		<div class="articletitle">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title</strong></a>
		</div>
		<div class="row2-main-datapakage">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
			<img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/>
		</div>
		<div class="row3-main-datapakage">$description1...</div>
		<hr class='hr95'>
	</div>
	<!-- Block 2 (generated by function doArticle_image300_artandculture) -->
	<div class="wrapper-for-datapakage-firstpage">
		<div class="articletitle">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title</strong></a>
		</div>
		<div class="row2-main-datapakage">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
			<img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/>
		</div>
		<div class="row3-main-datapakage">$description1...</div>
		<hr class='hr95'>
	</div>
	<!-- Block 3 (generated by function doArticle_image300_artandculture) -->
	<div class="wrapper-for-datapakage-firstpage">
		<div class="articletitle">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title</strong></a>
		</div>
		<div class="row2-main-datapakage">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
			<img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/>
		</div>
		<div class="row3-main-datapakage">$description1...</div>
		<hr class='hr95'>
	</div>
	<!-- Block 4 (generated by function doArticle_image300_artandculture) -->
	<div class="wrapper-for-datapakage-firstpage">
		<div class="articletitle">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title</strong></a>
		</div>
		<div class="row2-main-datapakage">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
			<img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/>
		</div>
		<div class="row3-main-datapakage">$description1...</div>
		<hr class='hr95'>
	</div>
	<!-- Block 5 (generated by function doArticle_image300_artandculture) -->
	<div class="wrapper-for-datapakage-firstpage">
		<div class="articletitle">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title</strong></a>
		</div>
		<div class="row2-main-datapakage">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
			<img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/>
		</div>
		<div class="row3-main-datapakage">$description1...</div>
		<hr class='hr95'>
	</div>
	<!-- Block 6 (generated by function doArticle_image300_artandculture) -->
	<div class="wrapper-for-datapakage-firstpage">
		<div class="articletitle">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title</strong></a>
		</div>
		<div class="row2-main-datapakage">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
			<img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/>
		</div>
		<div class="row3-main-datapakage">$description1...</div>
		<hr class='hr95'>
	</div>
	<!-- Block 7 (generated by function doArticle_image300_artandculture) -->
	<div class="wrapper-for-datapakage-firstpage">
		<div class="articletitle">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title</strong></a>
		</div>
		<div class="row2-main-datapakage">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
			<img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/>
		</div>
		<div class="row3-main-datapakage">$description1...</div>
		<hr class='hr95'>
	</div>
	<!-- Block 8 (generated by function doArticle_image300_artandculture) -->
	<div class="wrapper-for-datapakage-firstpage">
		<div class="articletitle">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'><strong>$title</strong></a>
		</div>
		<div class="row2-main-datapakage">
			<a href='./$folder/$file?articleid=$articleid&parentid=$parentid&catid=$catid'>
			<img src='./images/mimage/$photo' border='0' alt='$altdescription' /></a><br/>
		</div>
		<div class="row3-main-datapakage">$description1...</div>
		<hr class='hr95'>
	</div>
</div>

Open in new window

The CSS to place them side by side would look something like
div.two_columns { width: 600px; height: auto; overflow: hidden; }
div.wrapper-for-datapakage-firstpage { width: 300px; margin: 0; padding: 0; float: left; }

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MOSTAGHASSI

ASKER
Thanks Ray,specially for your great article, it seams that we must be ready for everyday upgrading,for this question i need your help,for convert this part of my old codes(works well) from 'table' to 'div' :

<?php
$result_artandculture = mysql_query($query_artandculture);

if ( $result_artandculture) {
	
	$tab = "<table width = 640  valign=top border=0 cellspacing=1 bordercolor=#ffffff bgcolor=#FFFFFF style=border: 1px solid #0066ff>\n";
	
	      $i = 1;
     for ( $i=1 ; $i<=4; $i++){
    $rw = @mysql_fetch_assoc( $result_artandculture);
     $tab .= "<tr>\n";
     $tab .= "<td   align=center bordercolor=#ffffff >" .doArticle_image300_artandculture( $rw['articleid'], $rw['title'],    $rw['description1'], $rw['photofilename'], $rw['parentid'], $rw['catid'],$rw['mediastate'],$rw['altdescription']) . "</td>\n"; 
	 
	 
	 if ( $rw = @mysql_fetch_assoc($result_artandculture ) )
	 $tab .= "<td   align=center bordercolor=#ffffff >" .doArticle_image300_artandculture( $rw['articleid'], $rw['title'], $rw['description1'], $rw['photofilename'], $rw['parentid'], $rw['catid'],$rw['mediastate'],$rw['altdescription']) . "</td>\n";		
	 
	 $tab .= "</tr>\n";
     }
	 $tab .= "</table>\n"  ; 
	} 
    echo   "$tab"; 
     ?>

Open in new window

Ray Paseur

This is not really a question with an answer -- it's more of a requirement for application development.  You might do well to try E-E Gigs.
MOSTAGHASSI

ASKER
Please let me know that how much is normal for this very small project?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.