I have a fancybox that opens on div click. The divs are made automatically and the id's are not the same.
I have 8 divs on which the fancybox should open on 4 of them and it does.
But on the others, it opens also with a content can't be found message, and that should not pop up.
I have tried the jquery removeclass function already but doesn't seem to be working.
This is the code :
$outputEdities = '<div id="data_' . $currID . '" class="fancybox-content" style="display: none; max-width: 600px;"> ';
while($rowEditie = mysql_fetch_assoc($resultEdities)){ //Creates a loop to loop through results
$currIDEditie = $rowEditie['id'];
$currStream = $rowEditie['streamurl'];
$currStation = $rowEditie['stationid'];
$currName = $rowEditie['editienaam'];
$outputEdities .= '<h2>Editie</h2>';
$outputEdities .= '<h1>'. $currName .' </h1>';
}
$outputEdities .= '</div>';
}
$output .= '<div class="content-b' . $count . '" style="text-align:center;">';
//$output .= $outputEdities;
$output .= '<img src="' . $currPicture . '" alt="' . $currName . ' Luisteren" />';
$output .= $outputEdities;
$output .= '</div>';
if( $count == 1 )
$count = 2;
else if( $count == 2 )
$count = 3;
else if( $count == 3 )
{
$count = 1;
$output .= '<div class="clear"></div>';
This code generates the divs and shows content.
I dont know if I have posted my question correctly but we will see.
if (isset($_GET['q'])){
$q = $_GET['q'];
//variables
$sql = "SELECT * FROM products WHERE product LIKE '%$q%' OR search LIKE '%$q%'";
$result = $conn->query($sql);
//check database
if($result->num_rows > 0){
while ($row = $result->fetch_array()){
$product = $row['product'];
$productImage = $row['product_image'];
$price = $row['price'];
$seller = $row['seller_name'];
$sellerImage = $row['seller_image'];
$desc = $row['description'];
$search = $row['search'];
$console = $row['console'];
$array = array($product, $price, $productImage);
$arrayDesc = array($desc, $sellerImage);
if (preg_match('/Game/', $seller)){
for ($num = 0; $num < 3; $num++) {
echo '<div class="tile col-md-4 col-sm-3">';
if($num == 0){
echo '<div class="tileTitleBox"><h4>' . $array[$num] . '</h4></div>';
}
if($num = 1){
echo '<p class="price">' . $array[$num] . '</p>';
}
if($num = 2){
echo '<img class="tilePic" src="' . $array[$num] . '"/>';
}
// if($num = 3){
// echo '<div class = "desc"><p>' . $array[$num] . '</p></div>';
// }
echo '</div>';
}//For Iteration Loop - TILE
for($count = 0; $count < 2; $count++){
echo '<div class="tile-description col-md-4 col-sm-3 hidden">';
if($count == 0){
echo '<div class="desc"><p>' . $arrayDesc[$count] . '</p></div>';
}
if($count == 1){
echo '<img class="sellerImg" src="' . $arrayDesc[$count] . '"/>';
}
echo '</div>';
}//end for loop - TILE-DESCRIPTION
So as you see above, I have one for loop which creates the "tile" and the second which is supposed to create the "tile-description". The first one works well to create a single div with the class of "tile" in which my remaining contents is loaded into the div. But in the second for loop the "desc" dev and the "sellerImg" div are separated. The loop needs to go through the array various times.
Shown Bellow:
You can see that the "Tile" div contains "tileTitleBox", "price", and "tilePic". But the "tile-description" which is hidden, is separated into two divs. As opposed to holding both elements inside the same div.
#sam-dufel rightly pointed out you're overwriting the iterator
if($num = 1){
But in fact you shouldn't use any loops here:
echo '<div class="tile col-md-4 col-sm-3">';
echo '<div class="tileTitleBox"><h4>' . $array[0] . '</h4></div>';
echo '<p class="price">' . $array[1] . '</p>';
echo '<img class="tilePic" src="' . $array[2] . '"/>';
echo '</div>';
echo '<div class="tile-description col-md-4 col-sm-3 hidden">';
echo '<div class="desc"><p>' . $arrayDesc[0] . '</p></div>';
echo '<img class="sellerImg" src="' . $arrayDesc[1] . '"/>';
echo '</div>';
How to add in this code multiple ID category.
I have in kategorija_id 5 arrays:
1 - News
2 - Magazine
3 - Kokursi
4 - Grantovi ect..
I whant to display just key 1 and 2
when i add array i just print the first key
$kategorija = Kategorija::model()->findByPk($item->kategorija_**id=1,2**);
Thnx :)
Code update:
<div class="carousel-inner">
<div class="item active">
<ul class="thumbnails">
<?php
$i = 0;
$lastDefault = 0;
foreach ($ids as $itemId) {
$item = InfoPaket::model()->findByPk($itemId);
$kategorija = Kategorija::model()->findByPk($item->kategorija_id);
if ( $i % 3 == 0 && $i > 0 ) {
echo "</ul></div><div class='item'><ul class='thumbnails'>";
}
$imageUrl = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->baseUrl . "/images/infopaket/" . $item->slika;
if ( !file_exists($imageUrl) || empty($item->slika)) {
if ( $lastDefault == 0 ) {
$imagePath = Yii::app()->baseUrl . "/images/infopaket/info_paket.png";
$lastDefault = 1;
} else {
$imagePath = Yii::app()->baseUrl . "/images/infopaket/info_paket_redv2.png";
$lastDefault = 0;
}
} else {
$imagePath = Yii::app()->baseUrl . "/images/infopaket/" . $item->slika;
}
echo "<li class='span3 thmb-elem'>";
echo "<div class='thumbnail right-caption image'>";
echo "<a class='img-link' href='" . Yii::app()->getHomeUrl() . "?r=infoPaket/clanak&id=" . $item->id . "'><img class='img-class' src='$imagePath'></a>";
echo "</div>";
echo "<div class='caption caption-link'>";
echo "<div class='naziv'><img class='arrow-img' src='". Yii::app()->getBaseUrl() . "/themes/shadow_dancer/images/arrow.png'> " . strtoupper($kategorija->naziv) . "</div>";
echo "<p><a class='naslov' href='" . Yii::app()->getHomeUrl() . "?r=infoPaket/clanak&id=" . $item->id . "'><strong>" . $item->naslov . "</strong></a></p>";
echo "</div>";
echo "</li>";
$i++;
}
?>
</ul>
</div>
</div>
I solve this problem adding this line of code
if ($item->kategorija_id==3 || $item->kategorija_id==4 ) {
now code look like this and it works perfect.
<?php
$lastDefault = 0;
foreach ($ids as $itemId) {
$item = InfoPaket::model()->findByPk($itemId);
$kategorija = Kategorija::model()->findByPk($item->kategorija_id);
if ($item->kategorija_id==3 || $item->kategorija_id==4 ) {
echo '<li>';
echo '<img src="<?php echo Yii::app()->theme->baseUrl; ?>/images/infopaket/info_paket.png" />';
echo '<h2>';
echo strtoupper($kategorija->naziv);
echo '</h2>';
echo '<h1>';
echo "<a class='naslov' href='" . Yii::app()->getHomeUrl() . "?r=infoPaket/clanak&id=" . $item->id . "'>";
echo $item->naslov;
echo '</h1>';
echo '</a>';
echo '</li>';
}
}
?>
findByPk() accepts first argument as array too. So you can do
category::model()->findByPk(array('1', '2'));
Also, $item->category_id will return only single entry. If your item has multiple categories, than set up relations to categories and then get categories ID's with
CHtml::listData($item->categoriesRelationName, 'id', 'id');
can use function ($data){return $data->attribtues} too ---------^--- to get all attributes of model
I'm using a script PHP to get all posts from a fan page. The code is this:
require_once("../facebook-sdk/src/facebook.php");
$config = array(
'appId' => '#############',
'secret' => '###############################',
'fileUpload' => false
);
$facebook = new Facebook($config);
$facebook->setAccessToken("###################################");
$pageid = "###############";
$pagefeed = $facebook->api("/" . $pageid . "/feed");
$i = 0;
foreach($pagefeed['data'] as $post) {
if ($post['type'] == 'video' || $post['type'] == 'link' || $post['type'] == 'photo') {
// open up an fb-update div
echo "<div class=\"fb-update\">";
// check if post type is a link
if ($post['type'] == 'link') {
echo '<img class="imagem-feed" src="' . $post["picture"] . '">';
$interno = "<p>" . $post['message'] . "</p><p>" . $post['link'] . "</p>";
}
// check if post type is a photo
if ($post['type'] == 'photo') {
$fotoAlta = $facebook->api("/" . $post["object_id"] . "?fields=source");
echo '<img class="imagem-feed" src="' . $fotoAlta["source"] . '">';
//interno
if (empty($post['story']) === false) {
$interno = "<p>" . $post['story'] . "</p>";
} elseif (empty($post['message']) === false) {
$interno = "<p>" . $post['message'] . "</p>";
}
$interno .= "<p>Ver no Facebook →</p>";
}
// check if post type is a video
if ($post['type'] == 'video') {
echo '<iframe class="imagem-feed" width="350" height="263" src="' . str_replace("&autoplay=1","",$post["source"]) . '" frameborder="0" allowfullscreen></iframe>';
//interno
if (empty($post['story']) === false) {
$interno = "<p>" . $post['story'] . "</p>";
} elseif (empty($post['message']) === false) {
$interno = "<p>" . $post['message'] . "</p>";
}
}
echo '<div class="cabecalho-fanpage"><a target="_blank" href="https://www.facebook.com/Angelameza.arquitetura"><img class="img-perfil-fanpage" width="50" height="50" src="http://profile.ak.fbcdn.net/hprofile-ak-ash1/373040_201176906637605_665931623_q.jpg"><h1>' . $post["from"]["name"] . '</h1><p>' . date("d/m/Y", (strtotime($post['created_time']))) . '</p></a></div>';
echo $interno;
echo '<div class="container-interacoes">';
$totalCurtidas = $facebook->api("/" . $post["id"] . "/likes/?summary=true");
$titulo = ($totalCurtidas["summary"]["total_count"] == 0 || $totalCurtidas["summary"]["total_count"] > 1) ? $totalCurtidas["summary"]["total_count"] . " pessoas curtiram isso." : "1 pessoa curtiu isso.";
echo "<span title='$titulo' class='icon-curtidas'>" . $totalCurtidas["summary"]["total_count"] . "</span>";
$compartilhamentos = (isset($post["shares"]["count"])) ? $post["shares"]["count"] : 0;
$titulo = ($compartilhamentos == 0 || $compartilhamentos > 1) ? $compartilhamentos . " pessoas compartilharam isso." : "1 pessoa compartilhou isso.";
echo "<span title='$titulo' class='icon-compartilhamentos'>" . $compartilhamentos . "</span>";
$totalComentarios = $facebook->api("/" . $post["id"] . "/comments/?summary=true");
$titulo = ($totalComentarios["summary"]["total_count"] == 0 || $totalComentarios["summary"]["total_count"] > 1) ? $totalComentarios["summary"]["total_count"] . " pessoas comentaram isso." : "1 pessoa comentou isso.";
echo "<span title='$titulo' class='icon-comentarios'>" . $totalComentarios["summary"]["total_count"] . "</span>";
echo "</div>";
echo "<div style='clear:both'></div></div>"; // close fb-update div
$i++; // add 1 to the counter if our condition for $post['type'] is met
}
} // end the foreach statement
Using this code, the page is very slow (50 seconds to load). I tested any thing for optimize and don't improve. Can someone help me?
You are making calls to graph API inside the for loop, i.e for every post, you are making additional calls. Obviously, this contributes towards your 50 secs. Your best bet is to arrange your code to use batch requests. Here is the documentation for batching calls.
https://developers.facebook.com/docs/graph-api/making-multiple-requests/
Note: You can make upto 50 calls in one go using a batch request.
I have migrated some codes, all went fine till I encountered this code in the tutorial. Because I have a custome template, the html and php code is a little different from the original template, now I'm totally lost.
This is the original code, which should be replaced with the one beneath this code:
<table cellspacing="0" cellpadding="0" border="0" class="product">
<tr>
<td width="103" height="104"><script language="javascript"><!--
document.write('<?php echo '
<a href="javascript:popupWindow(\\\'' .
tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' .
$product_info['products_id']) . '\\\')">'
. tep_image(DIR_WS_IMAGES .
$product_info['products_image'], addslashes(
$product_info['products_name']),
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="0" vspace="0"') . '</a>'; ?>');
//--></script>
<noscript>
<?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES .
$product_info['products_image']) . '" target="_blank">' .
tep_image(DIR_WS_IMAGES .
$product_info['products_image'],
$product_info['products_name'],
SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="0" vspace="0"') . '</a>'; ?>
</noscript></td>
<td width="344" height="104"><br>
<br style="line-height:5px"><?php echo stripslashes(
$product_info['products_description']); ?>
<br style="line-height:1px;"><br style="line-height:5px;">
</td>
</tr>
<tr>
<td width="447" height="1" colspan="2">
<img src="images/3_line.gif" alt="" border="0"><br></td>
</tr>
<tr>
<td height="38">
<br style="line-height:12px"><script language="javascript"><!--
document.write('<?php echo '
<div style=" text-align:center; width:90%;">
<a href="javascript:popupWindow(\\\''
. tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' .
$product_info['products_id']) . '\\\')">'
. TEXT_CLICK_TO_ENLARGE . '</a></div><br style="line-height:2px;">'; ?>');
//--></script>
<noscript>
<?php echo '<div style=" text-align:center; width:90%;">
<a href="' . tep_href_link(DIR_WS_IMAGES .
$product_info['products_image']) . '" target="_blank">
<br style="line-height:7px">' . TEXT_CLICK_TO_ENLARGE . '</a>
</div>
<br style="line-height:2px;">'; ?>
</noscript>
</td>
<td style=" vertical-align:middle; padding-left:20px;"><strong>
<?=$products_price?></strong><br></td>
</tr>
</table>
This is the code I had to replace with the original one (the one above this code):
<!-- Simple multi image addon -->
<div id="fancy">
<table border="0" cellspacing="0" cellpadding="2" align="right">
<tr>
<td align="center" class="smallText">
<?php
if (strlen($product_info['products_name']) >
$max_title_length)
{
$title = wordwrap(htmlspecialchars($product_info['products_name']),
$max_title_length, '<br>');
}
else
{
$title = htmlspecialchars($product_info['products_name']);
}
$m_source = '';
$thumb = (class_exists('oscthumb') && CFG_MASTER_SWITCH == 'On');
if ($thumb)
{
preg_match('/"([^"]+)"/', htmlentities(tep_image(
DIR_WS_IMAGES .
$product_info['products_image'], '', '', '', '', '', 5),
ENT_NOQUOTES), $image);
$m_source = str_replace('&', '&', $image[1]);
}
echo '<a rel="image_group" title="' . $title . '" href="' . (
$m_source ? $m_source : DIR_WS_IMAGES .
$product_info['products_image']) . '"
alt="' . $product_info['products_name'] . '" target="_blank">' .
tep_image(DIR_WS_IMAGES . $product_info['products_image'],
$product_info['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT,
'hspace="5" vspace="5"', false, 5) . '
<br /></a>';
if (!$vertical_format)
{
echo '';
$row = 1;
reset($products_image_array);
foreach ($products_image_array as $value)
{
if ($thumb)
{
$source = '';
preg_match('/"([^"]+)"/', htmlentities(
tep_image(DIR_WS_IMAGES . $value, '', '', '', '', '', 5), ENT_NOQUOTES),
$image);
$source = str_replace('&', '&', $image[1]);
}
echo '<a rel="image_group" title="' . $title . '" href="' . (
$source ? $source : DIR_WS_IMAGES . $value) . '" target="_blank">' .
tep_image(DIR_WS_IMAGES . $value, $product_info['products_name'],
TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT, 'hspace="5" vspace="5"') .
'</a>';
++$row;
if ($row > $image_group)
{
echo '<br />';
$row = 1;
}
}
}
echo '</td>';
if ($vertical_format)
{
echo '<td>';
$row = 1;
reset($products_image_array);
foreach ($products_image_array as $value)
{
if ($thumb)
{
$source = '';
preg_match('/"([^"]+)"/', htmlentities(
tep_image(DIR_WS_IMAGES . $value, '', '', '', '', '', 5),
ENT_NOQUOTES), $image);
$source = str_replace('&', '&', $image[1]);
}
echo '<a rel="image_group" title="' .
$title . '" href="' . ($source ? $source : DIR_WS_IMAGES . $value) . '"
target="_blank">' .
tep_image(DIR_WS_IMAGES . $value, $product_info['products_name'],
TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT, 'hspace="5" vspace="5"') .
'<br />' . '</a>';
++$row;
if ($row > $image_group)
{
echo '</td><td>';
$row = 1;
}
}
echo '</td>';
}
?>
</tr>
<?php
echo
'<tr><td class="smallText">' . TEXT_CLICK_TO_ENLARGE . '</td></tr>';
?>
</table>
</div>
<!-- EOF Simple multi image addon -->
This is the error it produces on my website:
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in..
includes/functions/database.php on line 99
This is line 99
function tep_db_fetch_array($db_query) {
return mysql_fetch_array($db_query, MYSQL_ASSOC);
}
Any help would be great, excuse me for the formatting of the code, i tried to make it as good as possible, but some echo lines are to long.
Edit:
Posting here, complete database.php
<?php
/*
$Id: database.php,v 1.21 2003/06/09 21:21:59 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
function tep_db_connect(
$server = DB_SERVER,
$username = DB_SERVER_USERNAME,
$password = DB_SERVER_PASSWORD,
$database = DB_DATABASE,
$link = 'db_link') {
global $$link;
if (USE_PCONNECT == 'true') {
$$link = mysql_pconnect($server, $username, $password);
} else {
$$link = mysql_connect($server, $username, $password);
}
if ($$link) mysql_select_db($database);
return $$link;
}
function tep_db_close($link = 'db_link') {
global $$link;
return mysql_close($$link);
}
function tep_db_error(
$query, $errno, $error) {
die('<font color="#000000">
<b>' . $errno . ' - ' . $error . '<br><br>' .
$query . '<br><br><small><font color="#ff0000">
[TEP STOP]</font></small><br><br></b></font>');
}
function tep_db_query($query, $link = 'db_link') {
global $$link;
if (defined('STORE_DB_TRANSACTIONS') && (
STORE_DB_TRANSACTIONS == 'true')) {
error_log('QUERY ' .
$query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
$result = mysql_query($query, $$link) or
tep_db_error($query, mysql_errno(), mysql_error());
if (defined('STORE_DB_TRANSACTIONS') && (
STORE_DB_TRANSACTIONS == 'true')) {
$result_error = mysql_error();
error_log('RESULT ' . $result . ' ' .
$result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
return $result;
}
function tep_db_perform($table, $data, $action = 'insert',
$parameters = '', $link = 'db_link') {
reset($data);
if ($action == 'insert') {
$query = 'insert into ' . $table . ' (';
while (list($columns, ) = each($data)) {
$query .= $columns . ', ';
}
$query = substr($query, 0, -2) . ') values (';
reset($data);
while (list(, $value) = each($data)) {
switch ((string)$value) {
case 'now()':
$query .= 'now(), ';
break;
case 'null':
$query .= 'null, ';
break;
default:
$query .= '\'' . tep_db_input($value) . '\', ';
break;
}
}
$query = substr($query, 0, -2) . ')';
} elseif ($action == 'update') {
$query = 'update ' . $table . ' set ';
while (list($columns, $value) = each($data)) {
switch ((string)$value) {
case 'now()':
$query .= $columns . ' = now(), ';
break;
case 'null':
$query .= $columns .= ' = null, ';
break;
default:
$query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
break;
}
}
$query = substr($query, 0, -2) . ' where ' . $parameters;
}
return tep_db_query($query, $link);
}
function tep_db_fetch_array($db_query) {
line 99
return mysql_fetch_array($db_query, MYSQL_ASSOC);
}
function tep_db_num_rows($db_query) {
return mysql_num_rows($db_query);
}
function tep_db_data_seek($db_query, $row_number) {
return mysql_data_seek($db_query, $row_number);
}
function tep_db_insert_id() {
return mysql_insert_id();
}
function tep_db_free_result($db_query) {
return mysql_free_result($db_query);
}
function tep_db_fetch_fields($db_query) {
return mysql_fetch_field($db_query);
}
function tep_db_output($string) {
return htmlspecialchars($string);
}
function tep_db_input($string, $link = 'db_link') {
global $$link;
if (function_exists('mysql_real_escape_string')) {
return mysql_real_escape_string($string, $$link);
} elseif (function_exists('mysql_escape_string')) {
return mysql_escape_string($string);
}
return addslashes($string);
}
function tep_db_prepare_input($string) {
if (is_string($string)) {
return trim(tep_sanitize_string(stripslashes($string)));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = tep_db_prepare_input($value);
}
return $string;
} else {
return $string;
}
}
?>
The first tep_fetch_array
// Simple multi image addon
$image_group = TINY_IMAGE_GROUP_SIZE; //Number of images to show per row/column
$vertical_format = (ADDITIONAL_IMAGE_FORMAT == 'vertical');
$max_title_length = 40; //Set the maximm length of popup titles before they are broken into multiple lines.
$product_info_query = tep_db_query("select p.products_id, pd.products_name,
pd.products_description, p.products_model, p.products_quantity, p.products_image,
p.products_image_array, pd.products_url, p.products_price,
p.products_tax_class_id, p.products_date_added,
p.products_date_available, p.manufacturers_id from "
. TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where
p.products_status = '1' and p.products_id = '" . (int)
$HTTP_GET_VARS['products_id'] . "' and
pd.products_id = p.products_id and
pd.language_id = '" . (int)$languages_id . "'");
$product_info = tep_db_fetch_array(
$product_info_query);
$products_image_array = unserialize($product_inf0
['products_image_array']);
if (!is_array($products_image_array)) $products_image_array = array();
// EOF Simple multi image addon
Given that error message, the $db_query you're passing in to the tep_db_fetch_array() is obviously not set properly. Somewhere it's getting nulled out, overwritten, referred to out of scope, or you've got a typo in a parameter somewhere.