jarv Posted June 26, 2008 Share Posted June 26, 2008 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); ?> Link to comment https://forums.phpfreaks.com/topic/112020-country-repeats-for-each-headerid-in-loop/ Share on other sites More sharing options...
kenrbnsn Posted June 26, 2008 Share Posted June 26, 2008 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 Link to comment https://forums.phpfreaks.com/topic/112020-country-repeats-for-each-headerid-in-loop/#findComment-574999 Share on other sites More sharing options...
jarv Posted June 26, 2008 Author Share Posted June 26, 2008 ok so i moved $Country = $result1['country']; inside the loop and it still says china?! Link to comment https://forums.phpfreaks.com/topic/112020-country-repeats-for-each-headerid-in-loop/#findComment-575010 Share on other sites More sharing options...
kenrbnsn Posted June 26, 2008 Share Posted June 26, 2008 You have to move the query also. Ken Link to comment https://forums.phpfreaks.com/topic/112020-country-repeats-for-each-headerid-in-loop/#findComment-575013 Share on other sites More sharing options...
jarv Posted June 26, 2008 Author Share Posted June 26, 2008 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; } ?> Link to comment https://forums.phpfreaks.com/topic/112020-country-repeats-for-each-headerid-in-loop/#findComment-575017 Share on other sites More sharing options...
jarv Posted June 26, 2008 Author Share Posted June 26, 2008 please help!! Link to comment https://forums.phpfreaks.com/topic/112020-country-repeats-for-each-headerid-in-loop/#findComment-575077 Share on other sites More sharing options...
jarv Posted June 26, 2008 Author Share Posted June 26, 2008 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); ?> Link to comment https://forums.phpfreaks.com/topic/112020-country-repeats-for-each-headerid-in-loop/#findComment-575091 Share on other sites More sharing options...
jarv Posted June 26, 2008 Author Share Posted June 26, 2008 thanks for you help, my error lies in my SQL query! Link to comment https://forums.phpfreaks.com/topic/112020-country-repeats-for-each-headerid-in-loop/#findComment-575111 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.