...

View Full Version : Calling from mysql to echo error



bigredkacy
03-26-2009, 07:48 AM
http://integyfacts.com/betafolder/wordpress/?page=images&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.


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



<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>

bdl
03-26-2009, 08:28 AM
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 (http://www.lmgtfy.com?q="SQL+JOIN+tutorial"). 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:


<h5>Number of Clicks</h5></i><? echo mysql_result($yy,0,"img_clicked"); ?></td></td>';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum