Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling from mysql to echo error

    http://integyfacts.com/betafolder/wo...mages&imgid=60

    On the right side of my page im trying to get the script to echo the clicks for the image. The echo works in the description. Please look at my right side to see if you can pinpoint any coding errors.

    PHP Code:
    <h5>Number of Clicks</h5></i><? echo mysql_result($yy,0,"img_clicked"); ?></td></td>';
    is where i am calling the echo

    PHP Code:
    <table border="0">

      <?php
        $query
    ="select * from wp_imgManager_images where img_isapproved='Y' ORDER BY img_clicked DESC";
        
    $result=mysql_query($query);
        
    $rcount=mysql_num_rows($result);
        
    $imgid=$_GET['imgid'];
        
    $dd="select * from wp_imgManager_images where id='".$imgid."'";
        
    $yy=mysql_query($dd);
        if(
    $rcount>0)
        {
            
    $icount=0;
            echo 
    '<tr>';
            
    $colcount=0;
            
            for(
    $i=0;$i<$rcount;$i++)
            {
                    
    $icount=$icount+1;
                    
    $colcount=$colcount+1;
                    if(
    $icount==8)
                        break;
                    
                    if(
    $colcount==3)
                    {
                        
    $colcount=1;
                        echo 
    '</tr><tr>';
                    }
                    
    $icatid=mysql_result($result,$i,"img_cat_id");
                    
    $qq="select cat_virt_path from wp_imgManager_categories where id='".$icatid."'";
                    
    //echo $qq;
                    
    $rr=mysql_query($qq);
                    
    $vcpath=mysql_result($rr,0,"cat_virt_path");
                    
    $imgPath=$vcpath."/".mysql_result($result,$i,"id").".".mysql_result($result,$i,"img_fileextn");;
                    echo 
    '<td width="110" align="center"><a href="?page=images&imgid='.mysql_result($result,$i,"id").'"><img width="100" height="100" src="'.$imgPath.'"></a><i><h5>Number of Clicks</h5></i><? echo mysql_result($yy,0,"img_clicked"); ?></td></td>';
            }
            if(
    $icount==0)
            {
                echo 
    '<td>No latest images</td></tr>';
            }
            else
            {
                echo 
    '</tr><tr><td colspan=3 align="right"><a href="?page=images">more..</a></td></tr>';
            }
        }
        else
        {
            echo 
    "No latest images!!";
        }

     
    ?>
     
    </table>

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Not even sure of what all is going on in this script. It appears as though you have 3 query calls to the database? One of which is inside this loop?

    Please, please, please refactor your code using a proper JOIN statement. Also, don't use a for() loop with the mysql_result() function. Ideally this can all be distilled into a single SQL statement / query call, and a simple while() loop utilizing one of the mysql_fetch_* functions (mysql_fetch_assoc() being the preferred choice).

    Oh, and the one glaring error I see is that you have an echo statement embedded within another:
    PHP Code:
    <h5>Number of Clicks</h5></i><? echo mysql_result($yy,0,"img_clicked"); ?></td></td>';


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •