George Botley Posted March 1, 2009 Share Posted March 1, 2009 Hello guys, I am trying to create a CMS.. Very succesfull so far. My past versions have worked as designed however this time I am having errors when attempting to create Gallery Administration. Here is the code... <? /* Include Configuration Files */ include_once "../config/config.php"; $con = mysql_connect("$server","$dbuser","$dbpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$database", $con); $result = mysql_query("SELECT * FROM ap_gallery_cat"); while($row = mysql_fetch_array($result)) { $id_cat = $row['id']; $title_cat = $row['title']; echo "<h3 style='margin-left: 28px; font-size: 15px; margin-top: 8px; text-decoration: underline;'>$title_cat</h3>"; $results = mysql_query("SELECT * FROM ap_gallery WHERE category LIKE $title_cat"); $rowe = mysql_fetch_assoc($results); $photourl = $rowe["photourl"]; echo "<div style='margin-top: 15px; background: #FFF; margin-left: 25px; border: 1px solid rgb(0, 0, 0); padding: 5px ; float: left; clear: right;'> <img width='250' height='200' src='$photourl'/> <br />"; echo ' <div style="width: 100%; height: 25px;"> <div style="margin: auto; width: 234px;"> <a class="button" style="margin: auto; width: " href="index.php?ToDo=WebsiteContent/Gallery&delete=yes&id=ID" title="Delete Photo"><span>Remove this Photo From The Gallery</span></a> </div> </div> </div>'; } mysql_close($con); ?> The idea is for the gallery administration is for the page to display the category name from one table, and then display the images under that title for all images within that category (a seperate table) You can probably see this from the above code however when I use this bit of code it shows the following error when executing the $rowe fetch accoc array. Somebody please help, It is paramount that this works. Quote Link to comment https://forums.phpfreaks.com/topic/147440-solved-mysql_fetch_array-and-mysql_fetch_assoc-errors-within-my-sript-help/ Share on other sites More sharing options...
wildteen88 Posted March 1, 2009 Share Posted March 1, 2009 Values within an SQL query should be wraped in quotes $results = mysql_query("SELECT * FROM ap_gallery WHERE category LIKE '$title_cat'") Quote Link to comment https://forums.phpfreaks.com/topic/147440-solved-mysql_fetch_array-and-mysql_fetch_assoc-errors-within-my-sript-help/#findComment-773856 Share on other sites More sharing options...
George Botley Posted March 1, 2009 Author Share Posted March 1, 2009 Fantastic, That sorted that problem, and it is displaying data properly. However... I am now only being shown one image from each category for some strange reason. This is my basic database structure: id photoname photourl category 1 a hidden Category 1 2 b hidden Category 1 3 c hidden Category 2 4 d hidden Category 2 It is only taking value 1 for category 1 and value 3 for category 2 and not showing any other values. Any ideas. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/147440-solved-mysql_fetch_array-and-mysql_fetch_assoc-errors-within-my-sript-help/#findComment-773870 Share on other sites More sharing options...
George Botley Posted March 1, 2009 Author Share Posted March 1, 2009 bump^ Quote Link to comment https://forums.phpfreaks.com/topic/147440-solved-mysql_fetch_array-and-mysql_fetch_assoc-errors-within-my-sript-help/#findComment-773888 Share on other sites More sharing options...
corbin Posted March 1, 2009 Share Posted March 1, 2009 What's your query? The query fenway wrote should select more than 1. Quote Link to comment https://forums.phpfreaks.com/topic/147440-solved-mysql_fetch_array-and-mysql_fetch_assoc-errors-within-my-sript-help/#findComment-773892 Share on other sites More sharing options...
George Botley Posted March 1, 2009 Author Share Posted March 1, 2009 Well.... the query is in the above quote.... But here is the whole code again..... <? /* Include Configuration Files */ include_once "../config/config.php"; $con = mysql_connect("$server","$dbuser","$dbpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$database", $con); $result = mysql_query("SELECT * FROM ap_gallery_cat"); while($row = mysql_fetch_array($result)) { $id_cat = $row['id']; $title_cat = $row['title']; echo "<h3 style='margin-left: 28px; width: 100%; float: left; font-size: 15px; margin-top: 8px; text-decoration: underline;'>$title_cat</h3>"; $results = mysql_query("SELECT * FROM ap_gallery WHERE category = '$title_cat' ORDER BY id ASC LIMIT 100"); while($rowe = mysql_fetch_array($results)) { $photourl = $rowe["photourl"]; $id = $rowe["id"]; echo "<div style='margin-top: 15px; background: #FFF; margin-left: 25px; border: 1px solid rgb(0, 0, 0); padding: 5px ; float: left; clear: right;'> <img width='250' height='200' src='$photourl'/> <br />"; echo " <div style='width: 100%; height: 25px;'> <div style='margin: auto; width: 234px;'> <a class='button' style='margin: auto;' href='index.php?ToDo=WebsiteContent/Gallery&delete=yes&id=$id' title='Delete Photo'><span>Remove this Photo From The Gallery</span></a> </div> </div> </div>"; } } mysql_close($con); ?> And here is query it's self.... $results = mysql_query("SELECT * FROM ap_gallery WHERE category = '$title_cat' ORDER BY id ASC LIMIT 100"); while($rowe = mysql_fetch_array($results)) { $photourl = $rowe["photourl"]; $id = $rowe["id"]; echo "<div style='margin-top: 15px; background: #FFF; margin-left: 25px; border: 1px solid rgb(0, 0, 0); padding: 5px ; float: left; clear: right;'> <img width='250' height='200' src='$photourl'/> <br />"; echo " <div style='width: 100%; height: 25px;'> <div style='margin: auto; width: 234px;'> <a class='button' style='margin: auto;' href='index.php?ToDo=WebsiteContent/Gallery&delete=yes&id=$id' title='Delete Photo'><span>Remove this Photo From The Gallery</span></a> </div> </div> </div>"; } It still only shows one even when I add a limit with large numbers. I don't understand. My queries usually display multiple entries odd how this one doesn't. Could it be anything to do with the 2nd query being within the first? Quote Link to comment https://forums.phpfreaks.com/topic/147440-solved-mysql_fetch_array-and-mysql_fetch_assoc-errors-within-my-sript-help/#findComment-773893 Share on other sites More sharing options...
George Botley Posted March 1, 2009 Author Share Posted March 1, 2009 Moderators, Set to resolved. I sorted this error. Quote Link to comment https://forums.phpfreaks.com/topic/147440-solved-mysql_fetch_array-and-mysql_fetch_assoc-errors-within-my-sript-help/#findComment-773915 Share on other sites More sharing options...
wildteen88 Posted March 1, 2009 Share Posted March 1, 2009 Moderators, Set to resolved. I sorted this error. You can solve it by clicking the Solve Topic link just above the Quick Reply box. I have marked it solved for you. Quote Link to comment https://forums.phpfreaks.com/topic/147440-solved-mysql_fetch_array-and-mysql_fetch_assoc-errors-within-my-sript-help/#findComment-773948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.