Hi guys. I am currently working on my first ever PHP MYSQL website (for my brother’s first book), and I am very excited about it.
The site is PHP site, with a MySQL database. It all takes place on a single Index page where a couple of functions pull a Navigation menu from a CSS style-sheet, and the content pages from MySQL. Again, the images are not stored in the database. They are in a folder and the menu function pulls the CSS to display them.
The content function displays the text coming straight from from MySQL. The issue that I am having is that every time I click in any of the menu buttons (left side of the page), there’s a page flick or flash, which is very annoying. It seems that everything is being reloaded on each page click, which I guess causes the flick.
I even tried pre-loading all site images in a hidden div (hidden with css). Here’s the website: http://www.javierbooks.com/index.php
and here’s the code for the menu function:
[php]function menuDisplay(){
$query = mysql_query(“SELECT id, title, linklabel FROM mybooks WHERE showing =‘1’ ORDER BY id ASC”) or die(mysql_error());
// DETERMINE which page ID to USE in our query below ********************************************************************------------------------------
if (!isset($_GET['pid'])) {
$pageid = '1';
} else {
$pageid = preg_replace('#[^0-9]#i', '', $_GET['pid']); // filter everything but numbers for security(new)
//preg_replace($pattern, $replacement, $string);//preg_replace() Function structure
//***********************************************************************************************************************
}
$menuDisplay = ‘’;
while ($row = mysql_fetch_assoc($query)) {
$pid = $row[‘id’];
$postLinkLabel = $row[‘linklabel’];
//Prepare to Show and Highlight buttons
if($pageid==$pid){
//$pid = mysql_real_escape_string($pid);
//$menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';//original link
//DISPLAY BUTTONS - HIGHLIGHTED STATE
if( ($row['title']) == 'Inicio'){
$menuDisplay .= '<li class="inicio_selected"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel. '</a></li>';}
if( ($row['title']) == 'Autor'){
$menuDisplay .= '<li class="autor_selected"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel. '</a></li>';}
if( ($row['title']) == 'Libros'){
$menuDisplay .= '<li class="libros_selected"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel . '</a></li>';}
if( ($row['title']) == 'Discusion'){
$menuDisplay .= '<li class="discusion_selected"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel . '</a></li>';}
if( ($row['title']) == 'Ventas'){
$menuDisplay .= '<li class="ventas_selected"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel . '</a></li>';}
if( ($row['title']) == 'Contacto'){
$menuDisplay .= '<li class="contacto_selected"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel . '</a></li>';}
}
//DISPLAY BUTTONS - NORMAL STATE
else{
if( ($row[‘title’]) == ‘Inicio’)
$menuDisplay .= ’
if( ($row['title']) == 'Autor')
$menuDisplay .= '<ul class="menu"><li class="autor_but"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel . '</a></li>';
if( ($row['title']) == 'Libros')
$menuDisplay .= '<ul class="menu"><li class="libros_but"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel . '</a></li>';
if( ($row['title']) == 'Discusion')
$menuDisplay .= '<ul class="menu"><li class="discusion_but"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel . '</a></li>';
if( ($row['title']) == 'Ventas')
$menuDisplay .= '<ul class="menu"><li class="ventas_but"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel. '</a></li>';
if( ($row['title']) == 'Contacto')
$menuDisplay .= '<li class="contacto_but"> <a href="index.php?pid='.$pid. '">' . $postLinkLabel . '</a></li>';
}
}
echo $menuDisplay;
}[/php]
The content function is similar:
[php]function bookContent(){
// DETERMINE which page ID to USE in our query below ********************************************************************
if (!isset($_GET['pid'])) {
$pageid = '1';
} else {
$pageid = preg_replace('#[^0-9]#i', '', $_GET['pid']);} // filter everything but numbers for security(new)
//preg_replace($pattern, $replacement, $string);//preg_replace() Function structure
// Query the body section for the proper page
$query = mysql_query ("SELECT content,title,author FROM mybooks WHERE id = '$pageid' LIMIT 1") or die (mysql_error());
while ($row = mysql_fetch_array($query)) {
echo $row['title'].' by ';
echo '<b>'.$row['author']. '</b><br>';
echo $row['content'].'<br><p>';
}
}[/php]
Can anybody help me figure out why the page flick is occurring?
Thanks in advance for your help.