Newbie Question - an If in an Array?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm so confused. I have an array :


$display[] = " <div class='job-date'>{$cv['dates']}</div> <div class='job-title'>{$cv['job_title']}</div> <div class='company'>{$cv['company']}</div> <div class='job'>{$cv['job']}</div>";

In SOME of the rows of this table, there is a field called sidebar. I'd like to have this array include a reference to this field if it exists.

I was thinking something like:
if (!empty($cv['sidebar'])){
$sidebar_ref = "
<div class='sidebar_ref_box'><a href='../sidebars/index.htm?s={$cv['sidebar']}' title='Sidebar'>Learn More</a></div>"
};



Can anyone offer some help?

Thanks. The whole script is below:





<?php


/* invalid or missing GET? */
if (!isset($_GET['r']) || empty($_GET['r']) || !($r = intval($_GET['r']))) {
// show a plain vanilla index
include('/path/to/docs/cv.include.php');
exit;
}




/* With a valid $r, make some variables to help build the SQL query
* Note three conditions join the tables yes we are aware of that */
$fields = 'cv.cv_id,cv.category,dates,cv.job_title,cv.company,cv.job,cv.sort,cv.si debar,jobcat.category';
$where = "WHERE cvjobcats.cv_id=cv.cv_id
AND cvjobcats.jobcat_id = '$r'
AND jobcat.jobcat_id=cvjobcats.jobcat_id";
$restables = "cv, cvjobcats, jobcat";
$sort = "ORDER BY cv.sort";



/* Finally the actual SQL query, using the variables just set
* do we have a valid mysql result resource?
*/
if (!($result = mysql_query("SELECT $fields FROM $restables $where $sort"))) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}


/* do we have any records? if not show the list/menu */
if (mysql_num_rows($result) == 0) {
  include_once('/path/to/docs/cv.include.php');
  exit;
}

$display = array();  // this is merely an array initialization

unset($cat);
while ($cv = mysql_fetch_assoc($result)) {
    /* set the category name for display in the output */
    if (!isset($cat)) {
    	$cat = $cv['category'];

    }

/*$sidebar_ref = array();
while ($cv = mysql_fetch_assoc($result)) {
if (!empty($cv['sidebar'])){
$sidebar_ref [] = "
<div class='sidebar_ref_box'><a href='../sidebars/index.htm?s={$cv['sidebar']}' title='Sidebar'>Learn More</a></div>"
};
}*/



/* make an array of jobs which includes the HTML to be displayed * in the HTML page when we make one... */ $display[] = " <div class='job-date'>{$cv['dates']}</div> <div class='job-title'>{$cv['job_title']}</div> <div class='company'>{$cv['company']}</div> <div class='job'>{$cv['job']}</div>"; }

/* be nice - tell mysql to free the resultset */
mysql_free_result($result);

/*
 * And now, wrap up the PHP and make the page...
 */

echo "<?xml version='1.0' ?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
<title>Resume </title>
<link rel='stylesheet' href='http://domain.com/docs/style.css' type='text/css' />
</head>
<body>


<!-- CALL EVERYTHING BELOW A PAGE -->
<div id='page-display'>

<!--START HEADER --><?php include_once "/path/to/docs/header.include.php" ?><!-- END HEADER -->


<!-- BEGIN LEFT SIDE --> <div id='left-sidebar'> <?php include_once "/path/to/docs/left-sidebar.cv.include.php"; ?> </div> <!-- END LEFT SIDE -->


<!--START MAIN CONTENT AREA--> <div id='content'>



	<h1>R&eacute;sum&eacute;</h1>

	<?php include_once "/path/to/docs/cv.$r.include.php"; ?>

	<div class='job-category'><?php echo $cat?></div>



	<?php
	if (sizeof($display)) {
		echo "
	<div id='table-of-contents'>
	";
		echo join("\n\t\t", $display);

		echo "
	</div>
	";

	}
	
	?>

</div>
<!--END MAIN CONTENT AREA-->

<!--BEGIN FOOTER-->
<div id='footer'><?php include_once "/path/to/docs/footer.include.php" ?></div>
<!--END FOOTER-->


</div>
<!--END PAGE-->

</body>
</html>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux