• Help
  • Search
  • Login
  • Register
  • Home

Forum: web design and graphics community

Celestial Star Forum > Web Development > Coding > PHP Troubles - get option incorrect
Pages: [1]
« previous next »
  Print  
Author Topic: PHP Troubles - get option incorrect  (Read 918 times)
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
PHP Troubles - get option incorrect
« on: May 05, 2008, 11:14:23 AM »

I'm currently trying to create a php-based website, including in the navigation area, with as few pages as possible.  Right now I'm working on the icons database and have run into problems with selecting the correct size of the icon.  For example, a visitor is to click the link 50x100 icons, which is then to take them to a new page.

The php code for the navigation:

Code:
<?php
mysql_connect
(localhost,user,pw);
@
mysql_select_db(db) or die( "Unable to select database");

$query = "select * from icons WHERE size like '%50x100%' LIMIT 1 ";
$result = mysql_query($query);

while(
$row=mysql_fetch_array($result))
{

$size_id=$row["size_id"];

echo 
"<a href=\"iconssize.php?size_id=$size_id\">50x100 Icons";
}
?>

The visitor is correctly transported to the iconssize page, but the icons shown are incorrect.  The page will only show the 120x120 size icons, but if I place the $size_id above the icons in a header, the correct size is shown.  I also cannot ORDER the icons, which makes me believe there is a disconnect somewhere in my code.  I've tried numerous ways to show the correct icons, but to no avail.

Here's the iconssize.php page (I've removed the pagination for simplification):

Code:
<?php

if (is_numeric($_GET["size_id"]))
{
$size_id = $_GET["size_id"];
}

mysql_connect(localhost,user,pw);
@
mysql_select_db(db) or die( "Unable to select database");
$sql="SELECT * FROM `icons` WHERE `size_id` = '$size_id' ORDER BY date desc";
$result = mysql_query( $sql ) or die(mysql_error());

