Insertion image

anel12089
Invité n'ayant pas de compte PHPfrance

03 nov. 2010, 16:33

Bonjour a tous, j'ai recupérer un script que je modifie tant bien que mal.

Je rencontre un probleme concernant l'affichage d'image qui sont stocké dans un répertoire avec un lien en sql.
Pour faire simple sur le script d'origine y'a une image qui fonctionne parfaitement en affichage, j'ai simplement créer un champ supplémentaire dans la table et je souhaitez donc afficher une 2 em image par rapport a ce champ, mais j'ai beau tout tester ca ne fonctionne pas.

Je vous met la partie de code d'origine qui affiche sans problème une image de la table adpics et je souhaitez simplement afficher une image d'une table adpics2.

Merci pour une aide éventuelle ;)
<?php




require_once("initvars.inc.php");
require_once("config.inc.php");
  
if($image_verification) 
{
	require_once("captcha.cls.php");
	$captcha = new captcha();
}

$msg = "";
$err = "";

?>

<?php

if (!$_GET['adid'])
{
	header("Location: $script_url/?view=main&cityid=$xcityid&lang=$xlang");
	exit;
}


$adtable = ($_GET['view'] == "showevent") ? $t_events : $t_ads;
$adid_prefix = (($xview == "events") ? "E" : "A");
$full_adid = ($adid_prefix . $xadid);
$reported = explode(";", $_COOKIE["reported"]);
$is_reported = in_array($full_adid, $reported);


$qsA = $_GET; $qs = "";
unset($qsA['do'], $qsA['reported'], $qsA['mailed'], $qsA['mailerr'], $qsA['msg'], $qsA['err']);
foreach ($qsA as $k=>$v) $qs .= "$k=$v&";

if ($_GET['do'] == "reportabuse")
{
    if (!$is_reported) {

		
    	$sql = "UPDATE $adtable 
    			SET abused = abused + 1 
    			WHERE adid = $_GET[adid] 
    				AND abused < " . ($spam_indicator - 1);
    	
    	mysql_query($sql) or die($sql);
    
    	if(mysql_affected_rows())
    	{
    		echo "<div class=\"msg\">$lang[MESSAGE_ABUSE_REPORT]</div>";
    		
    		if($max_abuse_reports)
    		{
    			
    			$sql = "UPDATE $adtable 
    					SET enabled = '0' 
    					WHERE adid = $_GET[adid]
    						AND abused >= $max_abuse_reports";
    			mysql_query($sql);
    			
    		}
    
    		header("Location: $script_url/?{$qs}reported=y");
    		exit;
    	}
    }

	unset($_GET['do']);
}


if ($xview == "showevent")
{
	
	$sql = "SELECT a.*, UNIX_TIMESTAMP(a.timestamp) AS timestamp, UNIX_TIMESTAMP(a.createdon) AS createdon, UNIX_TIMESTAMP(a.expireson) AS expireson, UNIX_TIMESTAMP(feat.featuredtill) AS featuredtill,
			UNIX_TIMESTAMP(a.starton) AS starton, UNIX_TIMESTAMP(a.endon) AS endon
		FROM $t_events a
			LEFT OUTER JOIN $t_featured feat ON a.adid = feat.adid AND feat.adtype = 'E'
		WHERE a.adid = $xadid
			AND $visibility_condn_admin";
	$ad = mysql_fetch_array(mysql_query($sql));
	
$sql = "SELECT *
		FROM $t_adpics2
		WHERE adid = $xadid";
	$ad = mysql_fetch_array(mysql_query($sql));
	
	$isevent = 1;

	
	$thisurl = buildURL($xview, array($xcityid, $xdate, $xadid, $ad['adtitle']));
	

}
else
{
	
	$xfieldsql = "";
	if(count($xsubcatfields)) 
	{
		for($i=1; $i<=$xfields_count; $i++)	$xfieldsql .= ", axf.f$i";
	}

	
	$sql = "SELECT a.*, ct.cityname as cityname, UNIX_TIMESTAMP(a.timestamp) AS timestamp, UNIX_TIMESTAMP(a.createdon) AS createdon, UNIX_TIMESTAMP(a.expireson) AS expireson, UNIX_TIMESTAMP(feat.featuredtill) AS featuredtill $xfieldsql
			FROM $t_ads a
				INNER JOIN $t_subcats scat ON scat.subcatid = a.subcatid
                INNER JOIN $t_cities ct ON a.cityid = ct.cityid
				LEFT OUTER JOIN $t_adxfields axf ON a.adid = axf.adid
				LEFT OUTER JOIN $t_featured feat ON a.adid = feat.adid AND feat.adtype = 'A'
			WHERE a.adid = $xadid
				AND $visibility_condn_admin";
	$ad = mysql_fetch_array(mysql_query($sql));

	$isevent = 0;
	
	$thisurl = buildURL($xview, array($xcityid, $xcatid, $xcatname, $xsubcatid, $xsubcatname, 
	    $xadid, $ad['adtitle']));
	

}


