Jump to content

country repeats for each HeaderID in Loop??


jarv

Recommended Posts

ok here is my code my problem is is that $Country shows

CHINA

CHINA

CHINA

CHINA

and so on... in the loop

CHINA is HeaderID = 1 the next one in the Headertbl table is USA but that doesn't show?!

 

<?php
include_once("config.php");
include_once("functions.php");
// Check user logged in already:
// checkLoggedIn("yes");
doCSS(); ?>
<div id="header">
<p class="wrap">

<? print("\n <a href=\"post.php"."\">+ Add new header</a> ");?>
</p>
<h1 class="wrap">Avert Weekly Headers</h1>
</div>
<?
include_once("config.php");
$result = mysql_query("SELECT * FROM Headertbl ORDER BY HeaderDate DESC");
$result1 = mysql_fetch_array(mysql_query("SELECT * FROM Headertbl LEFT JOIN country ON Headertbl.CountryID = country.CountryID"));

$Country = $result1['country'];
?>

<? print($result1['country']);?>
<?
while($row = mysql_fetch_array($result))


{
echo '<div id="entry" class="wrap">';
$HeaderID = $row['HeaderID'];
$HeaderImage = $row['HeaderImage'];
$HeaderDate = $row['HeaderDate'];
$HeaderPhotoNo = $row['HeaderPhotoNo'];
$HeaderName = $row['HeaderName'];
$PhotoID = $row['PhotoID'];
$CountryID = $row['CountryID'];




$output =<<<EOF
  <div class="entry_header">
    <b>Header Name:</b> $HeaderName <a href="edit.php?HeaderID=$HeaderID">Edit Header</a> | <a href="delete.php?HeaderID=$HeaderID">Delete Header</a><br />$Country
 <a href="upload.php?HeaderID=$HeaderID">Change Header</a><br />
  <a href="http://www.avert.org/photo_search.php?search_keyword_id=&search_country_id=country-$CountryID&page_type=thumbnails&search=search">Other pictures from </a><br />
<b>PhotoID:</b> $PhotoID <br />
<b>Header Photo No:</b> $HeaderPhotoNo <br />
<b>Header Date:</b> $HeaderDate <br />
<img src="headers/$HeaderImage">
  </div>
EOF;
echo $output;
echo '</div>';
}

mysql_close($link);
?>

You're setting $Country outside the loop, so it doesn't change.

 

Also, you should always use long tags "<?php", not short tags "<?".

 

Why are you constantly going in and out of PHP.

 

One more, why make the variable $output, when you can just echo the string:

<?php
echo <<<EOF
  <div class="entry_header">
    <b>Header Name:</b> $HeaderName <a href="edit.php?HeaderID=$HeaderID">Edit Header</a> | <a href="delete.php?HeaderID=$HeaderID">Delete Header</a><br />$Country
 <a href="upload.php?HeaderID=$HeaderID">Change Header</a><br />
  <a href="http://www.avert.org/photo_search.php?search_keyword_id=&search_country_id=country-$CountryID&page_type=thumbnails&search=search">Other pictures from </a><br />
<b>PhotoID:</b> $PhotoID <br />
<b>Header Photo No:</b> $HeaderPhotoNo <br />
<b>Header Date:</b> $HeaderDate <br />
<img src="headers/$HeaderImage">
  </div>
EOF;
?>

 

Ken

You have to move the query also.

 

Ken

 

but i have done this

 

<?
include_once("config.php");
$result = mysql_query("SELECT * FROM Headertbl ORDER BY HeaderDate DESC");


while($row = mysql_fetch_array($result))


{
echo '<div id="entry" class="wrap">';
$HeaderID = $row['HeaderID'];
$HeaderImage = $row['HeaderImage'];
$HeaderDate = $row['HeaderDate'];
$HeaderPhotoNo = $row['HeaderPhotoNo'];
$HeaderName = $row['HeaderName'];
$PhotoID = $row['PhotoID'];
$CountryID = $row['CountryID'];



$result1 = mysql_fetch_array(mysql_query("SELECT * FROM Headertbl LEFT JOIN country ON Headertbl.CountryID = country.CountryID"));
$Country = $result1['country'];

echo <<<EOF
  <div class="entry_header">
    <b>Header Name:</b> $HeaderName <a href="edit.php?HeaderID=$HeaderID">Edit Header</a> | <a href="delete.php?HeaderID=$HeaderID">Delete Header</a><br />
 <a href="upload.php?HeaderID=$HeaderID">Change Header</a><br />
  <a href="http://www.avert.org/photo_search.php?search_keyword_id=&search_country_id=country-$CountryID&page_type=thumbnails&search=search">Other pictures from $Country</a><br />
<b>PhotoID:</b> $PhotoID <br />
<b>Header Photo No:</b> $HeaderPhotoNo <br />
<b>Header Date:</b> $HeaderDate <br />
<img src="headers/$HeaderImage">
  </div>
EOF;
}

?>

 

ok so now i have added WHERE Header ID =".$result['HeaderID']; at teh end of my query

now i get an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Users/staff/Sites/johns/headers/display.php on line 34

<?php
include_once("config.php");
include_once("functions.php");
// Check user logged in already:
// checkLoggedIn("yes");
doCSS(); ?>
<div id="header">
<p class="wrap">

<? print("\n <a href=\"post.php"."\">+ Add new header</a> ");?>
</p>
<h1 class="wrap">Avert Weekly Headers</h1>
</div>
<?
include_once("config.php");
$result = mysql_query("SELECT * FROM Headertbl ORDER BY HeaderDate DESC");


while($row = mysql_fetch_array($result))


{
echo '<div id="entry" class="wrap">';
$HeaderID = $row['HeaderID'];
$HeaderImage = $row['HeaderImage'];
$HeaderDate = $row['HeaderDate'];
$HeaderPhotoNo = $row['HeaderPhotoNo'];
$HeaderName = $row['HeaderName'];
$PhotoID = $row['PhotoID'];
$CountryID = $row['CountryID'];



$result1 = mysql_fetch_array(mysql_query("SELECT * FROM Headertbl LEFT JOIN country ON Headertbl.CountryID = country.CountryID WHERE HeaderID =".$result['HeaderID']));
$Country = $result1['country'];

echo <<<EOF
  <div class="entry_header">
    <b>Header Name:</b> $HeaderName <a href="edit.php?HeaderID=$HeaderID">Edit Header</a> | <a href="delete.php?HeaderID=$HeaderID">Delete Header</a><br />
 <a href="upload.php?HeaderID=$HeaderID">Change Header</a><br />
  <a href="http://www.avert.org/photo_search.php?search_keyword_id=&search_country_id=country-$CountryID&page_type=thumbnails&search=search">Other pictures from $Country</a><br />
<b>PhotoID:</b> $PhotoID <br />
<b>Header Photo No:</b> $HeaderPhotoNo <br />
<b>Header Date:</b> $HeaderDate <br />
<img src="headers/$HeaderImage">
  </div>
EOF;
echo '</div>';
}

mysql_close($link);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.