while( 
$row = mysql_fetch_array( $result ) ) {

extract($row);

// dynamic navigation variables
$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=8;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
$last = $pages -1;

if (!isset(
$screen))
$screen=0;
$start = $screen * $rows_per_page;
$query .= "LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die
(
"Could not execute query : $query." . mysql_error());

$i=2;
echo 
'<div class="head">Icons - '.$size.'</div>
<table align="center">'
;

while (
$row = mysql_fetch_array($result))
{

extract($row);

$contents_here = '<table align="center" class="header">
<tr><th height="120">
<img src="'
.$url.'" title="icon" alt="icon">
<td width="120">
<b>Series:</b><br><div class="indent">'
.$series.'</div>
<b>Size:</b><br><div class="indent">'
.$size.'</div>
<b>Added:</b><br><div class="indent">'
.$date.'</div>
</table>'
;

if (
$i==0)
{
echo 
'<tr><td>'.$contents_here.'</td>';
}

else if (
$i==2)
{
echo 
'<td>'.$contents_here.'</td>';
}

else
{
echo 
'<td>'.$contents_here.'</td>';
}

$i++; $i=$i%2;

}
echo 
'</table>

<center>
<div class="pagenav">'
;

        
?>
Logged

ethereal
Skogul
**
Posts: 49


The world is filled with surprise attacks.


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #1 on: May 06, 2008, 01:43:51 AM »

From what I view on your site, the link for avatars are perfectly fine.  They do come out correctly. Though I have quite a difficult time trying to understand you. 

When I look at your code, the way they are arranged are fine, too.  If for some reason the $query do not work, try the code below where you HAVE to type in the exact value size of the icons.  I hope this help.

Code:
$query = "select * from icons WHERE size='120x120' order by date desc ";
Logged

No rose without thorns.
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #2 on: May 06, 2008, 02:14:18 AM »

I'm not sure where you tried the icon links, as I am dealing with an experimental site and not my main site. 

And unfortunately, the problem appears to be coming from the iconssize.php page rather than the index page of the icons.  The navigation links display the correct size id, but upon entering the iconssize.php page the information displayed is incorrect.

Here's a working example of the problem.  When the links in the Icon navigation are clicked, they merely lead to a page repeating the 120x120 icons.  However, the '.$size.' field placed in the header of the page (Icons - '.$size.') depicts the correct size.
Logged

EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #3 on: May 06, 2008, 10:38:45 AM »

I've found that a part of my problem was a repeating script with this line:

Quote
while( $row = mysql_fetch_array( $result ) ) {

extract($row);

above the dynamic pagination script.  However, the problem still persists with clicking the links.
Logged

ethereal
Skogul
**
Posts: 49


The world is filled with surprise attacks.


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #4 on: May 06, 2008, 07:47:24 PM »

Okay, I'm a little clear on what you are trying to say.  It's an experimental site not the main. 

But with the example you provided, I do not see what you describe.  Should I print screen what I see? 

Yes I get the navigation link with icon size etc.  However, it seem that most images are broken link and it's impossible for me to determine the size of the icons.

Is it okay if you repost your edit code again? 
Logged

No rose without thorns.
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #5 on: May 06, 2008, 09:19:13 PM »

The icon images haven't fully be uploaded yet, so the database is reading empty areas.  Also, the size of the images can be read beside the image.

And sure, I can repost the code (slightly modified but still useless to me).  If you think a screenshot of the page will help, then it would be great to see one.

The icon navigation:

Code:
<?php
mysql_connect
(localhost,animara_ham,Alucard666);
@
mysql_select_db(animara_graphics) or die( "Unable to select database");

$query = "SELECT DISTINCT size, size_id FROM icons WHERE `size`='50x100'";
$result = mysql_query($query);

while(
$row=mysql_fetch_array($result))
{

$size_id=$row["size_id"];

echo 
"<a href=\"iconssize.php?size_id=$size_id\">50x100 Icons";
}
?>

<div class="bottomnav"><?php

mysql_connect
(localhost,user,pw);
@
mysql_select_db(db) or die( "Unable to select database");

$query="select * from icons WHERE `size` = '50x100' ";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo 
"~ $num unique icons";

?>
</div></A>

And the iconssize.php page (full code this time):

Code:
<?php

if (is_numeric($_GET["size_id"]))
{
$size_id = $_GET["size_id"];
}

mysql_connect(localhost,user,pw);
@
mysql_select_db(db) or die( "Unable to select database");

$sql="SELECT * FROM `icons` WHERE `size_id` = '$size_id' ORDER BY date desc";
$result = mysql_query( $sql ) or die(mysql_error());

// Insert Code A Here

// dynamic navigation variables
$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];

$rows_per_page=4;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
$last = $pages -1;

if (!isset(
$screen))
$screen=0;
$start = $screen * $rows_per_page;
$query .= "LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die
(
"Could not execute query : $query." . mysql_error());

$i=2;
echo 
'<table align="center">';

while (
$row = mysql_fetch_array($result))
{

extract($row);

$contents_here = '<table align="center" class="header">
<tr><th height="120">
<img src="'
.$url.'" title="avatar" alt="avatar">
<td width="120">
<br><b>Size:</b><br>~ '
.$size.'
</table>'
;

if (
$i==0)
{
echo 
'<tr><td>'.$contents_here.'</td>';
}

else if (
$i==2)
{
echo 
'<td>'.$contents_here.'</td>';
}

else
{
echo 
'<td>'.$contents_here.'</td>';
}

$i++; $i=$i%2;

}
echo 
'</table>

<center>
<div class="pagenav">'
;

if (
$screen == 0)
{
}
else
{
echo 
"<a href=\"$PHP_SELF?a=show&size=$size2&screen=0\">&laquo;&laquo;</a>";
}

// Put Code C Here

        // create the dynamic links
        
if ($screen > 0) {
        
$j = $screen - 1;
        
$url = "$PHP_SELF?a=show&size=$size2&screen=$j";
        echo 
"<a href=\"$url\">&laquo;</a>";
        }
        
        
// page numbering links now
        
$p = 3;                                // number of links to display per page
        
$lower = $p;                    // set the lower limit to $p
        
$upper = $screen+$p;        // set the upper limit to current page + number of links per page
        
while($upper>$pages){
            
$p = $p-1;
            
$upper = $screen+$p;
        }
        if(
$p<$lower){
            
$y = $lower-$p;
            
$to = $screen-$y;
            while(
$to<0){
                
$to++;
            }
        }
        
        if(!empty(
$to))
        {
            for (
$i=$to;$i<$screen;$i++){
                
$url = "$PHP_SELF?a=show&size=$size2&screen=" . $i;
                
$j = $i + 1;
                echo 
"<a href=\"$url\">$j</a>";
            }
        }
        
        for (
$i=$screen;$i<$upper;$i++) {
            
$url = "$PHP_SELF?a=show&size=$size2&screen=" . $i;
            
$j = $i + 1;
            echo 
"<a href=\"$url\">$j</a>";
        }
        
        if (
$screen < $pages-1) {
        
$j = $screen + 1;
        
$url = "$PHP_SELF?a=show&size=$size2&screen=$j";
        echo 
"<a href=\"$url\">&raquo;</a>";
        }

if (
$screen == $last)
{
}
else {
echo 
"<a href=\"$PHP_SELF?a=show&size=$size2&screen=$last\">&raquo;&raquo;</a>";
}

        
?>
Logged

ethereal
Skogul
**
Posts: 49


The world is filled with surprise attacks.


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #6 on: May 08, 2008, 12:49:17 AM »

The code seem right, but I don't know what is wrong with it.  Maybe it's something to do with when you insert into the database.  Check your sql in the database.

Did you do this coding by yourself?  Or did you get it from a tutorial or a site?  If you did get it from a tutorial, may I see the site to see what's going on.  Maybe it will be clearer. 

I finally notice that when you click 50x100 it link to 120x120 and every single one of them link to 120x120.  (sorry I didnt see it earlier -__-)
Logged

No rose without thorns.
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #7 on: May 08, 2008, 10:19:52 AM »

I've used this same database for other areas of my site and the sql works fine.  Also, the code is a mix of tutorials and my own creation, so there's not really one site where you may find an example.

I also doubt the coding could get much cleaner, since I've eliminated all I can.
Logged

ethereal
Skogul
**
Posts: 49


The world is filled with surprise attacks.


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #8 on: May 09, 2008, 11:12:31 PM »

Hm...This is a tough situation.  Give me a few days (7) to try the code and work it out.  Hopefully maybe I can find something missing or why is it incorrect.  Sorry for the long wait.  I can't figure out why it behave that way.  I'll try my best to help out as I can.
Logged

No rose without thorns.
EternalSorrow
Retribution
***
Posts: 162


Got milk duds?


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #9 on: May 10, 2008, 08:14:39 PM »

Thankfully the problem's been solved.  Apparently the series page was incorrectly querying the database by using the sql command rather than the query command.
Logged

ethereal
Skogul
**
Posts: 49


The world is filled with surprise attacks.


View Profile WWW
Re: PHP Troubles - get option incorrect
« Reply #10 on: May 12, 2008, 12:20:20 AM »

Oh my goodness,   Shocked  I was going to try it out, but I guess I don't have to anymore.  Glad you found out the problem.  Smiley
Logged

No rose without thorns.
Pages: [1]
  Print  
« previous next »
 
Jump to:  

  • Welcome, Guest
  • Members login
  • Register for free

General

  • General
  • New members
  • Announcements
  • Support / Suggestions

Art boards

  • Creative mediums
  • Requests and offers
  • Tutorials
  • Celestial Star tutorials

Web development

  • Coding
  • Web design
  • Advertisements / affiliation

Off-topic

  • The non-sense
  • Ententainment

Go up
eXTReMe Tracker
  • Valid XHTML
  • Valid CSS
Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC | Seo4Smf v0.2 © Webmaster's Talks
Loading...