if (!$ad) 
{
    
	header("Location: $script_url/index.php?view=post404&cityid=$xcityid&lang=$xlang");
    
	exit;
}


if ($_POST['email'] && $_POST['mail'] && $ad['showemail'] == EMAIL_USEFORM)
{
	$err = "";
	
	if ($image_verification && !$captcha->verify($_POST['captcha']))
	{
		$err .= $lang['ERROR_IMAGE_VERIFICATION_FAILED'] . "<br>";
	}
	if (!ValidateEmail($_POST['email'])) 
	{
		$err .= $lang['ERROR_INVALID_EMAIL'] . "<br>";
	}

	if (preg_match("/[\\000-\\037]/", $_POST['email']))
	{
		handle_security_attack("@");
	}
	else if (!$err)
	{
		$thismail_header = file_get_contents("mailtemplates/contact_header.txt");
		$thismail_header = str_replace("{@SITENAME}", $site_name, $thismail_header);
		$thismail_header = str_replace("{@ADTITLE}", $ad['adtitle'], $thismail_header);
		$thismail_header = str_replace("{@ADURL}", "{$script_url}/{$thisurl}", $thismail_header);
		$thismail_header = str_replace("{@FROM}", $_POST['email'], $thismail_header);

		$thismail_footer = file_get_contents("mailtemplates/contact_footer.txt");
		$thismail_footer = str_replace("{@SITENAME}", $site_name, $thismail_footer);
		$thismail_footer = str_replace("{@ADTITLE}", $ad['adtitle'], $thismail_footer);
		$thismail_footer = str_replace("{@ADURL}", "{$script_url}/{$thisurl}", $thismail_footer);
		$thismail_footer = str_replace("{@FROM}", $_POST['email'], $thismail_footer);

		$msg = $thismail_header . "\n" .
				stripslashes($_POST['mail']) . "\n" .
				$thismail_footer;		
		
        $xtraheaders = array("Reply-To: " . $_POST['email']);

		$mailerr = sendMail($ad['email'], $lang['MAILSUBJECT_CONTACT_FORM'], $msg, 
			$site_email, $langx['charset'], "attach", $xtraheaders);
		
		
        if ($mailerr)
		{
			$mailresult = "n";
			if ($mailerr == "FAILED") $mailerr = "";
		}
		else 
		{
            $mailresult = "y";
        }

		header("Location: $script_url/?$qs&mailed=$mailresult&mailerr=$mailerr");
		exit;
	}

}

$sql = "SELECT *
		FROM $t_adpics p
		WHERE p.adid = $xadid
			AND isevent = '$isevent'";
$pres = mysql_query($sql);


?>


<script language="javascript">
function confirmAbuseReport()
{
	if (confirm('<?php echo addslashes($lang['REPORT_ABUSE_CONFIRM']); ?>'))
	{
        
        eval("location.href = '?' + '<?php echo $qs; ?>' + 'do=reportabuse'");
        
	}
}
</script>


<?php

if ($_GET['reported']) {
    $reported[] = $full_adid;
    setcookie("reported", implode(";", $reported), time()+90*24*60*60, "/");
    $is_reported = true;
}

?>


<?php

if(!$_POST['mail'])
{
	if($_GET['mailed'] == "y")		{ $msg .= $lang['MESSAGE_MAIL_SENT']."<br>"; }
	elseif ($_GET['mailed'] == "n")	{ $err .= $lang['ERROR_MAIL_NOT_SENT']."<br>".$_GET['mailerr']."<br>"; }

	if($_GET['reported'] == "y")	{ $msg .= $lang['MESSAGE_ABUSE_REPORT']."<br>"; }
}

if($_GET['msg'])				{ $msg .= nl2br(htmlentities($_GET['msg']))."<br>"; }
if($_GET['err'])				{ $err .= nl2br(htmlentities($_GET['err']))."<br>"; }

?>

<?php

if($err) echo "<div class=\"err\">$err</div>";
if($msg) echo "<div class=\"msg\">$msg</div>";

?>
<?php include_once("inc/prev_next.inc.php");?>
<?php if($ad['featuredtill'] && $ad['featuredtill'] > time()) { ?>
<div class="msg">
<img src="images/featured.gif" align="absmiddle">
<b><?php echo $lang['THIS_AD_IS_FEATURED']; ?></b>
</div>
<?php } ?>

<table class="postheader" width="100%"> 
<tr>
<td>

<div align="right">

<?php if(!$is_reported) { ?><a href="javascript:confirmAbuseReport();"><?php echo $lang['REPORT_ABUSE']; ?></a> | <?php } ?>
<a href="?view=mailad&cityid=<?php echo $xcityid; ?>&adid=<?php echo $xadid; ?>&adtype=<?php echo $xadtype; ?><?php if($xdate) echo "&date={$xdate}"; ?>"><?php echo $lang['EMAIL_THIS_AD_LINK']; ?></a></div>
<?php echo $lang['POST_ID']; ?> <?php echo ($xview=="showevent"?"E":"A"); ?><?php echo $ad['adid']; ?><br><br>
<?php
if ($xview == "showevent")
{
?>
	<b><?php echo date("d", $ad['starton'])." ".$langx['months_short'][date("n", $ad['starton'])-1] . ", " . date("y", $ad['starton']); ?>
	<?php if($ad['starton'] != $ad['endon']) echo " - " . date("d", $ad['endon']) . " " . $langx['months_short'][date("n", $ad['endon'])-1] . ", " . date("y", $ad['endon']); ?></b>
	<br>

<?php
}

?>

<div class="posttitle"> 
<?php echo $ad['adtitle']; ?>
<?php 
$loc = "";
if($ad['area']) $loc = $ad['area'];
if($xcityid < 0) $loc .= ($loc ? ", " : "") . $ad['cityname'];
if($loc) echo " <span class=\"adarea\">($loc)</span>";
?>
</div>
<table width="971" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="370"><b><?php echo $lang['AD_DATE']; ?></b>: <?php echo QuickDate($ad['createdon']); ?><br />
      <b><?php echo $lang['REPLY_TO']; ?></b>:
      <?php if ($ad['showemail'] == EMAIL_SHOW) { ?>
      <a href="mailto:<?php echo $ad['email']; ?>"><?php echo $ad['email']; ?></a>
      <?php } elseif ($ad['showemail'] == EMAIL_USEFORM) { ?>
      <i><?php echo $lang['USE_CONTACT_FORM']; ?></i>
      <?php } else { ?>
      <i><?php echo $lang['EMAIL_NOT_SHOWN']; ?></i>
      <?php } ?>
      <br />
      <p>
        <?php
	while ($row = mysql_fetch_array($pres))
	{
		$i++;

		$imgsize = GetThumbnailSize("{$datadir[adpics]}/{$row[picfile]}", $images_max_width, $images_max_height);

?>
        <img src="<?php echo "{$datadir[adpics]}/{$row[picfile]}"; ?>" id="adimg<?php echo $i; ?>" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>" />  <br />
        <br />
        <a href="<?php echo "{$datadir[adpics]}/{$row[picfile]}"; ?>" id="adimg<?php echo $i; ?>"></a>
		 </p>
      <p></p></td>
    <td width="601" bgcolor="#f9ebd0"><?php echo generateHtml($ad['addesc'], $ad['createdon']); ?><br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br /></td>
  </tr>
</table>
<br>
<table class="postpics" width="99%">
  <tr>
    <td width="49%" height="223"><p align="center">
      <?php
	}
?><br />
      <a href="images/<?php echo ($ad['pv']); ?>"><img src="images/pv.jpg" width="160" height="160" border="0" /></a></p></td>
    <td width="51%"><div align="center"><br />
    <br /> 
        <br />
        <object width="410" height="251">
        <param name="movie" value="<?php echo ($ad['you']); ?>" />
        </param>
        <param name="allowFullScreen" value="true" />
        </param>
        <param name="allowscriptaccess" value="always" />
        </param>
        <embed src="<?php echo ($ad['you']); ?>" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="410" height="251"></embed>
      </object>
        &nbsp;</div></td>
  </tr>
</table></td>
</tr>
</table>

<?php
if(($xsubcathasprice && $ad['price']) || count($xsubcatfields))
{
    
    $actualfields = $xsubcathasprice ? 1 : 0;
?>
<div></div>
<?php if ($actualfields) { ?>
<div style="border-bottom:1px solid #E0E0E0;">&nbsp;</div>
<?php } ?>
<?php
    
}
?>

<table class="post" width="100%"><tr><td>&nbsp;</td>
</tr></table>

<?php

if (@mysql_num_rows($pres))
{
	$i = 0;
?>
<?php

	$imgcnt = $i;

}
?>
<?php 
if($ad['othercontactok']) echo "<p class=\"disclosure_yes\">$lang[COMMERCIAL_CONTACT_OK]</p>";
else echo "<p class=\"disclosure_no\">$lang[COMMERCIAL_CONTACT_NOT_OK]</p>";
?>
<?php
$hits = $ad['hits'];
$already_hit = explode(";", $_COOKIE["hits"]);
if (!in_array($full_adid, $already_hit)) {
    $sql = "update $adtable set hits = hits + 1, timestamp = timestamp where adid = $xadid";
    mysql_query($sql);
    $already_hit[] = $full_adid;
    setcookie("hits", implode(";", $already_hit), 0, "/");
    $hits++;
}
?>
<div class="hits">Vue <?php echo $hits; ?> fois<br><br></div>
<br style="clear:both">



<?php if ($ad['showemail'] == EMAIL_USEFORM) { 

/*$qs = ""; $qsA = $_GET; unset($qsA['syndicate']);
foreach ($qsA as $k=>$v) $qs .= "$k=$v&";*/

?>

	<form action="<?php echo "$script_url/?$qs"; ?>" method="post" enctype="multipart/form-data">
	<table class="contactform">
	<tr>
		<th colspan="2"><?php echo $lang['CONTACT_USER']; ?>:<a name="contactform">&nbsp;</a>
</th>
	</tr>
	<tr><td colspan="2">&nbsp;</td></tr>
	<tr>
		<td><?php echo $lang['YOUR_EMAIL']; ?>: <span class="marker">*</span></td>
		<td>
		<input type="text" size="65" name="email">
		</td>
	</tr>
	<tr>
		<td valign="top"><?php echo $lang['YOUR_MESSAGE']; ?>: <span class="marker">*</span></td>
		<td>
		<textarea cols="64" rows="10" name="mail"></textarea>
		</td>
	</tr>
	<tr>
		<td valign="top"><?php echo $lang['ATTACHMENT']; ?>:</td>
		<td>
		<input type="file" size="55" name="attach"><br>
		<span class="hint"><?php echo $lang['UNSUPPORTED_ATTACHEMNTS']; ?>: <?php echo implode(", ", $contactmail_attach_wrongfiles); ?><br>
		<?php echo $lang['MAX_ATTACHMENT_SIZE']; ?>: <?php echo $contactmail_attach_maxsize; ?>KB</span>
		</td>
	</tr>

	<?php
	if($image_verification)
	{
	?>

		<tr>
			<td valign="top"><?php echo $lang['POST_VERIFY_IMAGE']; ?>: <span class="marker">*</span></td>
			<td>
			<img src="captcha.png.php?<?php echo rand(0,999); ?>"><br>
			<span class="hint"><?php echo $lang['POST_VERIFY_IMAGE_HINT']; ?></span><br>
			<input type="text" name="captcha" value="">
			</td>
		</tr>

	<?php
	}
	?>

	<tr>
		<td>&nbsp;</td>
		<td><button type="submit"><?php echo $lang['BUTTON_SEND_MAIL']; ?></button></td>
	</tr>
	</table>
	</form>

<?php } ?>

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

03 nov. 2010, 17:43

salut,

la balise bbcode pour affichier du code php c'est
. La c'est un gros paté c'est peut lisible :/

j'ai vu un effort dans le lot 
[php]
<?php

$sql = "SELECT a.*, UNIX_TIMESTAMP(a.timestamp) AS timestamp, UNIX_TIMESTAMP(a.createdon) AS createdon, UNIX_TIMESTAMP(a.expireson) AS expireson, UNIX_TIMESTAMP(feat.featuredtill) AS featuredtill,
UNIX_TIMESTAMP(a.starton) AS starton, UNIX_TIMESTAMP(a.endon) AS endon
FROM $t_events a
LEFT OUTER JOIN $t_featured feat ON a.adid = feat.adid AND feat.adtype = 'E'
WHERE a.adid = $xadid
AND $visibility_condn_admin";
$ad = mysql_fetch_array(mysql_query($sql));

$sql = "SELECT *
FROM $t_adpics2
WHERE adid = $xadid";
$ad = mysql_fetch_array(mysql_query($sql));
?>
Mais la deuxième affectation de la variable $sql écrase la première donc effectivement la requête énorme du dessus ne fonctionne plus;

Sur le principe il te faut faire une deuxième requête et un second mysql_query après utilisation du premier lorsque tu veut afficher l'image.

Je t'invite à lire cet article sur l'utilisation du select *

Je pense qu'il serait préférable de demander à l'auteur du script de l'aide se serait plus simple ;)

@+
Il en faut peu pour être heureux ......

anel12089
Invité n'ayant pas de compte PHPfrance

03 nov. 2010, 18:08

Merci deja pour cette info je vais essayé de voir de ce coter la, mais l'auteur ne répond pas vraiment au demande que l'ont envoie lol.

Merci quand même pour cette petite info ;)